Esempio n. 1
0
// 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
}
Esempio n. 2
0
// EnableExtendedResultCodes enables or disables the extended result codes feature of SQLite.
// (See http://sqlite.org/c3ref/extended_result_codes.html)
func (c *Conn) EnableExtendedResultCodes(b bool) error {
	return c.error(C.sqlite3_extended_result_codes(c.db, btocint(b)), "Conn.EnableExtendedResultCodes")
}
Esempio n. 3
0
func (self *sqlConnection) sqlExtendedResultCodes(on bool) int {
	v := map[bool]int{true: 1, false: 0}[on]
	return int(C.sqlite3_extended_result_codes(self.handle, C.int(v)))
}