// Data base Engine handle func Open(file string, mode OpenFlags) (*Unqlite, error) { f := C.CString(file) defer C.free(unsafe.Pointer(f)) db := &Unqlite{} e := C.unqlite_open(&db.db, f, C.uint(mode)) if e != C.UNQLITE_OK { return nil, code2Error(e) } return db, nil }
// Open a database and return unqite object. // If fileName is ":mem:", then a private, in-memory database is created for the connection. // See: http://unqlite.org/c_api/unqlite_open.html func OpenUnqlite(fileName string, mode uint) (*Unqlite, error) { cname := C.CString(fileName) defer C.free(unsafe.Pointer(cname)) var db *C.unqlite if rc := C.unqlite_open(&db, cname, C.uint(mode)); rc != C.UNQLITE_OK { return nil, ErrCode(rc) } return &Unqlite{db}, nil }
// NewDatabase ... func NewDatabase(filename string) (db *Database, err error) { db = &Database{} name := C.CString(filename) defer C.free(unsafe.Pointer(name)) res := C.unqlite_open(&db.handle, name, C.UNQLITE_OPEN_CREATE) if res != C.UNQLITE_OK { err = UnQLiteError(res) } if db.handle != nil { runtime.SetFinalizer(db, (*Database).Close) } return }
// Open creates a database handle. func Open(filename string) (*Handle, error) { var db *C.unqlite name := C.CString(filename) defer C.free(unsafe.Pointer(name)) rv := C.unqlite_open(&db, name, C.UNQLITE_OPEN_CREATE) if rv != C.UNQLITE_OK { return nil, Errno(rv) } if db == nil { return nil, errors.New("unqlite unable to allocate memory to hold the database") } return &Handle{db}, nil }