cardinality_t dbAnyCursor::selectByKeyRange(dbFieldDescriptor* field, void const* minValue, void const* maxValue) { assert(field->tTree != 0); reset(); db->beginTransaction(type == dbCursorForUpdate ? dbDatabase::dbExclusiveLock : dbDatabase::dbSharedLock); db->threadContext.get()->cursors.link(this); dbSearchContext sc; sc.db = db; sc.probes = 0; sc.offs = field->dbsOffs; sc.cursor = this; sc.condition = NULL; sc.prefixLength = 0; sc.firstKey = (char*)minValue; sc.lastKey = (char*)maxValue; sc.firstKeyInclusion = sc.lastKeyInclusion = true; sc.field = field; sc.type = field->type; dbTtree::find(db, field->tTree, sc); if (gotoFirst() && prefetch) { fetch(); } return selection.nRows; }
int dbAnyCursor::selectByKey(char const* key, void const* value) { dbFieldDescriptor* field = table->find(key); assert(field != NULL); assert(field->hashTable != 0 || field->tTree != 0); reset(); db->beginTransaction(type == dbCursorForUpdate ? dbDatabase::dbExclusiveLock : dbDatabase::dbSharedLock); db->threadContext.get()->cursors.link(this); dbSearchContext sc; sc.db = db; sc.probes = 0; sc.offs = field->dbsOffs; sc.cursor = this; sc.condition = NULL; sc.prefixLength = 0; sc.firstKey = sc.lastKey = (char*)value; sc.firstKeyInclusion = sc.lastKeyInclusion = true; sc.comparator = field->comparator; sc.sizeofType = field->dbsSize; sc.type = field->type; if (field->hashTable != 0) { dbHashTable::find(db, field->hashTable, sc); } else { dbTtree::find(db, field->tTree, sc); } if (gotoFirst() && prefetch) { fetch(); } return selection.nRows; }
int dbAnyCursor::seek(oid_t oid) { int pos = 0; if (gotoFirst()) { do { if (currId == oid) { if (prefetch) { fetch(); } return pos; } pos += 1; } while (gotoNext()); } return -1; }