updated Transaction::del. Fixes #17

without.crypto
Rick Richardson 6 years ago
parent 8599e4051e
commit 5aa123cdbc
  1. 34
      src/transaction.rs

@ -275,11 +275,6 @@ impl <'env> RwTransaction<'env> {
mv_data: key.as_ptr() as *mut c_void }; mv_data: key.as_ptr() as *mut c_void };
let mut data_val: ffi::MDB_val = ffi::MDB_val { mv_size: data.len() as size_t, let mut data_val: ffi::MDB_val = ffi::MDB_val { mv_size: data.len() as size_t,
mv_data: data.as_ptr() as *mut c_void }; mv_data: data.as_ptr() as *mut c_void };
/*
unsafe { println!("put {:?} {:?}",
std::slice::from_raw_parts(key_val.mv_data as *const u8, key_val.mv_size),
std::slice::from_raw_parts(data_val.mv_data as *const u8, data_val.mv_size)) };
*/
unsafe { unsafe {
lmdb_result(ffi::mdb_put(self.txn(), lmdb_result(ffi::mdb_put(self.txn(),
database.dbi(), database.dbi(),
@ -338,18 +333,21 @@ impl <'env> RwTransaction<'env> {
data.map(|data| ffi::MDB_val { mv_size: data.len() as size_t, data.map(|data| ffi::MDB_val { mv_size: data.len() as size_t,
mv_data: data.as_ptr() as *mut c_void }); mv_data: data.as_ptr() as *mut c_void });
/* if let Some(mut d) = data_val {
data_val.as_ref().map(|v| unsafe { unsafe {
println!("del {:?} {:?}", lmdb_result(ffi::mdb_del(self.txn(),
std::slice::from_raw_parts(key_val.mv_data as *const u8, key_val.mv_size), database.dbi(),
std::slice::from_raw_parts(v.mv_data as *const u8, v.mv_size)) }); &mut key_val,
*/ &mut d))
unsafe {
lmdb_result(ffi::mdb_del(self.txn(), }
database.dbi(), } else {
&mut key_val, unsafe {
data_val.map(|mut data_val| &mut data_val as *mut _) lmdb_result(ffi::mdb_del(self.txn(),
.unwrap_or(ptr::null_mut()))) database.dbi(),
&mut key_val,
ptr::null_mut()))
}
} }
} }
@ -432,7 +430,7 @@ mod test {
fn test_put_get_del_multi() { fn test_put_get_del_multi() {
let dir = TempDir::new("test").unwrap(); let dir = TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path()).unwrap(); let env = Environment::new().open(dir.path()).unwrap();
let db = env.create_db(Some("putgetdel"), DatabaseFlags::DUP_SORT).unwrap(); let db = env.create_db(None, DatabaseFlags::DUP_SORT).unwrap();
let mut txn = env.begin_rw_txn().unwrap(); let mut txn = env.begin_rw_txn().unwrap();
txn.put(db, b"key1", b"val1", WriteFlags::empty()).unwrap(); txn.put(db, b"key1", b"val1", WriteFlags::empty()).unwrap();

Loading…
Cancel
Save