cursorOpen method
Opens a new cursor for the specified database
Parameters:
txn- Active transactiondbName- Optional named database
Returns a cursor that must be closed with cursorClose
Example:
final txn = await db.txnStart();
try {
final cursor = await db.cursorOpen(txn);
try {
// Use cursor...
} finally {
db.cursorClose(cursor);
}
await db.txnCommit(txn);
} catch (e) {
await db.txnAbort(txn);
rethrow;
}
Implementation
Future<Pointer<MDB_cursor>> cursorOpen(
Pointer<MDB_txn> txn, {
String? dbName,
}) async {
if (!isInitialized) throw StateError(_errDbNotInitialized);
final dbi = await _getDatabase(txn, name: dbName);
final cursorPtr = calloc<Pointer<MDB_cursor>>();
try {
final result = _lib.mdb_cursor_open(txn, dbi, cursorPtr);
if (result != 0) {
throw LMDBException('Failed to open cursor', result);
}
return cursorPtr.value;
} finally {
calloc.free(cursorPtr);
}
}