Skip to content

Commit

Permalink
always use ANSI version of ODBC API
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbrainman committed Jun 16, 2017
1 parent 632bcac commit 0ee187a
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 58 deletions.
10 changes: 5 additions & 5 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ type (
//sys SQLBindCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, targetType SQLSMALLINT, targetValuePtr SQLPOINTER, bufferLength SQLLEN, vallen *SQLLEN) (ret SQLRETURN) = odbc32.SQLBindCol
//sys SQLBindParameter(statementHandle SQLHSTMT, parameterNumber SQLUSMALLINT, inputOutputType SQLSMALLINT, valueType SQLSMALLINT, parameterType SQLSMALLINT, columnSize SQLULEN, decimalDigits SQLSMALLINT, parameterValue SQLPOINTER, bufferLength SQLLEN, ind *SQLLEN) (ret SQLRETURN) = odbc32.SQLBindParameter
//sys SQLCloseCursor(statementHandle SQLHSTMT) (ret SQLRETURN) = odbc32.SQLCloseCursor
//sys SQLDescribeCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, columnName *SQLWCHAR, bufferLength SQLSMALLINT, nameLengthPtr *SQLSMALLINT, dataTypePtr *SQLSMALLINT, columnSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLDescribeColW
//sys SQLDescribeCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, columnName *SQLCHAR, bufferLength SQLSMALLINT, nameLengthPtr *SQLSMALLINT, dataTypePtr *SQLSMALLINT, columnSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLDescribeCol
//sys SQLDescribeParam(statementHandle SQLHSTMT, parameterNumber SQLUSMALLINT, dataTypePtr *SQLSMALLINT, parameterSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLDescribeParam
//sys SQLDisconnect(connectionHandle SQLHDBC) (ret SQLRETURN) = odbc32.SQLDisconnect
//sys SQLDriverConnect(connectionHandle SQLHDBC, windowHandle SQLHWND, inConnectionString *SQLWCHAR, stringLength1 SQLSMALLINT, outConnectionString *SQLWCHAR, bufferLength SQLSMALLINT, stringLength2Ptr *SQLSMALLINT, driverCompletion SQLUSMALLINT) (ret SQLRETURN) = odbc32.SQLDriverConnectW
//sys SQLDriverConnect(connectionHandle SQLHDBC, windowHandle SQLHWND, inConnectionString *SQLCHAR, stringLength1 SQLSMALLINT, outConnectionString *SQLCHAR, bufferLength SQLSMALLINT, stringLength2Ptr *SQLSMALLINT, driverCompletion SQLUSMALLINT) (ret SQLRETURN) = odbc32.SQLDriverConnect
//sys SQLEndTran(handleType SQLSMALLINT, handle SQLHANDLE, completionType SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLEndTran
//sys SQLExecute(statementHandle SQLHSTMT) (ret SQLRETURN) = odbc32.SQLExecute
//sys SQLFetch(statementHandle SQLHSTMT) (ret SQLRETURN) = odbc32.SQLFetch
//sys SQLFreeHandle(handleType SQLSMALLINT, handle SQLHANDLE) (ret SQLRETURN) = odbc32.SQLFreeHandle
//sys SQLGetData(statementHandle SQLHSTMT, colOrParamNum SQLUSMALLINT, targetType SQLSMALLINT, targetValuePtr SQLPOINTER, bufferLength SQLLEN, vallen *SQLLEN) (ret SQLRETURN) = odbc32.SQLGetData
//sys SQLGetDiagRec(handleType SQLSMALLINT, handle SQLHANDLE, recNumber SQLSMALLINT, sqlState *SQLWCHAR, nativeErrorPtr *SQLINTEGER, messageText *SQLWCHAR, bufferLength SQLSMALLINT, textLengthPtr *SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLGetDiagRecW
//sys SQLGetDiagRec(handleType SQLSMALLINT, handle SQLHANDLE, recNumber SQLSMALLINT, sqlState *SQLCHAR, nativeErrorPtr *SQLINTEGER, messageText *SQLCHAR, bufferLength SQLSMALLINT, textLengthPtr *SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLGetDiagRec
//sys SQLNumParams(statementHandle SQLHSTMT, parameterCountPtr *SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLNumParams
//sys SQLNumResultCols(statementHandle SQLHSTMT, columnCountPtr *SQLSMALLINT) (ret SQLRETURN) = odbc32.SQLNumResultCols
//sys SQLPrepare(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (ret SQLRETURN) = odbc32.SQLPrepareW
//sys SQLPrepare(statementHandle SQLHSTMT, statementText *SQLCHAR, textLength SQLINTEGER) (ret SQLRETURN) = odbc32.SQLPrepare
//sys SQLRowCount(statementHandle SQLHSTMT, rowCountPtr *SQLLEN) (ret SQLRETURN) = odbc32.SQLRowCount
//sys SQLSetEnvAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) = odbc32.SQLSetEnvAttr
//sys SQLSetConnectAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) = odbc32.SQLSetConnectAttrW
//sys SQLSetConnectAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) = odbc32.SQLSetConnectAttr

// UTF16ToString returns the UTF-8 encoding of the UTF-16 sequence s,
// with a terminating NUL removed.
Expand Down
1 change: 1 addition & 0 deletions api/api_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ type (
SQLHSTMT C.SQLHSTMT
SQLHWND uintptr

SQLCHAR C.SQLCHAR
SQLWCHAR C.SQLWCHAR
SQLSCHAR C.SQLSCHAR
SQLSMALLINT C.SQLSMALLINT
Expand Down
18 changes: 9 additions & 9 deletions api/zapi_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func SQLCloseCursor(statementHandle SQLHSTMT) (ret SQLRETURN) {
return SQLRETURN(r)
}

func SQLDescribeCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, columnName *SQLWCHAR, bufferLength SQLSMALLINT, nameLengthPtr *SQLSMALLINT, dataTypePtr *SQLSMALLINT, columnSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (ret SQLRETURN) {
r := C.SQLDescribeColW(C.SQLHSTMT(statementHandle), C.SQLUSMALLINT(columnNumber), (*C.SQLWCHAR)(unsafe.Pointer(columnName)), C.SQLSMALLINT(bufferLength), (*C.SQLSMALLINT)(nameLengthPtr), (*C.SQLSMALLINT)(dataTypePtr), (*C.SQLULEN)(columnSizePtr), (*C.SQLSMALLINT)(decimalDigitsPtr), (*C.SQLSMALLINT)(nullablePtr))
func SQLDescribeCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, columnName *SQLCHAR, bufferLength SQLSMALLINT, nameLengthPtr *SQLSMALLINT, dataTypePtr *SQLSMALLINT, columnSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (ret SQLRETURN) {
r := C.SQLDescribeCol(C.SQLHSTMT(statementHandle), C.SQLUSMALLINT(columnNumber), (*C.SQLCHAR)(unsafe.Pointer(columnName)), C.SQLSMALLINT(bufferLength), (*C.SQLSMALLINT)(nameLengthPtr), (*C.SQLSMALLINT)(dataTypePtr), (*C.SQLULEN)(columnSizePtr), (*C.SQLSMALLINT)(decimalDigitsPtr), (*C.SQLSMALLINT)(nullablePtr))
return SQLRETURN(r)
}

Expand All @@ -54,8 +54,8 @@ func SQLDisconnect(connectionHandle SQLHDBC) (ret SQLRETURN) {
return SQLRETURN(r)
}

func SQLDriverConnect(connectionHandle SQLHDBC, windowHandle SQLHWND, inConnectionString *SQLWCHAR, stringLength1 SQLSMALLINT, outConnectionString *SQLWCHAR, bufferLength SQLSMALLINT, stringLength2Ptr *SQLSMALLINT, driverCompletion SQLUSMALLINT) (ret SQLRETURN) {
r := C.SQLDriverConnectW(C.SQLHDBC(connectionHandle), C.SQLHWND(windowHandle), (*C.SQLWCHAR)(unsafe.Pointer(inConnectionString)), C.SQLSMALLINT(stringLength1), (*C.SQLWCHAR)(unsafe.Pointer(outConnectionString)), C.SQLSMALLINT(bufferLength), (*C.SQLSMALLINT)(stringLength2Ptr), C.SQLUSMALLINT(driverCompletion))
func SQLDriverConnect(connectionHandle SQLHDBC, windowHandle SQLHWND, inConnectionString *SQLCHAR, stringLength1 SQLSMALLINT, outConnectionString *SQLCHAR, bufferLength SQLSMALLINT, stringLength2Ptr *SQLSMALLINT, driverCompletion SQLUSMALLINT) (ret SQLRETURN) {
r := C.SQLDriverConnect(C.SQLHDBC(connectionHandle), C.SQLHWND(windowHandle), (*C.SQLCHAR)(unsafe.Pointer(inConnectionString)), C.SQLSMALLINT(stringLength1), (*C.SQLCHAR)(unsafe.Pointer(outConnectionString)), C.SQLSMALLINT(bufferLength), (*C.SQLSMALLINT)(stringLength2Ptr), C.SQLUSMALLINT(driverCompletion))
return SQLRETURN(r)
}

Expand Down Expand Up @@ -84,8 +84,8 @@ func SQLGetData(statementHandle SQLHSTMT, colOrParamNum SQLUSMALLINT, targetType
return SQLRETURN(r)
}

func SQLGetDiagRec(handleType SQLSMALLINT, handle SQLHANDLE, recNumber SQLSMALLINT, sqlState *SQLWCHAR, nativeErrorPtr *SQLINTEGER, messageText *SQLWCHAR, bufferLength SQLSMALLINT, textLengthPtr *SQLSMALLINT) (ret SQLRETURN) {
r := C.SQLGetDiagRecW(C.SQLSMALLINT(handleType), C.SQLHANDLE(handle), C.SQLSMALLINT(recNumber), (*C.SQLWCHAR)(unsafe.Pointer(sqlState)), (*C.SQLINTEGER)(nativeErrorPtr), (*C.SQLWCHAR)(unsafe.Pointer(messageText)), C.SQLSMALLINT(bufferLength), (*C.SQLSMALLINT)(textLengthPtr))
func SQLGetDiagRec(handleType SQLSMALLINT, handle SQLHANDLE, recNumber SQLSMALLINT, sqlState *SQLCHAR, nativeErrorPtr *SQLINTEGER, messageText *SQLCHAR, bufferLength SQLSMALLINT, textLengthPtr *SQLSMALLINT) (ret SQLRETURN) {
r := C.SQLGetDiagRec(C.SQLSMALLINT(handleType), C.SQLHANDLE(handle), C.SQLSMALLINT(recNumber), (*C.SQLCHAR)(unsafe.Pointer(sqlState)), (*C.SQLINTEGER)(nativeErrorPtr), (*C.SQLCHAR)(unsafe.Pointer(messageText)), C.SQLSMALLINT(bufferLength), (*C.SQLSMALLINT)(textLengthPtr))
return SQLRETURN(r)
}

Expand All @@ -99,8 +99,8 @@ func SQLNumResultCols(statementHandle SQLHSTMT, columnCountPtr *SQLSMALLINT) (re
return SQLRETURN(r)
}

func SQLPrepare(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (ret SQLRETURN) {
r := C.SQLPrepareW(C.SQLHSTMT(statementHandle), (*C.SQLWCHAR)(unsafe.Pointer(statementText)), C.SQLINTEGER(textLength))
func SQLPrepare(statementHandle SQLHSTMT, statementText *SQLCHAR, textLength SQLINTEGER) (ret SQLRETURN) {
r := C.SQLPrepare(C.SQLHSTMT(statementHandle), (*C.SQLCHAR)(unsafe.Pointer(statementText)), C.SQLINTEGER(textLength))
return SQLRETURN(r)
}

Expand All @@ -115,6 +115,6 @@ func SQLSetEnvAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr SQL
}

func SQLSetConnectAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) {
r := C.SQLSetConnectAttrW(C.SQLHDBC(connectionHandle), C.SQLINTEGER(attribute), C.SQLPOINTER(valuePtr), C.SQLINTEGER(stringLength))
r := C.SQLSetConnectAttr(C.SQLHDBC(connectionHandle), C.SQLINTEGER(attribute), C.SQLPOINTER(valuePtr), C.SQLINTEGER(stringLength))
return SQLRETURN(r)
}
58 changes: 29 additions & 29 deletions api/zapi_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,26 @@ func errnoErr(e syscall.Errno) error {
var (
mododbc32 = windows.NewLazySystemDLL("odbc32.dll")

procSQLAllocHandle = mododbc32.NewProc("SQLAllocHandle")
procSQLBindCol = mododbc32.NewProc("SQLBindCol")
procSQLBindParameter = mododbc32.NewProc("SQLBindParameter")
procSQLCloseCursor = mododbc32.NewProc("SQLCloseCursor")
procSQLDescribeColW = mododbc32.NewProc("SQLDescribeColW")
procSQLDescribeParam = mododbc32.NewProc("SQLDescribeParam")
procSQLDisconnect = mododbc32.NewProc("SQLDisconnect")
procSQLDriverConnectW = mododbc32.NewProc("SQLDriverConnectW")
procSQLEndTran = mododbc32.NewProc("SQLEndTran")
procSQLExecute = mododbc32.NewProc("SQLExecute")
procSQLFetch = mododbc32.NewProc("SQLFetch")
procSQLFreeHandle = mododbc32.NewProc("SQLFreeHandle")
procSQLGetData = mododbc32.NewProc("SQLGetData")
procSQLGetDiagRecW = mododbc32.NewProc("SQLGetDiagRecW")
procSQLNumParams = mododbc32.NewProc("SQLNumParams")
procSQLNumResultCols = mododbc32.NewProc("SQLNumResultCols")
procSQLPrepareW = mododbc32.NewProc("SQLPrepareW")
procSQLRowCount = mododbc32.NewProc("SQLRowCount")
procSQLSetEnvAttr = mododbc32.NewProc("SQLSetEnvAttr")
procSQLSetConnectAttrW = mododbc32.NewProc("SQLSetConnectAttrW")
procSQLAllocHandle = mododbc32.NewProc("SQLAllocHandle")
procSQLBindCol = mododbc32.NewProc("SQLBindCol")
procSQLBindParameter = mododbc32.NewProc("SQLBindParameter")
procSQLCloseCursor = mododbc32.NewProc("SQLCloseCursor")
procSQLDescribeCol = mododbc32.NewProc("SQLDescribeCol")
procSQLDescribeParam = mododbc32.NewProc("SQLDescribeParam")
procSQLDisconnect = mododbc32.NewProc("SQLDisconnect")
procSQLDriverConnect = mododbc32.NewProc("SQLDriverConnect")
procSQLEndTran = mododbc32.NewProc("SQLEndTran")
procSQLExecute = mododbc32.NewProc("SQLExecute")
procSQLFetch = mododbc32.NewProc("SQLFetch")
procSQLFreeHandle = mododbc32.NewProc("SQLFreeHandle")
procSQLGetData = mododbc32.NewProc("SQLGetData")
procSQLGetDiagRec = mododbc32.NewProc("SQLGetDiagRec")
procSQLNumParams = mododbc32.NewProc("SQLNumParams")
procSQLNumResultCols = mododbc32.NewProc("SQLNumResultCols")
procSQLPrepare = mododbc32.NewProc("SQLPrepare")
procSQLRowCount = mododbc32.NewProc("SQLRowCount")
procSQLSetEnvAttr = mododbc32.NewProc("SQLSetEnvAttr")
procSQLSetConnectAttr = mododbc32.NewProc("SQLSetConnectAttr")
)

func SQLAllocHandle(handleType SQLSMALLINT, inputHandle SQLHANDLE, outputHandle *SQLHANDLE) (ret SQLRETURN) {
Expand All @@ -85,8 +85,8 @@ func SQLCloseCursor(statementHandle SQLHSTMT) (ret SQLRETURN) {
return
}

func SQLDescribeCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, columnName *SQLWCHAR, bufferLength SQLSMALLINT, nameLengthPtr *SQLSMALLINT, dataTypePtr *SQLSMALLINT, columnSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (ret SQLRETURN) {
r0, _, _ := syscall.Syscall9(procSQLDescribeColW.Addr(), 9, uintptr(statementHandle), uintptr(columnNumber), uintptr(unsafe.Pointer(columnName)), uintptr(bufferLength), uintptr(unsafe.Pointer(nameLengthPtr)), uintptr(unsafe.Pointer(dataTypePtr)), uintptr(unsafe.Pointer(columnSizePtr)), uintptr(unsafe.Pointer(decimalDigitsPtr)), uintptr(unsafe.Pointer(nullablePtr)))
func SQLDescribeCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, columnName *SQLCHAR, bufferLength SQLSMALLINT, nameLengthPtr *SQLSMALLINT, dataTypePtr *SQLSMALLINT, columnSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (ret SQLRETURN) {
r0, _, _ := syscall.Syscall9(procSQLDescribeCol.Addr(), 9, uintptr(statementHandle), uintptr(columnNumber), uintptr(unsafe.Pointer(columnName)), uintptr(bufferLength), uintptr(unsafe.Pointer(nameLengthPtr)), uintptr(unsafe.Pointer(dataTypePtr)), uintptr(unsafe.Pointer(columnSizePtr)), uintptr(unsafe.Pointer(decimalDigitsPtr)), uintptr(unsafe.Pointer(nullablePtr)))
ret = SQLRETURN(r0)
return
}
Expand All @@ -103,8 +103,8 @@ func SQLDisconnect(connectionHandle SQLHDBC) (ret SQLRETURN) {
return
}

func SQLDriverConnect(connectionHandle SQLHDBC, windowHandle SQLHWND, inConnectionString *SQLWCHAR, stringLength1 SQLSMALLINT, outConnectionString *SQLWCHAR, bufferLength SQLSMALLINT, stringLength2Ptr *SQLSMALLINT, driverCompletion SQLUSMALLINT) (ret SQLRETURN) {
r0, _, _ := syscall.Syscall9(procSQLDriverConnectW.Addr(), 8, uintptr(connectionHandle), uintptr(windowHandle), uintptr(unsafe.Pointer(inConnectionString)), uintptr(stringLength1), uintptr(unsafe.Pointer(outConnectionString)), uintptr(bufferLength), uintptr(unsafe.Pointer(stringLength2Ptr)), uintptr(driverCompletion), 0)
func SQLDriverConnect(connectionHandle SQLHDBC, windowHandle SQLHWND, inConnectionString *SQLCHAR, stringLength1 SQLSMALLINT, outConnectionString *SQLCHAR, bufferLength SQLSMALLINT, stringLength2Ptr *SQLSMALLINT, driverCompletion SQLUSMALLINT) (ret SQLRETURN) {
r0, _, _ := syscall.Syscall9(procSQLDriverConnect.Addr(), 8, uintptr(connectionHandle), uintptr(windowHandle), uintptr(unsafe.Pointer(inConnectionString)), uintptr(stringLength1), uintptr(unsafe.Pointer(outConnectionString)), uintptr(bufferLength), uintptr(unsafe.Pointer(stringLength2Ptr)), uintptr(driverCompletion), 0)
ret = SQLRETURN(r0)
return
}
Expand Down Expand Up @@ -139,8 +139,8 @@ func SQLGetData(statementHandle SQLHSTMT, colOrParamNum SQLUSMALLINT, targetType
return
}

func SQLGetDiagRec(handleType SQLSMALLINT, handle SQLHANDLE, recNumber SQLSMALLINT, sqlState *SQLWCHAR, nativeErrorPtr *SQLINTEGER, messageText *SQLWCHAR, bufferLength SQLSMALLINT, textLengthPtr *SQLSMALLINT) (ret SQLRETURN) {
r0, _, _ := syscall.Syscall9(procSQLGetDiagRecW.Addr(), 8, uintptr(handleType), uintptr(handle), uintptr(recNumber), uintptr(unsafe.Pointer(sqlState)), uintptr(unsafe.Pointer(nativeErrorPtr)), uintptr(unsafe.Pointer(messageText)), uintptr(bufferLength), uintptr(unsafe.Pointer(textLengthPtr)), 0)
func SQLGetDiagRec(handleType SQLSMALLINT, handle SQLHANDLE, recNumber SQLSMALLINT, sqlState *SQLCHAR, nativeErrorPtr *SQLINTEGER, messageText *SQLCHAR, bufferLength SQLSMALLINT, textLengthPtr *SQLSMALLINT) (ret SQLRETURN) {
r0, _, _ := syscall.Syscall9(procSQLGetDiagRec.Addr(), 8, uintptr(handleType), uintptr(handle), uintptr(recNumber), uintptr(unsafe.Pointer(sqlState)), uintptr(unsafe.Pointer(nativeErrorPtr)), uintptr(unsafe.Pointer(messageText)), uintptr(bufferLength), uintptr(unsafe.Pointer(textLengthPtr)), 0)
ret = SQLRETURN(r0)
return
}
Expand All @@ -157,8 +157,8 @@ func SQLNumResultCols(statementHandle SQLHSTMT, columnCountPtr *SQLSMALLINT) (re
return
}

func SQLPrepare(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (ret SQLRETURN) {
r0, _, _ := syscall.Syscall(procSQLPrepareW.Addr(), 3, uintptr(statementHandle), uintptr(unsafe.Pointer(statementText)), uintptr(textLength))
func SQLPrepare(statementHandle SQLHSTMT, statementText *SQLCHAR, textLength SQLINTEGER) (ret SQLRETURN) {
r0, _, _ := syscall.Syscall(procSQLPrepare.Addr(), 3, uintptr(statementHandle), uintptr(unsafe.Pointer(statementText)), uintptr(textLength))
ret = SQLRETURN(r0)
return
}
Expand All @@ -176,7 +176,7 @@ func SQLSetEnvAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr SQL
}

func SQLSetConnectAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) {
r0, _, _ := syscall.Syscall6(procSQLSetConnectAttrW.Addr(), 4, uintptr(connectionHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength), 0, 0)
r0, _, _ := syscall.Syscall6(procSQLSetConnectAttr.Addr(), 4, uintptr(connectionHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength), 0, 0)
ret = SQLRETURN(r0)
return
}
10 changes: 5 additions & 5 deletions column.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ type Column interface {
Value(h api.SQLHSTMT, idx int) (driver.Value, error)
}

func describeColumn(h api.SQLHSTMT, idx int, namebuf []uint16) (namelen int, sqltype api.SQLSMALLINT, size api.SQLULEN, ret api.SQLRETURN) {
func describeColumn(h api.SQLHSTMT, idx int, namebuf []byte) (namelen int, sqltype api.SQLSMALLINT, size api.SQLULEN, ret api.SQLRETURN) {
var l, decimal, nullable api.SQLSMALLINT
ret = api.SQLDescribeCol(h, api.SQLUSMALLINT(idx+1),
(*api.SQLWCHAR)(unsafe.Pointer(&namebuf[0])),
(*api.SQLCHAR)(unsafe.Pointer(&namebuf[0])),
api.SQLSMALLINT(len(namebuf)), &l,
&sqltype, &size, &decimal, &nullable)
return int(l), sqltype, size, ret
Expand All @@ -51,11 +51,11 @@ func describeColumn(h api.SQLHSTMT, idx int, namebuf []uint16) (namelen int, sql
// TODO(brainman): did not check for MS SQL timestamp

func NewColumn(h api.SQLHSTMT, idx int) (Column, error) {
namebuf := make([]uint16, 150)
namebuf := make([]byte, 150)
namelen, sqltype, size, ret := describeColumn(h, idx, namebuf)
if ret == api.SQL_SUCCESS_WITH_INFO && namelen > len(namebuf) {
// try again with bigger buffer
namebuf = make([]uint16, namelen)
namebuf = make([]byte, namelen)
namelen, sqltype, size, ret = describeColumn(h, idx, namebuf)
}
if IsError(ret) {
Expand All @@ -66,7 +66,7 @@ func NewColumn(h api.SQLHSTMT, idx int) (Column, error) {
return nil, errors.New("Failed to allocate column name buffer")
}
b := &BaseColumn{
name: api.UTF16ToString(namebuf[:namelen]),
name: string(namebuf[:namelen]),
}
switch sqltype {
case api.SQL_BIT:
Expand Down
5 changes: 3 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package odbc

import (
"database/sql/driver"
"syscall"
"unsafe"

"github.com/alexbrainman/odbc/api"
Expand All @@ -26,9 +27,9 @@ func (d *Driver) Open(dsn string) (driver.Conn, error) {
h := api.SQLHDBC(out)
drv.Stats.updateHandleCount(api.SQL_HANDLE_DBC, 1)

b := api.StringToUTF16(dsn)
b := syscall.StringByteSlice(dsn)
ret = api.SQLDriverConnect(h, 0,
(*api.SQLWCHAR)(unsafe.Pointer(&b[0])), api.SQL_NTS,
(*api.SQLCHAR)(unsafe.Pointer(&b[0])), api.SQL_NTS,
nil, 0, nil, api.SQL_DRIVER_NOPROMPT)
if IsError(ret) {
defer releaseHandle(h)
Expand Down
Loading

0 comments on commit 0ee187a

Please sign in to comment.