Beispiel #1
0
// Put stores an item in database dbi.
//
// See mdb_put.
func (txn *Txn) Put(dbi DBI, key []byte, val []byte, flags uint) error {
	kn := len(key)
	if kn == 0 {
		return txn.putNilKey(dbi, flags)
	}
	vn := len(val)
	if vn == 0 {
		val = []byte{0}
	}

	ret := C.lmdbgo_mdb_put2(
		txn._txn, C.MDB_dbi(dbi),
		(*C.char)(unsafe.Pointer(&key[0])), C.size_t(kn),
		(*C.char)(unsafe.Pointer(&val[0])), C.size_t(vn),
		C.uint(flags),
	)
	return operrno("mdb_put", ret)
}
Beispiel #2
0
func (txn *Txn) putNilKey(dbi DBI, flags uint) error {
	// mdb_put with an empty key will always fail
	ret := C.lmdbgo_mdb_put2(txn._txn, C.MDB_dbi(dbi), nil, 0, nil, 0, C.uint(flags))
	return operrno("mdb_put", ret)
}