Пример #1
0
func newConn(database, username, password, schema, timezone string) (*Conn, error) {
	location := timezone
	if timezone == "" {
		location = "Local"
	}
	loc, err := time.LoadLocation(location)
	if err != nil {
		return nil, fmt.Errorf("nuodb: %s", err)
	}
	c := &Conn{loc: loc}
	C.nuodb_init(&c.db)
	cdatabase := C.CString(database)
	defer C.free(unsafe.Pointer(cdatabase))
	cusername := C.CString(username)
	defer C.free(unsafe.Pointer(cusername))
	cpassword := C.CString(password)
	defer C.free(unsafe.Pointer(cpassword))
	cschema := C.CString(schema)
	defer C.free(unsafe.Pointer(cschema))
	ctimezone := C.CString(timezone)
	defer C.free(unsafe.Pointer(ctimezone))
	if C.nuodb_open(c.db, cdatabase, cusername, cpassword, cschema, ctimezone) != 0 {
		lastError := c.lastError()
		C.nuodb_close(&c.db)
		return nil, lastError
	}
	return c, nil
}
Пример #2
0
func (c *Conn) Close() error {
	if c != nil && c.db != nil {
		if rc := C.nuodb_close(&c.db); rc != 0 {
			// can't use lastError here
			return fmt.Errorf("nuodb: conn close failed: %d", rc)
		}
	}
	return nil
}