示例#1
0
文件: sqlite.go 项目: kazyk/go-sqlite
func (Driver) Open(name string) (driver.Conn, error) {
	n := C.CString(name)
	defer C.free(unsafe.Pointer(n))

	var conn Conn
	r := C.sqlite3_open(n, &conn.db)
	if r != C.SQLITE_OK {
		return &conn, driver.ErrBadConn
	}
	return &conn, nil
}
示例#2
0
func (h *Handle) Open(filename string) (err string) {
	rv := C.sqlite3_open(C.CString(filename), &h.cptr)

	if rv != 0 {
		if nil != h.cptr {
			return h.ErrMsg()
		} else {
			return "Couldn't allocate memory for SQLite3"
		}
	}
	return ""
}
示例#3
0
文件: sqlite.go 项目: welterde/mudkip
func sqlite_Open(filename string) (*Conn, os.Error) {
	var db *C.sqlite3
	name := C.CString(filename)
	defer C.free(unsafe.Pointer(name))
	rv := C.sqlite3_open(name, &db)
	if rv != 0 {
		return nil, Errno(rv)
	}
	if db == nil {
		return nil, os.NewError("sqlite succeeded without returning a database")
	}
	return &Conn{db}, nil
}