Ejemplo n.º 1
0
func (cursor *Cursor) Get(set_key []byte, op uint) (key, val []byte, err error) {
	var ckey C.MDB_val
	var cval C.MDB_val
	if set_key != nil && op == SET {
		var cset_key *C.MDB_val
		cset_key = &C.MDB_val{mv_size: C.size_t(len(set_key)),
			mv_data: unsafe.Pointer(&set_key[0])}
		ret := C.mdb_cursor_get(cursor._cursor, cset_key, &cval, C.MDB_cursor_op(op))
		if ret != SUCCESS {
			err = Errno(ret)
			key = nil
			val = nil
			return
		}
		key = set_key
		val = C.GoBytes(cval.mv_data, C.int(cval.mv_size))
	}
	ret := C.mdb_cursor_get(cursor._cursor, &ckey, &cval, C.MDB_cursor_op(op))
	if ret != SUCCESS {
		err = Errno(ret)
		key = nil
		val = nil
		return
	}
	err = nil
	key = C.GoBytes(ckey.mv_data, C.int(ckey.mv_size))
	val = C.GoBytes(cval.mv_data, C.int(cval.mv_size))
	return
}
Ejemplo n.º 2
0
// getVal1 retrieves items from the database using key data for reference
// (Set, SetRange, etc).
//
// See mdb_cursor_get.
func (c *Cursor) getVal1(setkey []byte, op uint) error {
	ret := C.lmdbgo_mdb_cursor_get1(
		c._c,
		(*C.char)(unsafe.Pointer(&setkey[0])), C.size_t(len(setkey)),
		c.txn.key, c.txn.val,
		C.MDB_cursor_op(op),
	)
	return operrno("mdb_cursor_get", ret)
}
Ejemplo n.º 3
0
func (cursor *Cursor) Get(set_key []byte, op uint) (key, val []byte, err error) {
	var ckey C.MDB_val
	var cval C.MDB_val
	if set_key != nil && (op == SET || op == SET_KEY || op == SET_RANGE) {
		ckey.mv_size = C.size_t(len(set_key))
		ckey.mv_data = unsafe.Pointer(&set_key[0])
	}
	ret := C.mdb_cursor_get(cursor._cursor, &ckey, &cval, C.MDB_cursor_op(op))
	if ret != SUCCESS {
		err = Errno(ret)
		key = nil
		val = nil
		return
	}
	err = nil
	key = C.GoBytes(ckey.mv_data, C.int(ckey.mv_size))
	val = C.GoBytes(cval.mv_data, C.int(cval.mv_size))
	return
}
Ejemplo n.º 4
0
// getVal0 retrieves items from the database without using given key or value
// data for reference (Next, First, Last, etc).
//
// See mdb_cursor_get.
func (c *Cursor) getVal0(op uint) error {
	ret := C.mdb_cursor_get(c._c, c.txn.key, c.txn.val, C.MDB_cursor_op(op))
	return operrno("mdb_cursor_get", ret)
}
Ejemplo n.º 5
0
func (cursor *Cursor) GetVal(key, val []byte, op uint) (*Val, *Val, error) {
	ckey := Wrap(key)
	cval := Wrap(val)
	ret := C.mdb_cursor_get(cursor._cursor, (*C.MDB_val)(ckey), (*C.MDB_val)(cval), C.MDB_cursor_op(op))
	return ckey, cval, errno(ret)
}
Ejemplo n.º 6
0
func (cursor *Cursor) GetVal(key []byte, op uint) (Val, Val, error) {
	ckey := Wrap(key)
	var cval Val
	ret := C.mdb_cursor_get(cursor._cursor, (*C.MDB_val)(&ckey), (*C.MDB_val)(&cval), C.MDB_cursor_op(op))
	return ckey, cval, errno(ret)
}