cursorPut method
Stores data at current cursor position
Parameters:
cursor- Active cursorkey- Key to storevalue- Value to storeflags- Optional operation flags
Example:
await db.cursorPut(
cursor,
utf8.encode('key'),
utf8.encode('value'),
0
);
Implementation
Future<void> cursorPut(
Pointer<MDB_cursor> cursor,
List<int> key,
List<int> value,
int flags,
) async {
final keyPtr = calloc<Uint8>(key.length);
final valuePtr = calloc<Uint8>(value.length);
try {
final keyList = keyPtr.asTypedList(key.length);
keyList.setAll(0, key);
final valueList = valuePtr.asTypedList(value.length);
valueList.setAll(0, value);
return _withAllocated<void, MDB_val>((keyVal) {
return _withAllocated<void, MDB_val>((dataVal) {
keyVal.ref.mv_size = key.length;
keyVal.ref.mv_data = keyPtr.cast();
dataVal.ref.mv_size = value.length;
dataVal.ref.mv_data = valuePtr.cast();
final result = _lib.mdb_cursor_put(
cursor,
keyVal,
dataVal,
flags,
);
if (result != 0) {
throw LMDBException('Failed to put cursor data', result);
}
}, calloc<MDB_val>());
}, calloc<MDB_val>());
} finally {
calloc.free(keyPtr);
calloc.free(valuePtr);
}
}