// Close closes a database connection and any dangling statements. // (See http://sqlite.org/c3ref/close.html) func (c *Conn) Close() error { if c == nil { return errors.New("nil sqlite database") } if c.db == nil { return nil } c.stmtCache.flush() rv := C.sqlite3_close(c.db) if rv == C.SQLITE_BUSY { // Dangling statements stmt := C.sqlite3_next_stmt(c.db, nil) for stmt != nil { if C.sqlite3_stmt_busy(stmt) != 0 { Log(C.SQLITE_MISUSE, "Dangling statement (not reset): \""+C.GoString(C.sqlite3_sql(stmt))+"\"") } else { Log(C.SQLITE_MISUSE, "Dangling statement (not finalize): \""+C.GoString(C.sqlite3_sql(stmt))+"\"") } C.sqlite3_finalize(stmt) stmt = C.sqlite3_next_stmt(c.db, nil) } rv = C.sqlite3_close(c.db) } if rv != C.SQLITE_OK { Log(int32(rv), "error while closing Conn") return c.error(rv, "Conn.Close") } c.db = nil return nil }
// OpenVfs opens a new database with a specified virtual file system. func OpenVfs(filename string, vfsname string, flags ...OpenFlag) (*Conn, error) { if C.sqlite3_threadsafe() == 0 { return nil, errors.New("sqlite library was not compiled for thread-safe operation") } var openFlags int if len(flags) > 0 { for _, flag := range flags { openFlags |= int(flag) } } else { openFlags = C.SQLITE_OPEN_FULLMUTEX | C.SQLITE_OPEN_READWRITE | C.SQLITE_OPEN_CREATE } var db *C.sqlite3 name := C.CString(filename) defer C.free(unsafe.Pointer(name)) var vfs *C.char if len(vfsname) > 0 { vfs = C.CString(vfsname) defer C.free(unsafe.Pointer(vfs)) } rv := C.sqlite3_open_v2(name, &db, C.int(openFlags), vfs) if rv != C.SQLITE_OK { if db != nil { C.sqlite3_close(db) } return nil, Errno(rv) } if db == nil { return nil, errors.New("sqlite succeeded without returning a database") } return &Conn{db: db, stmtCache: newCache()}, nil }
func (c *Conn) Close() os.Error { rv := C.sqlite3_close(c.db) if rv != 0 { return c.error(rv) } return nil }
func (conn Conn) Close() error { r := C.sqlite3_close(conn.db) if r != C.SQLITE_OK { return driver.ErrBadConn } return nil }
func (c *conn) Close() error { if c.closed { panic("database/sql/driver: misuse of sqlite driver: multiple Close") } c.closed = true rv := C.sqlite3_close(c.db) c.db = nil return c.error(rv) }
func (c *Conn) Close() error { if c == nil || c.db == nil { return errors.New("nil sqlite database") } rv := C.sqlite3_close(c.db) if rv != 0 { return c.error(rv) } c.db = nil return nil }
// Close the connection. func (c *SQLiteConn) Close() error { s := C.sqlite3_next_stmt(c.db, nil) for s != nil { C.sqlite3_finalize(s) s = C.sqlite3_next_stmt(c.db, nil) } rv := C.sqlite3_close(c.db) if rv != C.SQLITE_OK { return errors.New("error while closing sqlite database connection") } c.db = nil return nil }
func (c *SQLiteConn) Close() error { s := C.sqlite3_next_stmt(c.db, nil) for s != nil { C.sqlite3_finalize(s) s = C.sqlite3_next_stmt(c.db, nil) } rv := C.sqlite3_close(c.db) if rv != C.SQLITE_OK { return errors.New("sqlite succeeded without returning a database") } c.db = nil return nil }
// Close the connection. func (c *SQLiteConn) Close() error { s := C.sqlite3_next_stmt(c.db, nil) for s != nil { C.sqlite3_finalize(s) s = C.sqlite3_next_stmt(c.db, nil) } rv := C.sqlite3_close(c.db) if rv != C.SQLITE_OK { return ErrNo(rv) } c.db = nil return nil }
// Close releases all resources associated with the connection. If any prepared // statements, incremental I/O operations, or backup operations are still // active, the connection becomes an unusable "zombie" and is closed after all // remaining statements and operations are destroyed. A BUSY error code is // returned if the connection is left in this "zombie" status, which may // indicate a programming error where some previously allocated resource is not // properly released. // [http://www.sqlite.org/c3ref/close.html] func (c *Conn) Close() error { if db := c.db; db != nil { c.db = nil runtime.SetFinalizer(c, nil) if rc := C.sqlite3_close(db); rc != OK { err := libErr(rc, db) if rc == BUSY { C.sqlite3_close_v2(db) } return err } *c = Conn{} // Clear callback handlers only if db was closed } return nil }
// OpenVfs opens a new database with a specified virtual file system. func OpenVfs(filename string, vfsname string, flags ...OpenFlag) (*Conn, error) { if C.sqlite3_threadsafe() == 0 { return nil, errors.New("sqlite library was not compiled for thread-safe operation") } var openFlags int if len(flags) > 0 { for _, flag := range flags { openFlags |= int(flag) } } else { openFlags = C.SQLITE_OPEN_FULLMUTEX | C.SQLITE_OPEN_READWRITE | C.SQLITE_OPEN_CREATE } var db *C.sqlite3 cname := C.CString(filename) defer C.free(unsafe.Pointer(cname)) var vfs *C.char if len(vfsname) > 0 { vfs = C.CString(vfsname) defer C.free(unsafe.Pointer(vfs)) } rv := C.sqlite3_open_v2(cname, &db, C.int(openFlags), vfs) if rv != C.SQLITE_OK { if db != nil { // try to extract futher details from db... err := OpenError{Code: Errno(rv), ExtendedCode: int(C.sqlite3_extended_errcode(db)), Msg: C.GoString(C.sqlite3_errmsg(db)), Filename: filename, } C.sqlite3_close(db) return nil, err } return nil, Errno(rv) } if db == nil { return nil, errors.New("sqlite succeeded without returning a database") } c := &Conn{db: db, stmtCache: newCache(), DefaultTimeLayout: "2006-01-02 15:04:05.000Z07:00"} if os.Getenv("SQLITE_DEBUG") != "" { //c.SetAuthorizer(authorizer, c.db) c.Trace(trace, "TRACE") //c.SetCacheSize(0) } return c, nil }
// Open creates a new connection to a SQLite database. The name can be 1) a path // to a file, which is created if it does not exist, 2) a URI using the syntax // described at http://www.sqlite.org/uri.html, 3) the string ":memory:", which // creates a temporary in-memory database, or 4) an empty string, which creates // a temporary on-disk database (deleted when closed) in the directory returned // by os.TempDir(). // [http://www.sqlite.org/c3ref/open.html] func Open(name string) (*Conn, error) { if initErr != nil { return nil, initErr } name += "\x00" var db *C.sqlite3 rc := C.sqlite3_open_v2(cStr(name), &db, C.SQLITE_OPEN_READWRITE|C.SQLITE_OPEN_CREATE, nil) if rc != OK { err := libErr(rc, db) C.sqlite3_close(db) return nil, err } c := &Conn{db: db} C.sqlite3_extended_result_codes(db, 1) runtime.SetFinalizer(c, (*Conn).Close) return c, nil }
func (self *sqlConnection) sqlClose() int { return int(C.sqlite3_close(self.handle)) }
func (h *Handle) Close() { C.sqlite3_close(h.cptr) h.cptr = nil }
func (db *Database) Close() { C.sqlite3_close(db.handle) db.handle = nil }