Esempio n. 1
0
File: tx.go Progetto: qida/godbc
func (c *Conn) setAutoCommitAttr(a uintptr) error {
	ret := api.SQLSetConnectAttr(c.h, api.SQL_ATTR_AUTOCOMMIT,
		api.SQLPOINTER(a), api.SQL_IS_UINTEGER)
	if IsError(ret) {
		return NewError("SQLSetConnectAttr", c.h)
	}
	return nil
}
Esempio n. 2
0
File: driver.go Progetto: qida/godbc
func initDriver() error {

	//Allocate environment handle
	var out api.SQLHANDLE
	in := api.SQLHANDLE(api.SQL_NULL_HANDLE)
	ret := api.SQLAllocHandle(api.SQL_HANDLE_ENV, in, &out)
	if IsError(ret) {
		return NewError("SQLAllocHandle", api.SQLHENV(in))
	}
	drv.h = api.SQLHENV(out)
	drv.Stats.updateHandleCount(api.SQL_HANDLE_ENV, 1)

	// will use ODBC v3
	ret = api.SQLSetEnvAttr(drv.h, api.SQL_ATTR_ODBC_VERSION,
		api.SQLPOINTER(api.SQL_OV_ODBC3), 0)
	if IsError(ret) {
		defer releaseHandle(drv.h)
		return NewError("SQLSetEnvAttr", drv.h)
	}

	//TODO: find a way to make this attribute changeable at runtime
	//Enable connection pooling
	ret = api.SQLSetEnvAttr(drv.h, api.SQL_ATTR_CONNECTION_POOLING, api.SQLPOINTER(api.SQL_CP_ONE_PER_HENV), api.SQL_IS_UINTEGER)
	if IsError(ret) {
		defer releaseHandle(drv.h)
		return NewError("SQLSetEnvAttr", drv.h)
	}

	//Set relaxed connection pool matching
	ret = api.SQLSetEnvAttr(drv.h, api.SQL_ATTR_CP_MATCH, api.SQLPOINTER(api.SQL_CP_RELAXED_MATCH), api.SQL_IS_UINTEGER)
	if IsError(ret) {
		defer releaseHandle(drv.h)
		return NewError("SQLSetEnvAttr", drv.h)
	}

	//TODO: it would be nice if we could call "drv.SetMaxIdleConns(0)" here but from the docs it looks like
	//the user must call this function after db.Open

	return nil
}
Esempio n. 3
0
File: column.go Progetto: qida/godbc
func (l *BufferLen) Bind(h api.SQLHSTMT, idx int, ctype api.SQLSMALLINT, buf []byte) api.SQLRETURN {
	return api.SQLBindCol(h, api.SQLUSMALLINT(idx+1), ctype,
		api.SQLPOINTER(unsafe.Pointer(&buf[0])), api.SQLLEN(len(buf)),
		(*api.SQLLEN)(l))
}