int db_cursor_seek(MDB_cursor *const cursor, MDB_val *const key, MDB_val *const data, int const dir) { if(!key) return EINVAL; MDB_val const orig = *key; MDB_cursor_op const op = 0 == dir ? MDB_SET : MDB_SET_RANGE; int rc = mdb_cursor_get(cursor, key, data, op); if(dir >= 0) return rc; if(MDB_SUCCESS == rc) { MDB_txn *const txn = mdb_cursor_txn(cursor); MDB_dbi const dbi = mdb_cursor_dbi(cursor); if(0 == mdb_cmp(txn, dbi, &orig, key)) return rc; } else if(MDB_NOTFOUND != rc) return rc; return mdb_cursor_get(cursor, key, data, MDB_PREV); }
/* * Class: jmdb_DatabaseWrapper * Method: cursorDbi * Signature: (J)I */ JNIEXPORT jint JNICALL Java_jmdb_DatabaseWrapper_cursorDbi(JNIEnv *vm, jclass clazz, jlong cursorL) { MDB_cursor *cursorC = (MDB_cursor*) cursorL; return (jint) mdb_cursor_dbi(cursorC); }