Ejemplo n.º 1
0
// Returns the data associated with a given key, or nil if the key is not
// present in the database.
func (d *Database) Fetch(key []byte) (value []byte) {
	dkey := toDatum(key)
	dval := C.gdbm_fetch(d.dbf, dkey)
	if dval.dptr != nil {
		defer C.free(unsafe.Pointer(dval.dptr))
		value = C.GoBytes(unsafe.Pointer(dval.dptr), dval.dsize)
	}
	return
}
Ejemplo n.º 2
0
func (d *gdbm) Get(keydata []byte) ([]byte, error) {
	key := toDatum(keydata)
	value := C.gdbm_fetch(d.dbf, key)
	if value.dptr == nil {
		return nil, nil
	}
	data := fromDatum(value)
	return data, nil
}
Ejemplo n.º 3
0
// Fetches the value of the given key. If the key is not in the database, an
// error will be returned in err. Otherwise, value will be the value string
// that is keyed by `key`.
func (db *Database) Fetch(key string) (value string, err error) {
	kcs := C.CString(key)
	k := C.mk_datum(kcs)
	defer C.free(unsafe.Pointer(kcs))

	vdatum := C.gdbm_fetch(db.dbf, k)
	if vdatum.dptr == nil {
		return "", lastError()
	}

	value = C.GoStringN(vdatum.dptr, vdatum.dsize)
	defer C.free(unsafe.Pointer(vdatum.dptr))
	return value, nil
}