func (db *Db) Close() { ret := C.db_close(db.db) if ret == 0 { return } else if ret == C.EINVAL { log.Error("Close|db_close|EINVAL") return } go func() { for { ret := C.db_close(db.db) if ret == 0 { break } else if ret == C.EINVAL { log.Error("Close|db_close|EINVAL") break } else if ret == C.DB_LOCK_DEADLOCK { log.Error("Close|db_close|DB_LOCK_DEADLOCK") } else if ret == C.DB_LOCK_NOTGRANTED { log.Error("Close|db_close|DB_LOCK_NOTGRANTED") } else { log.Error("Close|db_close|unknown|%v", ret) break } time.Sleep(time.Millisecond) } }() }
// Open a database in the given file and environment. func OpenDatabase(env Environment, txn Transaction, file string, config *DatabaseConfig) (db Database, err error) { err = check(C.db_create(&db.ptr, env.ptr, 0)) if err == nil { defer func() { if err != nil && db.ptr != nil { C.db_close(db.ptr, 0) db.ptr = nil } }() } else { return } var mode C.int = 0 var flags C.u_int32_t = C.DB_THREAD var cfile, cpassword, cname *C.char var dbtype C.DBTYPE = C.DB_UNKNOWN if len(file) > 0 { cfile = C.CString(file) defer C.free(unsafe.Pointer(cfile)) } if config != nil { if config.Create { flags |= C.DB_CREATE } if config.Mode != 0 { mode = C.int(config.Mode) } if len(config.Password) > 0 { cpassword := C.CString(config.Password) defer C.free(unsafe.Pointer(cpassword)) } if len(config.Name) > 0 { cname = C.CString(config.Name) defer C.free(unsafe.Pointer(cname)) } if config.Type != 0 { dbtype = C.DBTYPE(config.Type) } if config.ReadUncommitted { flags |= C.DB_READ_UNCOMMITTED } if config.Snapshot { flags |= C.DB_MULTIVERSION } } if cpassword != nil { err = check(C.db_set_encrypt(db.ptr, cpassword, 0)) if err != nil { return } } err = check(C.db_open(db.ptr, txn.ptr, cfile, cname, dbtype, flags, mode)) return }
func (db BerkeleyDB) Close(flags DbFlag) error { if db.ptr == nil { return ok } err := Err(C.db_close(db.ptr, C.u_int32_t(flags))) if err != nil { return err } db.ptr = nil return ok }
func (db *DB) Close() error { db.lk.Lock() defer db.lk.Unlock() if db.db == nil { return nil } n, err := C.db_close(db.db) db.db = nil if n != 0 { return err } return nil }
// Close the database. func (db Database) Close() (err error) { err = check(C.db_close(db.ptr, 0)) return }