func (c *Conn) PrepareODBCStmt(query string) (*ODBCStmt, error) { var out api.SQLHANDLE ret := api.SQLAllocHandle(api.SQL_HANDLE_STMT, api.SQLHANDLE(c.h), &out) if IsError(ret) { return nil, NewError("SQLAllocHandle", c.h) } h := api.SQLHSTMT(out) drv.Stats.updateHandleCount(api.SQL_HANDLE_STMT, 1) b := api.StringToUTF16(query) ret = api.SQLPrepare(h, (*api.SQLWCHAR)(unsafe.Pointer(&b[0])), api.SQLINTEGER(len(b))) if IsError(ret) { defer releaseHandle(h) return nil, NewError("SQLPrepare", h) } ps, err := ExtractParameters(h) if err != nil { defer releaseHandle(h) return nil, err } return &ODBCStmt{ h: h, Parameters: ps, usedByStmt: true, }, nil }
func (d *Driver) Open(dsn string) (driver.Conn, error) { var out api.SQLHANDLE ret := api.SQLAllocHandle(api.SQL_HANDLE_DBC, api.SQLHANDLE(d.h), &out) if IsError(ret) { return nil, NewError("SQLAllocHandle", d.h) } h := api.SQLHDBC(out) drv.Stats.updateHandleCount(api.SQL_HANDLE_DBC, 1) b := api.StringToUTF16(dsn) ret = api.SQLDriverConnect(h, 0, (*api.SQLWCHAR)(unsafe.Pointer(&b[0])), api.SQLSMALLINT(len(b)), nil, 0, nil, api.SQL_DRIVER_NOPROMPT) if IsError(ret) { defer releaseHandle(h) return nil, NewError("SQLDriverConnect", h) } return &Conn{h: h}, nil }