// 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 }
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 }
// 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 }