diff --git a/api/api.go b/api/api.go index 0b7e3fd..eb31855 100644 --- a/api/api.go +++ b/api/api.go @@ -59,7 +59,7 @@ type ( // UTF16ToString returns the UTF-8 encoding of the UTF-16 sequence s, // with a terminating NUL removed. func UTF16ToString(s []uint16) string { - trc.Trace1("api/api.go UTF16ToString() - ENTRY") + trc.Trace1("api/api.go UTF16ToString() - ENTRY") for i, v := range s { if v == 0 { s = s[0:i] @@ -74,9 +74,9 @@ func UTF16ToString(s []uint16) string { // with a terminating NUL added. //func StringToUTF16(s string) []uint16 { return utf16.Encode([]rune(s + "\u0000")) } func StringToUTF16(s string) []uint16 { - trc.Trace1("api/api.go StringToUTF16()") + trc.Trace1("api/api.go StringToUTF16()") trc.Trace1(fmt.Sprintf("api/api.go StringToUTF16() - s = %s", s)) - + if runtime.GOOS == "zos"{ return utf16.Encode([]rune(s)) }else { @@ -91,26 +91,26 @@ func StringToUTF16Ptr(s string) *uint16 { return &StringToUTF16(s)[0] } // ExtractUTF16Str uses unsafe package to copy UTF16 string to a byte slice. func ExtractUTF16Str(s []uint16) []byte { - trc.Trace1("api/api.go ExtractUTF16Str() - ENTRY") - + trc.Trace1("api/api.go ExtractUTF16Str() - ENTRY") + var out []byte for i := range s { b := Extract(unsafe.Pointer(&s[i]), unsafe.Sizeof(s[i])) out = append(out, b...) } - + trc.Trace1("api/api.go ExtractUTF16Str() - EXIT") return out } func Extract(ptr unsafe.Pointer, size uintptr) []byte { trc.Trace1("api/api.go Extract() - ENTRY") - + out := make([]byte, size) for i := range out { out[i] = *((*byte)(unsafe.Pointer(uintptr(ptr) + uintptr(i)))) } - + trc.Trace1("api/api.go Extract() - EXIT") return out } diff --git a/api/api_unix.go b/api/api_unix.go index bd73c15..ee7b9db 100644 --- a/api/api_unix.go +++ b/api/api_unix.go @@ -9,7 +9,7 @@ package api import ( - trc "github.com/ibmdb/go_ibm_db/log2" + trc "github.com/ibmdb/go_ibm_db/log2" "fmt" ) @@ -177,23 +177,23 @@ type ( ) func SQLSetEnvUIntPtrAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/api_unix.go SQLSetEnvUIntPtrAttr() - ENTRY) + trc.Trace1("api/api_unix.go SQLSetEnvUIntPtrAttr() - ENTRY") trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=0x%x, stringLength=%d", attribute, valuePtr, stringLength)) r := C.sqlSetEnvUIntPtrAttr(C.SQLHENV(environmentHandle), C.SQLINTEGER(attribute), C.uintptr_t(valuePtr), C.SQLINTEGER(stringLength)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) - trc.Trace1("api/api_unix.go SQLSetEnvUIntPtrAttr() - EXIT) + trc.Trace1("api/api_unix.go SQLSetEnvUIntPtrAttr() - EXIT") return SQLRETURN(r) } func SQLSetConnectUIntPtrAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/api_unix.go SQLSetConnectUIntPtrAttr() - ENTRY) + trc.Trace1("api/api_unix.go SQLSetConnectUIntPtrAttr() - ENTRY") trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=%x, stringLength=%d", attribute, valuePtr, stringLength)) - + r := C.sqlSetConnectUIntPtrAttr(C.SQLHDBC(connectionHandle), C.SQLINTEGER(attribute), C.uintptr_t(valuePtr), C.SQLINTEGER(stringLength)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) - trc.Trace1("api/api_unix.go SQLSetConnectUIntPtrAttr() - EXIT) + trc.Trace1("api/api_unix.go SQLSetConnectUIntPtrAttr() - EXIT") return SQLRETURN(r) } diff --git a/api/api_windows.go b/api/api_windows.go index 711a55c..fc21602 100644 --- a/api/api_windows.go +++ b/api/api_windows.go @@ -6,7 +6,7 @@ package api import ( "syscall" - trc "github.com/ibmdb/go_ibm_db/log2" + trc "github.com/ibmdb/go_ibm_db/log2" "fmt" ) @@ -112,10 +112,51 @@ const ( SQL_AUTOCOMMIT_ON = 1 SQL_AUTOCOMMIT_DEFAULT = SQL_AUTOCOMMIT_ON SQL_ATTR_PARAMSET_SIZE = 22 + // Statement attributes + SQL_ROW_NUMBER = 14 + + // Statement attributes for ODBC 3.0 + SQL_ATTR_CURSOR_TYPE = 6 + //SQL_ATTR_PARAMSET_SIZE = 22 + SQL_ATTR_ROW_NUMBER = SQL_ROW_NUMBER + SQL_ATTR_ROW_ARRAY_SIZE = 27 + SQL_ATTR_ROW_STATUS_PTR = 25 + SQL_ATTR_ROWS_FETCHED_PTR = 26 + + // SQL_CURSOR_TYPE options + SQL_CURSOR_FORWARD_ONLY = 0 + SQL_CURSOR_KEYSET_DRIVEN = 1 + SQL_CURSOR_DYNAMIC = 2 + SQL_CURSOR_STATIC = 3 + SQL_CURSOR_TYPE_DEFAULT = SQL_CURSOR_FORWARD_ONLY + + // Operations in SQLSetPos + SQL_POSITION = 0 + SQL_REFRESH = 1 + SQL_UPDATE = 2 + SQL_DELETE = 3 + + // Operations in SQLBulkOperations + SQL_ADD = 4 + SQL_SETPOS_MAX_OPTION_VALUE = SQL_ADD + SQL_UPDATE_BY_BOOKMARK = 5 // Check if to be removed + SQL_DELETE_BY_BOOKMARK = 6 + SQL_FETCH_BY_BOOKMARK = 7 + + // Lock options in SQLSetPos + SQL_LOCK_NO_CHANGE = 0 SQL_IS_UINTEGER = -5 SQL_IS_INTEGER = -6 + // Fetch Orientation in SQLFetchScroll + SQL_FETCH_NEXT = 1 + SQL_FETCH_FIRST = 2 + SQL_FETCH_LAST = 3 + SQL_FETCH_PRIOR = 4 + SQL_FETCH_ABSOLUTE = 5 + SQL_FETCH_RELATIVE = 6 + //Connection pooling SQL_ATTR_CONNECTION_POOLING = 201 SQL_ATTR_CP_MATCH = 202 @@ -145,14 +186,15 @@ type ( SQLHSTMT SQLHANDLE SQLHWND uintptr - SQLWCHAR uint16 - SQLSCHAR int8 - SQLSMALLINT int16 - SQLUSMALLINT uint16 - SQLINTEGER int32 - SQLUINTEGER uint32 - SQLPOINTER uintptr - SQLRETURN SQLSMALLINT + SQLWCHAR uint16 + SQLSCHAR int8 + SQLSMALLINT int16 + SQLUSMALLINT uint16 + SQLINTEGER int32 + SQLUINTEGER uint32 + SQLPOINTER uintptr + SQLRETURN SQLSMALLINT + SQLSETPOSIROW SQLUSMALLINT SQLGUID struct { Data1 uint32 @@ -163,24 +205,24 @@ type ( ) func SQLSetEnvUIntPtrAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/api_windows.go SQLSetEnvUIntPtrAttr() - ENTRY") + trc.Trace1("api/api_windows.go SQLSetEnvUIntPtrAttr() - ENTRY") trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=0x%x, stringLength=%d", attribute, valuePtr, stringLength)) - + r0, _, _ := syscall.Syscall6(procSQLSetEnvAttr.Addr(), 4, uintptr(environmentHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength), 0, 0) ret = SQLRETURN(r0) - trc.Trace1(fmt.Sprintf("ret = %d", ret)) + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/api_windows.go SQLSetEnvUIntPtrAttr() - EXIT") return } func SQLSetConnectUIntPtrAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/api_windows.go SQLSetConnectUIntPtrAttr() - ENTRY") + trc.Trace1("api/api_windows.go SQLSetConnectUIntPtrAttr() - ENTRY") trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=%x, stringLength=%d", attribute, valuePtr, stringLength)) - + r0, _, _ := syscall.Syscall6(procSQLSetConnectAttrW.Addr(), 4, uintptr(connectionHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/api_windows.go SQLSetConnectUIntPtrAttr() - EXIT") return diff --git a/api/api_zos.go b/api/api_zos.go index f96be74..571439e 100644 --- a/api/api_zos.go +++ b/api/api_zos.go @@ -10,7 +10,6 @@ import ( "log" "runtime" "unsafe" - "github.com/ibmruntimes/go-recordio/v2/utils" trc "github.com/ibmdb/go_ibm_db/log2" "fmt" @@ -166,21 +165,21 @@ type ( ) func SQLSetEnvUIntPtrAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/api_zos.go SQLSetEnvUIntPtrAttr() - ENTRY") - + trc.Trace1("api/api_zos.go SQLSetEnvUIntPtrAttr() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLSetEnvAttr"), uintptr(environmentHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/api_zos.go SQLSetEnvUIntPtrAttr() - EXIT") return SQLRETURN(r) } func SQLSetConnectUIntPtrAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/api_zos.go SQLSetConnectUIntPtrAttr() - ENTRY") + trc.Trace1("api/api_zos.go SQLSetConnectUIntPtrAttr() - ENTRY") r := utils.CfuncEbcdic(getFunc(&dll, "SQLSetConnectAttr"), uintptr(connectionHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/api_zos.go SQLSetConnectUIntPtrAttr() - EXIT") return SQLRETURN(r) -} \ No newline at end of file +} diff --git a/api/zapi_unix.go b/api/zapi_unix.go index 0b75de3..982bc46 100644 --- a/api/zapi_unix.go +++ b/api/zapi_unix.go @@ -11,7 +11,7 @@ package api import ( - "fmt" + "fmt" "unsafe" trc "github.com/ibmdb/go_ibm_db/log2" ) @@ -23,95 +23,95 @@ import ( import "C" func SQLAllocHandle(handleType SQLSMALLINT, inputHandle SQLHANDLE, outputHandle *SQLHANDLE) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLAllocHandle() - ENTRY") + trc.Trace1("api/zapi_unix.go SQLAllocHandle() - ENTRY") trc.Trace1(fmt.Sprintf("handleType=%d", handleType)) - + r := C.SQLAllocHandle(C.SQLSMALLINT(handleType), C.SQLHANDLE(inputHandle), (*C.SQLHANDLE)(outputHandle)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLAllocHandle() - EXIT") return SQLRETURN(r) } func SQLBindCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, targetType SQLSMALLINT, targetValuePtr []byte, bufferLength SQLLEN, vallen *SQLLEN) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLBindCol() - ENTRY") + trc.Trace1("api/zapi_unix.go SQLBindCol() - ENTRY") trc.Trace1(fmt.Sprintf("columnNumber=%d, targetType=%d, bufferLength=%d", columnNumber, targetType, bufferLength)) r := C.SQLBindCol(C.SQLHSTMT(statementHandle), C.SQLUSMALLINT(columnNumber), C.SQLSMALLINT(targetType), C.SQLPOINTER(&targetValuePtr[0]), C.SQLLEN(bufferLength), (*C.SQLLEN)(vallen)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLBindCol() - EXIT") return SQLRETURN(r) } func SQLBindParameter(statementHandle SQLHSTMT, parameterNumber SQLUSMALLINT, inputOutputType SQLSMALLINT, valueType SQLSMALLINT, parameterType SQLSMALLINT, columnSize SQLULEN, decimalDigits SQLSMALLINT, parameterValue SQLPOINTER, bufferLength SQLLEN, ind *SQLLEN) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLBindParameter() - ENTRY") + trc.Trace1("api/zapi_unix.go SQLBindParameter() - ENTRY") trc.Trace1(fmt.Sprintf("parameterNumber=%d, inputOutputType=%d, valueType=%d, parameterType=%d, columnSize=%d, decimalDigits=%d, parameterValue=%x, bufferLength=%d", parameterNumber, inputOutputType, valueType, parameterType, columnSize, decimalDigits, parameterValue, bufferLength)) r := C.SQLBindParameter(C.SQLHSTMT(statementHandle), C.SQLUSMALLINT(parameterNumber), C.SQLSMALLINT(inputOutputType), C.SQLSMALLINT(valueType), C.SQLSMALLINT(parameterType), C.SQLULEN(columnSize), C.SQLSMALLINT(decimalDigits), C.SQLPOINTER(parameterValue), C.SQLLEN(bufferLength), (*C.SQLLEN)(ind)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLBindParameter() - EXIT") return SQLRETURN(r) } func SQLCloseCursor(statementHandle SQLHSTMT) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLCloseCursor() - ENTRY") - + trc.Trace1("api/zapi_unix.go SQLCloseCursor() - ENTRY") + r := C.SQLCloseCursor(C.SQLHSTMT(statementHandle)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLCloseCursor() - EXIT") 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) { - trc.Trace1("api/zapi_unix.go SQLDescribeCol() - ENTRY") - trc.Trace1(fmt.Sprintf("columnNumber=%d, columnName=%s, bufferLength=%d, nameLengthPtr=0x%x, dataTypePtr=0x%x, columnSizePtr=0x%x, decimalDigitsPtr=%x, nullablePtr=0x%x", columnNumber, *columnName, bufferLength, nameLengthPtr, dataTypePtr, columnSizePtr, decimalDigitsPtr, nullablePtr)) - + trc.Trace1("api/zapi_unix.go SQLDescribeCol() - ENTRY") + trc.Trace1(fmt.Sprintf("columnNumber=%d, columnName=%s, bufferLength=%d, nameLengthPtr=0x%x, dataTypePtr=0x%x, columnSizePtr=0x%x, decimalDigitsPtr=%x, nullablePtr=0x%x", columnNumber, *columnName, bufferLength, nameLengthPtr, dataTypePtr, columnSizePtr, decimalDigitsPtr, nullablePtr)) + 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)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLDescribeCol() - EXIT") return SQLRETURN(r) } func SQLDescribeParam(statementHandle SQLHSTMT, parameterNumber SQLUSMALLINT, dataTypePtr *SQLSMALLINT, parameterSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLDescribeParam() - ENTRY") + trc.Trace1("api/zapi_unix.go SQLDescribeParam() - ENTRY") trc.Trace1(fmt.Sprintf("parameterNumber=%d, dataTypePtr=%x, parameterSizePtr=%x, decimalDigitsPtr=%x, nullablePtr=%x", parameterNumber, dataTypePtr, parameterSizePtr, decimalDigitsPtr, nullablePtr)) - + r := C.SQLDescribeParam(C.SQLHSTMT(statementHandle), C.SQLUSMALLINT(parameterNumber), (*C.SQLSMALLINT)(dataTypePtr), (*C.SQLULEN)(parameterSizePtr), (*C.SQLSMALLINT)(decimalDigitsPtr), (*C.SQLSMALLINT)(nullablePtr)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLDescribeParam() - EXIT") return SQLRETURN(r) } func SQLDisconnect(connectionHandle SQLHDBC) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLDisconnect() - ENTRY") - + trc.Trace1("api/zapi_unix.go SQLDisconnect() - ENTRY") + r := C.SQLDisconnect(C.SQLHDBC(connectionHandle)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLDisconnect() - EXIT") return SQLRETURN(r) } func SQLDriverConnect(connectionHandle SQLHDBC, windowHandle SQLHWND, inConnectionString *SQLWCHAR, stringLength1 SQLSMALLINT, outConnectionString *SQLWCHAR, bufferLength SQLSMALLINT, stringLength2Ptr *SQLSMALLINT, driverCompletion SQLUSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLDriverConnect() - ENTRY") - trc.Trace1(fmt.Sprintf("inConnectionString=%s, stringLength1=%d, outConnectionString=%s, bufferLength=%d, stringLength2Ptr=%x, driverCompletion=%d", inConnectionString, stringLength1, outConnectionString, bufferLength, stringLength2Ptr, driverCompletion)) - + trc.Trace1("api/zapi_unix.go SQLDriverConnect() - ENTRY") + trc.Trace1(fmt.Sprintf("inConnectionString=%s, stringLength1=%d, outConnectionString=%s, bufferLength=%d, stringLength2Ptr=%x, driverCompletion=%d", inConnectionString, stringLength1, outConnectionString, bufferLength, stringLength2Ptr, driverCompletion)) + 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)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLDriverConnect() - EXIT") return SQLRETURN(r) } func SQLEndTran(handleType SQLSMALLINT, handle SQLHANDLE, completionType SQLSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLEndTran() - ENTRY") - trc.Trace1(fmt.Sprintf("handleType=%d, completionType=%d", handleType, completionType)) - + trc.Trace1("api/zapi_unix.go SQLEndTran() - ENTRY") + trc.Trace1(fmt.Sprintf("handleType=%d, completionType=%d", handleType, completionType)) + r := C.SQLEndTran(C.SQLSMALLINT(handleType), C.SQLHANDLE(handle), C.SQLSMALLINT(completionType)) trc.Trace1(fmt.Sprintf("r = %d", r)) @@ -120,182 +120,182 @@ func SQLEndTran(handleType SQLSMALLINT, handle SQLHANDLE, completionType SQLSMAL } func SQLExecute(statementHandle SQLHSTMT) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLExecute() - ENTRY") - + trc.Trace1("api/zapi_unix.go SQLExecute() - ENTRY") + r := C.SQLExecute(C.SQLHSTMT(statementHandle)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLExecute() - EXIT") return SQLRETURN(r) } func SQLFetch(statementHandle SQLHSTMT) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLFetch() - ENTRY") - + trc.Trace1("api/zapi_unix.go SQLFetch() - ENTRY") + r := C.SQLFetch(C.SQLHSTMT(statementHandle)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLFetch() - EXIT") return SQLRETURN(r) } func SQLFreeHandle(handleType SQLSMALLINT, handle SQLHANDLE) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLFreeHandle() - ENTRY") + trc.Trace1("api/zapi_unix.go SQLFreeHandle() - ENTRY") trc.Trace1(fmt.Sprintf("handleType=%d", handleType)) - + r := C.SQLFreeHandle(C.SQLSMALLINT(handleType), C.SQLHANDLE(handle)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLFreeHandle() - EXIT") return SQLRETURN(r) } func SQLGetData(statementHandle SQLHSTMT, colOrParamNum SQLUSMALLINT, targetType SQLSMALLINT, targetValuePtr SQLPOINTER, bufferLength SQLLEN, vallen *SQLLEN) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLGetData() - ENTRY") - trc.Trace1(fmt.Sprintf("colOrParamNum=%d, targetType=%d, targetValuePtr=%x, bufferLength=%d, vallen=%d", colOrParamNum, targetType, targetValuePtr, bufferLength, vallen)) - + trc.Trace1("api/zapi_unix.go SQLGetData() - ENTRY") + trc.Trace1(fmt.Sprintf("colOrParamNum=%d, targetType=%d, targetValuePtr=%x, bufferLength=%d, vallen=%d", colOrParamNum, targetType, targetValuePtr, bufferLength, vallen)) + r := C.SQLGetData(C.SQLHSTMT(statementHandle), C.SQLUSMALLINT(colOrParamNum), C.SQLSMALLINT(targetType), C.SQLPOINTER(targetValuePtr), C.SQLLEN(bufferLength), (*C.SQLLEN)(vallen)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLGetData() - EXIT") return SQLRETURN(r) } func SQLGetDiagRec(handleType SQLSMALLINT, handle SQLHANDLE, recNumber SQLSMALLINT, sqlState *SQLWCHAR, nativeErrorPtr *SQLINTEGER, messageText *SQLWCHAR, bufferLength SQLSMALLINT, textLengthPtr *SQLSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLGetDiagRec() - ENTRY") - trc.Trace1(fmt.Sprintf("handleType=%d, recNumber=%d, sqlState=%s, nativeErrorPtr=%x, messageText=%s, bufferLength=%d, textLengthPtr=%x", handleType, recNumber, sqlState, nativeErrorPtr, messageText, bufferLength, textLengthPtr)) - + trc.Trace1("api/zapi_unix.go SQLGetDiagRec() - ENTRY") + trc.Trace1(fmt.Sprintf("handleType=%d, recNumber=%d, sqlState=%s, nativeErrorPtr=%x, messageText=%s, bufferLength=%d, textLengthPtr=%x", handleType, recNumber, sqlState, nativeErrorPtr, messageText, bufferLength, textLengthPtr)) + 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)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLGetDiagRec() - EXIT") return SQLRETURN(r) } func SQLNumParams(statementHandle SQLHSTMT, parameterCountPtr *SQLSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLNumParams() - ENTRY") - trc.Trace1(fmt.Sprintf("parameterCountPtr=0x%x", parameterCountPtr)) - + trc.Trace1("api/zapi_unix.go SQLNumParams() - ENTRY") + trc.Trace1(fmt.Sprintf("parameterCountPtr=0x%x", parameterCountPtr)) + r := C.SQLNumParams(C.SQLHSTMT(statementHandle), (*C.SQLSMALLINT)(parameterCountPtr)) - trc.Trace1(fmt.Sprintf("r = %d", r)) + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLNumParams() - EXIT") return SQLRETURN(r) } func SQLNumResultCols(statementHandle SQLHSTMT, columnCountPtr *SQLSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLNumResultCols() - ENTRY") + trc.Trace1("api/zapi_unix.go SQLNumResultCols() - ENTRY") trc.Trace1(fmt.Sprintf("columnCountPtr=%x", columnCountPtr)) - + r := C.SQLNumResultCols(C.SQLHSTMT(statementHandle), (*C.SQLSMALLINT)(columnCountPtr)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLNumResultCols() - EXIT") - return SQLRETURN(r) + return SQLRETURN(r) } func SQLPrepare(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLPrepare() - ENTRY") - trc.Trace1(fmt.Sprintf("statementText=%s, textLength=%d", statementText, textLength)) - + trc.Trace1("api/zapi_unix.go SQLPrepare() - ENTRY") + trc.Trace1(fmt.Sprintf("statementText=%s, textLength=%d", statementText, textLength)) + r := C.SQLPrepareW(C.SQLHSTMT(statementHandle), (*C.SQLWCHAR)(unsafe.Pointer(statementText)), C.SQLINTEGER(textLength)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLPrepare() - EXIT") return SQLRETURN(r) } func SQLRowCount(statementHandle SQLHSTMT, rowCountPtr *SQLLEN) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLRowCount() - ENTRY") - + trc.Trace1("api/zapi_unix.go SQLRowCount() - ENTRY") + r := C.SQLRowCount(C.SQLHSTMT(statementHandle), (*C.SQLLEN)(rowCountPtr)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLRowCount() - EXIT") return SQLRETURN(r) } func SQLSetEnvAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLSetEnvAttr() - ENTRY") - trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=0x%x, stringLength=%d", attribute, valuePtr, stringLength)) - + trc.Trace1("api/zapi_unix.go SQLSetEnvAttr() - ENTRY") + trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=0x%x, stringLength=%d", attribute, valuePtr, stringLength)) + r := C.SQLSetEnvAttr(C.SQLHENV(environmentHandle), C.SQLINTEGER(attribute), C.SQLPOINTER(valuePtr), C.SQLINTEGER(stringLength)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLSetEnvAttr() - EXIT") return SQLRETURN(r) } func SQLSetConnectAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLSetConnectAttr() - ENTRY") + trc.Trace1("api/zapi_unix.go SQLSetConnectAttr() - ENTRY") trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=0x%x, stringLength=%d", attribute, valuePtr, stringLength)) - - r := C.SQLSetConnectAttrW(C.SQLHDBC(connectionHandle), C.SQLINTEGER(attribute), C.SQLPOINTER(valuePtr), C.SQLINTEGER(stringLength)) - + + r := C.SQLSetConnectAttrW(C.SQLHDBC(connectionHandle), C.SQLINTEGER(attribute), C.SQLPOINTER(valuePtr), C.SQLINTEGER(stringLength)) + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLSetConnectAttr() - EXIT") return SQLRETURN(r) } func SQLColAttribute(statementHandle SQLHSTMT, ColumnNumber SQLUSMALLINT, FieldIdentifier SQLUSMALLINT, CharacterAttributePtr SQLPOINTER, BufferLength SQLSMALLINT, StringLengthPtr *SQLSMALLINT, NumericAttributePtr SQLPOINTER) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLColAttribute() - ENTRY") + trc.Trace1("api/zapi_unix.go SQLColAttribute() - ENTRY") trc.Trace1(fmt.Sprintf("ColumnNumber=%d, FieldIdentifier=%d, CharacterAttributePtr=0x%x, BufferLength=%d, StringLengthPtr=0x%x, NumericAttributePtr=0x%x", ColumnNumber, FieldIdentifier, CharacterAttributePtr, BufferLength, StringLengthPtr, NumericAttributePtr)) - - r := C.SQLColAttribute(C.SQLHSTMT(statementHandle), C.SQLUSMALLINT(ColumnNumber), C.SQLUSMALLINT(FieldIdentifier), C.SQLPOINTER(CharacterAttributePtr), C.SQLSMALLINT(BufferLength), - ENTRY")(*C.SQLSMALLINT)(unsafe.Pointer(StringLengthPtr)), (C.SQLPOINTER)(NumericAttributePtr)) - + + r := C.SQLColAttribute(C.SQLHSTMT(statementHandle), C.SQLUSMALLINT(ColumnNumber), C.SQLUSMALLINT(FieldIdentifier), C.SQLPOINTER(CharacterAttributePtr), C.SQLSMALLINT(BufferLength),(*C.SQLSMALLINT)(unsafe.Pointer(StringLengthPtr)), (C.SQLPOINTER)(NumericAttributePtr)) + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLColAttribute() - EXIT") return SQLRETURN(r) } func SQLMoreResults(statementHandle SQLHSTMT) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLMoreResults() - ENTRY") - + trc.Trace1("api/zapi_unix.go SQLMoreResults() - ENTRY") + r := C.SQLMoreResults(C.SQLHSTMT(statementHandle)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLMoreResults() - EXIT") return SQLRETURN(r) } func SQLSetStmtAttr(statementHandle SQLHSTMT, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLSetStmtAttr() - ENTRY") + trc.Trace1("api/zapi_unix.go SQLSetStmtAttr() - ENTRY") trc.Trace1(fmt.Sprintf("attribute=%d, stringLength=%d", attribute, stringLength)) - + r := C.SQLSetStmtAttrW(C.SQLHSTMT(statementHandle), C.SQLINTEGER(attribute), C.SQLPOINTER(valuePtr), C.SQLINTEGER(stringLength)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLSetStmtAttr() - EXIT") return SQLRETURN(r) } func SQLCreateDb(connectionHandle SQLHDBC, dbnamePtr *SQLWCHAR, dbnameLen SQLINTEGER, codeSetPtr *SQLWCHAR, codeSetLen SQLINTEGER, modePtr *SQLWCHAR, modeLen SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLCreateDb() - ENTRY") + trc.Trace1("api/zapi_unix.go SQLCreateDb() - ENTRY") trc.Trace1(fmt.Sprintf("dbnamePtr=%x,dbnameLen=%d, codeSetPtr=%x, codeSetLen=%d, modePtr=%x, modeLen=%d", dbnamePtr, dbnameLen, codeSetPtr, codeSetLen, modePtr, modeLen)) - + r := C.SQLCreateDbW(C.SQLHDBC(connectionHandle), (*C.SQLWCHAR)(unsafe.Pointer(dbnamePtr)), C.SQLINTEGER(dbnameLen), (*C.SQLWCHAR)(unsafe.Pointer(codeSetPtr)), C.SQLINTEGER(codeSetLen), (*C.SQLWCHAR)(unsafe.Pointer(modePtr)), C.SQLINTEGER(modeLen)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLCreateDb() - EXIT") return SQLRETURN(r) } func SQLDropDb(connectionHandle SQLHDBC, dbnamePtr *SQLWCHAR, dbnameLen SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLDropDb() - ENTRY") + trc.Trace1("api/zapi_unix.go SQLDropDb() - ENTRY") trc.Trace1(fmt.Sprintf("dbnamePtr=%x, dbnameLen=%d", dbnamePtr, dbnameLen)) - + r := C.SQLDropDbW(C.SQLHDBC(connectionHandle), (*C.SQLWCHAR)(unsafe.Pointer(dbnamePtr)), C.SQLINTEGER(dbnameLen)) - + trc.Trace1("api/zapi_unix.go SQLDropDb() - EXIT") return SQLRETURN(r) } func SQLExecDirect(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_unix.go SQLExecDirect() - ENTRY") + trc.Trace1("api/zapi_unix.go SQLExecDirect() - ENTRY") trc.Trace1(fmt.Sprintf("statementText=%s, textLength=%d", statementText, textLength)) - + r := C.SQLExecDirectW(C.SQLHSTMT(statementHandle), (*C.SQLWCHAR)(unsafe.Pointer(statementText)), C.SQLINTEGER(textLength)) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_unix.go SQLExecDirect() - EXIT") return SQLRETURN(r) diff --git a/api/zapi_windows.go b/api/zapi_windows.go index 3b29d91..356fbb2 100644 --- a/api/zapi_windows.go +++ b/api/zapi_windows.go @@ -7,7 +7,7 @@ import ( "os" "syscall" "unsafe" - trc "github.com/ibmdb/go_ibm_db/log2" + trc "github.com/ibmdb/go_ibm_db/log2" "fmt" ) @@ -25,6 +25,7 @@ var ( procSQLEndTran = mododbc32.NewProc("SQLEndTran") procSQLExecute = mododbc32.NewProc("SQLExecute") procSQLFetch = mododbc32.NewProc("SQLFetch") + procSQLFetchScroll = mododbc32.NewProc("SQLFetchScroll") procSQLFreeHandle = mododbc32.NewProc("SQLFreeHandle") procSQLGetData = mododbc32.NewProc("SQLGetData") procSQLGetDiagRecW = mododbc32.NewProc("SQLGetDiagRecW") @@ -37,13 +38,17 @@ var ( procSQLSetConnectAttrW = mododbc32.NewProc("SQLSetConnectAttrW") procSQLColAttribute = mododbc32.NewProc("SQLColAttribute") procSQLMoreResults = mododbc32.NewProc("SQLMoreResults") + procSQLSetStmtAttr = mododbc32.NewProc("SQLSetStmtAttr") procSQLSetStmtAttrW = mododbc32.NewProc("SQLSetStmtAttrW") + procSQLGetStmtAttr = mododbc32.NewProc("SQLGetStmtAttr") + procSQLSetPos = mododbc32.NewProc("SQLSetPos") + procSQLBulkOperations = mododbc32.NewProc("SQLBulkOperations") procSQLCreateDb = mododbc32.NewProc("SQLCreateDbW") procSQLDropDb = mododbc32.NewProc("SQLDropDbW") ) func GetDllName() string { - trc.Trace1("api/zapi_windows.go GetDllName()") + trc.Trace1("api/zapi_windows.go GetDllName()") if winArch := os.Getenv("PROCESSOR_ARCHITECTURE"); winArch == "x86" { trc.Trace1("winArch is x86 and db2cli.dll") return "db2cli.dll" @@ -54,259 +59,271 @@ func GetDllName() string { } func SQLAllocHandle(handleType SQLSMALLINT, inputHandle SQLHANDLE, outputHandle *SQLHANDLE) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLAllocHandle() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLAllocHandle() - ENTRY") trc.Trace1(fmt.Sprintf("handleType=%d", handleType)) - + r0, _, _ := syscall.Syscall(procSQLAllocHandle.Addr(), 3, uintptr(handleType), uintptr(inputHandle), uintptr(unsafe.Pointer(outputHandle))) ret = SQLRETURN(r0) - - trc.Trace1(fmt.Sprintf("ret = %d", ret)) + + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLAllocHandle()- EXIT") return } func SQLBindCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, targetType SQLSMALLINT, targetValuePtr []byte, bufferLength SQLLEN, vallen *SQLLEN) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLBindCol() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLBindCol() - ENTRY") trc.Trace1(fmt.Sprintf("columnNumber=%d, targetType=%d, bufferLength=%d", columnNumber, targetType, bufferLength)) - + r0, _, _ := syscall.Syscall6(procSQLBindCol.Addr(), 6, uintptr(statementHandle), uintptr(columnNumber), uintptr(targetType), uintptr(unsafe.Pointer(&targetValuePtr[0])), uintptr(bufferLength), uintptr(unsafe.Pointer(vallen))) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLBindCol()- EXIT") return } func SQLBindParameter(statementHandle SQLHSTMT, parameterNumber SQLUSMALLINT, inputOutputType SQLSMALLINT, valueType SQLSMALLINT, parameterType SQLSMALLINT, columnSize SQLULEN, decimalDigits SQLSMALLINT, parameterValue SQLPOINTER, bufferLength SQLLEN, ind *SQLLEN) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLBindParameter() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLBindParameter() - ENTRY") trc.Trace1(fmt.Sprintf("parameterNumber=%d, inputOutputType=%d, valueType=%d, parameterType=%d, columnSize=%d, decimalDigits=%d, parameterValue=%x, bufferLength=%d", parameterNumber, inputOutputType, valueType, parameterType, columnSize, decimalDigits, parameterValue, bufferLength)) - + r0, _, _ := syscall.Syscall12(procSQLBindParameter.Addr(), 10, uintptr(statementHandle), uintptr(parameterNumber), uintptr(inputOutputType), uintptr(valueType), uintptr(parameterType), uintptr(columnSize), uintptr(decimalDigits), uintptr(parameterValue), uintptr(bufferLength), uintptr(unsafe.Pointer(ind)), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLBindParameter()- EXIT") return } func SQLCloseCursor(statementHandle SQLHSTMT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLCloseCursor() - ENTRY") - + trc.Trace1("api/zapi_windows.go SQLCloseCursor() - ENTRY") + r0, _, _ := syscall.Syscall(procSQLCloseCursor.Addr(), 1, uintptr(statementHandle), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLCloseCursor() - EXIT") return } func SQLDescribeCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, columnName *SQLWCHAR, bufferLength SQLSMALLINT, nameLengthPtr *SQLSMALLINT, dataTypePtr *SQLSMALLINT, columnSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLDescribeCol() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLDescribeCol() - ENTRY") trc.Trace1(fmt.Sprintf("columnNumber=%d, columnName=%s, bufferLength=%d, nameLengthPtr=0x%x, dataTypePtr=0x%x, columnSizePtr=0x%x, decimalDigitsPtr=%x, nullablePtr=0x%x", columnNumber, *columnName, bufferLength, nameLengthPtr, dataTypePtr, columnSizePtr, decimalDigitsPtr, nullablePtr)) - + 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))) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLDescribeCol()- EXIT") return } func SQLDescribeParam(statementHandle SQLHSTMT, parameterNumber SQLUSMALLINT, dataTypePtr *SQLSMALLINT, parameterSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLDescribeParam() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLDescribeParam() - ENTRY") trc.Trace1(fmt.Sprintf("parameterNumber=%d, dataTypePtr=%x, parameterSizePtr=%x, decimalDigitsPtr=%x, nullablePtr=%x", parameterNumber, dataTypePtr, parameterSizePtr, decimalDigitsPtr, nullablePtr)) r0, _, _ := syscall.Syscall6(procSQLDescribeParam.Addr(), 6, uintptr(statementHandle), uintptr(parameterNumber), uintptr(unsafe.Pointer(dataTypePtr)), uintptr(unsafe.Pointer(parameterSizePtr)), uintptr(unsafe.Pointer(decimalDigitsPtr)), uintptr(unsafe.Pointer(nullablePtr))) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLDescribeParam()- EXIT") return } func SQLDisconnect(connectionHandle SQLHDBC) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLDisconnect() - ENTRY") - + trc.Trace1("api/zapi_windows.go SQLDisconnect() - ENTRY") + r0, _, _ := syscall.Syscall(procSQLDisconnect.Addr(), 1, uintptr(connectionHandle), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLDisconnect()- EXIT") return } func SQLDriverConnect(connectionHandle SQLHDBC, windowHandle SQLHWND, inConnectionString *SQLWCHAR, stringLength1 SQLSMALLINT, outConnectionString *SQLWCHAR, bufferLength SQLSMALLINT, stringLength2Ptr *SQLSMALLINT, driverCompletion SQLUSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLDriverConnect()- ENTRY") + trc.Trace1("api/zapi_windows.go SQLDriverConnect()- ENTRY") trc.Trace1(fmt.Sprintf("inConnectionString=%s, stringLength1=%d, outConnectionString=%s, bufferLength=%d, stringLength2Ptr=%x, driverCompletion=%d", inConnectionString, stringLength1, outConnectionString, bufferLength, stringLength2Ptr, driverCompletion)) - + 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) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLDriverConnect()- EXIT") return } func SQLEndTran(handleType SQLSMALLINT, handle SQLHANDLE, completionType SQLSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLEndTran() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLEndTran() - ENTRY") trc.Trace1(fmt.Sprintf("completionType=%d", completionType)) - + r0, _, _ := syscall.Syscall(procSQLEndTran.Addr(), 3, uintptr(handleType), uintptr(handle), uintptr(completionType)) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLEndTran()- EXIT") return } func SQLExecute(statementHandle SQLHSTMT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLExecute() - ENTRY") - + trc.Trace1("api/zapi_windows.go SQLExecute() - ENTRY") + r0, _, _ := syscall.Syscall(procSQLExecute.Addr(), 1, uintptr(statementHandle), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLExecute()- EXIT") return } func SQLFetch(statementHandle SQLHSTMT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLFetch() - ENTRY") - + trc.Trace1("api/zapi_windows.go SQLFetch() - ENTRY") + r0, _, _ := syscall.Syscall(procSQLFetch.Addr(), 1, uintptr(statementHandle), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLFetch()- EXIT") return } +func SQLFetchScroll(statementHandle SQLHSTMT, fetchOrientation SQLUSMALLINT, fetchOffset SQLLEN) (ret SQLRETURN) { + trc.Trace1("api/zapi_windows.go SQLFetchScroll() - ENTRY") + trc.Trace1(fmt.Sprintf("fetchOrientation=%d, fetchOffset=%d", fetchOrientation, fetchOffset)) + + r0, _, _ := syscall.Syscall(procSQLFetch.Addr(), 3, uintptr(statementHandle), uintptr(fetchOrientation), uintptr(fetchOffset)) + ret = SQLRETURN(r0) + + trc.Trace1(fmt.Sprintf("ret = %d", ret)) + trc.Trace1("api/zapi_windows.go SQLFetchScroll()- EXIT") + return +} + func SQLFreeHandle(handleType SQLSMALLINT, handle SQLHANDLE) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLFreeHandle() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLFreeHandle() - ENTRY") trc.Trace1(fmt.Sprintf("handleType=%d", handleType)) - + r0, _, _ := syscall.Syscall(procSQLFreeHandle.Addr(), 2, uintptr(handleType), uintptr(handle), 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLFreeHandle()- EXIT") return } func SQLGetData(statementHandle SQLHSTMT, colOrParamNum SQLUSMALLINT, targetType SQLSMALLINT, targetValuePtr SQLPOINTER, bufferLength SQLLEN, vallen *SQLLEN) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLGetData() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLGetData() - ENTRY") trc.Trace1(fmt.Sprintf("colOrParamNum=%d, targetType=%d, targetValuePtr=%x, bufferLength=%d, vallen=%d", colOrParamNum, targetType, targetValuePtr, bufferLength, vallen)) - + r0, _, _ := syscall.Syscall6(procSQLGetData.Addr(), 6, uintptr(statementHandle), uintptr(colOrParamNum), uintptr(targetType), uintptr(targetValuePtr), uintptr(bufferLength), uintptr(unsafe.Pointer(vallen))) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLGetData()- EXIT") return } func SQLGetDiagRec(handleType SQLSMALLINT, handle SQLHANDLE, recNumber SQLSMALLINT, sqlState *SQLWCHAR, nativeErrorPtr *SQLINTEGER, messageText *SQLWCHAR, bufferLength SQLSMALLINT, textLengthPtr *SQLSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLGetDiagRec() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLGetDiagRec() - ENTRY") trc.Trace1(fmt.Sprintf("handleType=%d, recNumber=%d, sqlState=%s, nativeErrorPtr=%x, messageText=%s, bufferLength=%d, textLengthPtr=%x", handleType, recNumber, sqlState, nativeErrorPtr, messageText, bufferLength, textLengthPtr)) - + 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) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLGetDiagRec()- EXIT") return } func SQLNumParams(statementHandle SQLHSTMT, parameterCountPtr *SQLSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLNumParams() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLNumParams() - ENTRY") trc.Trace1(fmt.Sprintf("parameterCountPtr=%x", parameterCountPtr)) - + r0, _, _ := syscall.Syscall(procSQLNumParams.Addr(), 2, uintptr(statementHandle), uintptr(unsafe.Pointer(parameterCountPtr)), 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLNumParams()- EXIT") return } func SQLNumResultCols(statementHandle SQLHSTMT, columnCountPtr *SQLSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLNumResultCols() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLNumResultCols() - ENTRY") trc.Trace1(fmt.Sprintf("columnCountPtr=%x", columnCountPtr)) - + r0, _, _ := syscall.Syscall(procSQLNumResultCols.Addr(), 2, uintptr(statementHandle), uintptr(unsafe.Pointer(columnCountPtr)), 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLNumResultCols()- EXIT") return } func SQLPrepare(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLPrepare() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLPrepare() - ENTRY") trc.Trace1(fmt.Sprintf("statementText=%s, textLength=%d", statementText, textLength)) - + r0, _, _ := syscall.Syscall(procSQLPrepareW.Addr(), 3, uintptr(statementHandle), uintptr(unsafe.Pointer(statementText)), uintptr(textLength)) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLPrepare()- EXIT") return } func SQLRowCount(statementHandle SQLHSTMT, rowCountPtr *SQLLEN) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLRowCount() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLRowCount() - ENTRY") trc.Trace1(fmt.Sprintf("rowCountPtr=0x%x", rowCountPtr)) - + r0, _, _ := syscall.Syscall(procSQLRowCount.Addr(), 2, uintptr(statementHandle), uintptr(unsafe.Pointer(rowCountPtr)), 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLRowCount()- EXIT") return } func SQLSetEnvAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLSetEnvAttr() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLSetEnvAttr() - ENTRY") trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=0x%x, stringLength=%d", attribute, valuePtr, stringLength)) r0, _, _ := syscall.Syscall6(procSQLSetEnvAttr.Addr(), 4, uintptr(environmentHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLSetEnvAttr()- EXIT") return } func SQLSetConnectAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLSetConnectAttr() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLSetConnectAttr() - ENTRY") trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=0x%x, stringLength=%d", attribute, valuePtr, stringLength)) - + r0, _, _ := syscall.Syscall6(procSQLSetConnectAttrW.Addr(), 4, uintptr(connectionHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLSetConnectAttr()- EXIT") return } func SQLColAttribute(statementHandle SQLHSTMT, ColumnNumber SQLUSMALLINT, FieldIdentifier SQLUSMALLINT, CharacterAttributePtr SQLPOINTER, BufferLength SQLSMALLINT, StringLengthPtr *SQLSMALLINT, NumericAttributePtr SQLPOINTER) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLColAttribute() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLColAttribute() - ENTRY") trc.Trace1(fmt.Sprintf("ColumnNumber=%d, FieldIdentifier=%d, CharacterAttributePtr=0x%x, BufferLength=%d, StringLengthPtr=0x%x, NumericAttributePtr=0x%x", ColumnNumber, FieldIdentifier, CharacterAttributePtr, BufferLength, StringLengthPtr, NumericAttributePtr)) - + r0, _, _ := syscall.Syscall9(procSQLColAttribute.Addr(), 7, uintptr(statementHandle), uintptr(ColumnNumber), uintptr(FieldIdentifier), uintptr(CharacterAttributePtr), uintptr(BufferLength), uintptr(unsafe.Pointer(StringLengthPtr)), uintptr(NumericAttributePtr), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLColAttribute()- EXIT") return } func SQLMoreResults(statementHandle SQLHSTMT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLMoreResults() - ENTRY") - + trc.Trace1("api/zapi_windows.go SQLMoreResults() - ENTRY") + r0, _, _ := syscall.Syscall(procSQLMoreResults.Addr(), 1, uintptr(statementHandle), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLMoreResults()- EXIT") return @@ -315,70 +332,82 @@ func SQLMoreResults(statementHandle SQLHSTMT) (ret SQLRETURN) { func SQLSetStmtAttr(statementHandle SQLHSTMT, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) { trc.Trace1("api/zapi_windows.go SQLSetStmtAttr() - ENTRY") trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=0x%x, stringLength=%d", attribute, valuePtr, stringLength)) - + r0, _, _ := syscall.Syscall6(procSQLSetStmtAttr.Addr(), 4, uintptr(statementHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLSetStmtAttr()- EXIT") return } +func SQLGetStmtAttr(environmentHandle SQLHSTMT, attribute SQLINTEGER, targetValuePtr []byte, stringLength SQLINTEGER) (ret SQLRETURN) { + trc.Trace1("api/zapi_windows.go SQLGetStmtAttr() - ENTRY") + trc.Trace1(fmt.Sprintf("attribute=%d, stringLength=%d", attribute, stringLength)) + + r0, _, _ := syscall.Syscall6(procSQLGetStmtAttr.Addr(), 4, uintptr(environmentHandle), uintptr(attribute), uintptr(unsafe.Pointer(&targetValuePtr[0])), uintptr(stringLength), 0, 0) + ret = SQLRETURN(r0) + + trc.Trace1(fmt.Sprintf("ret = %d", ret)) + trc.Trace1("api/zapi_windows.go SQLGetStmtAttr()- EXIT") + return +} + func SQLSetPos(statementHandle SQLHSTMT, rowNumber SQLSETPOSIROW, operation SQLUSMALLINT, lockType SQLUSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLSetPos() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLSetPos() - ENTRY") trc.Trace1(fmt.Sprintf("rowNumber=%d, operation=%d, lockType=%d", rowNumber, operation, lockType)) - + r0, _, _ := syscall.Syscall6(procSQLSetPos.Addr(), 4, uintptr(statementHandle), uintptr(rowNumber), uintptr(operation), uintptr(lockType), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLSetPos()- EXIT") return } func SQLBulkOperations(statementHandle SQLHSTMT, operation SQLSMALLINT) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLBulkOperations() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLBulkOperations() - ENTRY") trc.Trace1(fmt.Sprintf("operation=%d", operation)) - + r0, _, _ := syscall.Syscall6(procSQLBulkOperations.Addr(), 2, uintptr(statementHandle), uintptr(operation), 0, 0, 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLBulkOperations()- EXIT") return } func SQLCreateDb(connectionHandle SQLHDBC, dbnamePtr *SQLWCHAR, dbnameLen SQLINTEGER, codeSetPtr *SQLWCHAR, codeSetLen SQLINTEGER, modePtr *SQLWCHAR, modeLen SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLCreateDb() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLCreateDb() - ENTRY") trc.Trace1(fmt.Sprintf("dbnamePtr=%x,dbnameLen=%d, codeSetPtr=%x, codeSetLen=%d, modePtr=%x, modeLen=%d", dbnamePtr, dbnameLen, codeSetPtr, codeSetLen, modePtr, modeLen)) - + r0, _, _ := syscall.Syscall9(procSQLCreateDb.Addr(), 7, uintptr(connectionHandle), uintptr(unsafe.Pointer(dbnamePtr)), uintptr(dbnameLen), uintptr(unsafe.Pointer(codeSetPtr)), uintptr(codeSetLen), uintptr(unsafe.Pointer(modePtr)), uintptr(modeLen), 0, 0) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLCreateDb()- EXIT") return } func SQLDropDb(connectionHandle SQLHDBC, dbnamePtr *SQLWCHAR, dbnameLen SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLDropDb() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLDropDb() - ENTRY") trc.Trace1(fmt.Sprintf("dbnamePtr=%x, dbnameLen=%d", dbnamePtr, dbnameLen)) - + r0, _, _ := syscall.Syscall(procSQLDropDb.Addr(), 3, uintptr(connectionHandle), uintptr(unsafe.Pointer(dbnamePtr)), uintptr(dbnameLen)) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLDropDb()- EXIT") return } func SQLExecDirect(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (ret SQLRETURN) { - trc.Trace1("api/zapi_windows.go SQLExecDirect() - ENTRY") + trc.Trace1("api/zapi_windows.go SQLExecDirect() - ENTRY") trc.Trace1(fmt.Sprintf("statementText=%s, textLength=%d", statementText, textLength)) - + r0, _, _ := syscall.Syscall(procSQLExecDirectW.Addr(), 3, uintptr(statementHandle), uintptr(unsafe.Pointer(statementText)), uintptr(textLength)) ret = SQLRETURN(r0) - + trc.Trace1(fmt.Sprintf("ret = %d", ret)) trc.Trace1("api/zapi_windows.go SQLExecDirect()- EXIT") return diff --git a/api/zapi_zos.go b/api/zapi_zos.go index f76e77c..c611ad9 100644 --- a/api/zapi_zos.go +++ b/api/zapi_zos.go @@ -27,238 +27,238 @@ func init() { } func SQLAllocHandle(handleType SQLSMALLINT, inputHandle SQLHANDLE, outputHandle *SQLHANDLE) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLAllocHandle() - ENTRY") + trc.Trace1("api/zapi_zos.go SQLAllocHandle() - ENTRY") trc.Trace1(fmt.Sprintf("handleType = %d", handleType)) - + r := utils.CfuncEbcdic(getFunc(&dll, "SQLAllocHandle"), uintptr(handleType), uintptr(inputHandle), uintptr(unsafe.Pointer(outputHandle))) - + trc.Trace1(fmt.Sprintf("r = %d", r)) trc.Trace1("api/zapi_zos.go SQLAllocHandle() - EXIT") return SQLRETURN(r) } func SQLBindCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, targetType SQLSMALLINT, targetValuePtr []byte, bufferLength SQLLEN, vallen *SQLLEN) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLBindCol() - ENTRY") + trc.Trace1("api/zapi_zos.go SQLBindCol() - ENTRY") trc.Trace1(fmt.Sprintf("columnNumber=%d, targetType=%d, bufferLength=%d, vallen=%d", columnNumber, targetType, bufferLength, vallen)) - + r := utils.CfuncEbcdic(getFunc(&dll, "SQLBindCol"), uintptr(statementHandle), uintptr(columnNumber), uintptr(targetType), uintptr(unsafe.Pointer(&targetValuePtr[0])), uintptr(bufferLength), uintptr(unsafe.Pointer(vallen))) - + trc.Trace1("api/zapi_zos.go SQLBindCol() - EXIT") return SQLRETURN(r) } func SQLBindParameter(statementHandle SQLHSTMT, parameterNumber SQLUSMALLINT, inputOutputType SQLSMALLINT, valueType SQLSMALLINT, parameterType SQLSMALLINT, columnSize SQLULEN, decimalDigits SQLSMALLINT, parameterValue SQLPOINTER, bufferLength SQLLEN, ind *SQLLEN) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLBindParameter() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLBindParameter() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLBindParameter"), uintptr(statementHandle), uintptr(parameterNumber), uintptr(inputOutputType), uintptr(valueType), uintptr(parameterType), uintptr(columnSize), uintptr(decimalDigits), uintptr(parameterValue), uintptr(bufferLength), uintptr(unsafe.Pointer(ind))) - + trc.Trace1("api/zapi_zos.go SQLBindParameter() - EXIT") return SQLRETURN(r) } func SQLCloseCursor(statementHandle SQLHSTMT) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLCloseCursor() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLCloseCursor() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLCloseCursor"), uintptr(statementHandle)) - + trc.Trace1("api/zapi_zos.go SQLCloseCursor() - EXIT") return SQLRETURN(r) } func SQLDescribeCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, columnName *SQLWCHAR, bufferLength SQLSMALLINT, nameLengthPtr *SQLSMALLINT, dataTypePtr *SQLSMALLINT, columnSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) SQLRETURN { - trc.Trace1("api/zapi_zos.go SQLDescribeCol() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLDescribeCol() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLDescribeColW"), 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))) - + trc.Trace1("api/zapi_zos.go SQLDescribeCol() - EXIT") return SQLRETURN(r) } func SQLDescribeParam(statementHandle SQLHSTMT, parameterNumber SQLUSMALLINT, dataTypePtr *SQLSMALLINT, parameterSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLDescribeParam() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLDescribeParam() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLDescribeParam"), uintptr(statementHandle), uintptr(parameterNumber), uintptr(unsafe.Pointer(dataTypePtr)), uintptr(unsafe.Pointer(parameterSizePtr)), uintptr(unsafe.Pointer(decimalDigitsPtr)), uintptr(unsafe.Pointer(nullablePtr))) - + trc.Trace1("api/zapi_zos.go SQLDescribeParam() - EXIT") return SQLRETURN(r) } func SQLDisconnect(connectionHandle SQLHDBC) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLDisconnect() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLDisconnect() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLDisconnect"), uintptr(connectionHandle)) - + trc.Trace1("api/zapi_zos.go SQLDisconnect() - EXIT") return SQLRETURN(r) } func SQLDriverConnect(connectionHandle SQLHDBC, windowHandle SQLHWND, inConnectionString *SQLWCHAR, stringLength1 SQLSMALLINT, outConnectionString *SQLWCHAR, bufferLength SQLSMALLINT, stringLength2Ptr *SQLSMALLINT, driverCompletion SQLUSMALLINT) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLDriverConnect() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLDriverConnect() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLDriverConnectW"),uintptr(connectionHandle), uintptr(windowHandle), uintptr(unsafe.Pointer(inConnectionString)), uintptr(stringLength1), uintptr(unsafe.Pointer(outConnectionString)), uintptr(bufferLength), uintptr(unsafe.Pointer(stringLength2Ptr)), uintptr(driverCompletion)) - + trc.Trace1("api/zapi_zos.go SQLDriverConnect() - EXIT") return SQLRETURN(r) } func SQLEndTran(handleType SQLSMALLINT, handle SQLHANDLE, completionType SQLSMALLINT) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLEndTran() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLEndTran() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLEndTran"), uintptr(handleType), uintptr(handle), uintptr(completionType)) - + trc.Trace1("api/zapi_zos.go SQLEndTran() - EXIT") return SQLRETURN(r) } func SQLExecute(statementHandle SQLHSTMT) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLExecute() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLExecute() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLExecute"), uintptr(statementHandle)) - + trc.Trace1("api/zapi_zos.go SQLExecute() - EXIT") return SQLRETURN(r) } func SQLFetch(statementHandle SQLHSTMT) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLFetch() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLFetch() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLFetch"), uintptr(statementHandle)) - + trc.Trace1("api/zapi_zos.go SQLFetch() - EXIT") return SQLRETURN(r) } func SQLFreeHandle(handleType SQLSMALLINT, handle SQLHANDLE) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLFreeHandle() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLFreeHandle() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLFreeHandle"), uintptr(handleType), uintptr(handle)) - + trc.Trace1("api/zapi_zos.go SQLFreeHandle() - EXIT") return SQLRETURN(r) } func SQLGetData(statementHandle SQLHSTMT, colOrParamNum SQLUSMALLINT, targetType SQLSMALLINT, targetValuePtr SQLPOINTER, bufferLength SQLLEN, vallen *SQLLEN) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLGetData() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLGetData() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLGetData"), uintptr(statementHandle), uintptr(colOrParamNum), uintptr(targetType), uintptr(targetValuePtr), uintptr(bufferLength), uintptr(unsafe.Pointer(vallen))) - + trc.Trace1("api/zapi_zos.go SQLGetData() - EXIT") return SQLRETURN(r) } func SQLGetDiagRec(handleType SQLSMALLINT, handle SQLHANDLE, recNumber SQLSMALLINT, sqlState *SQLWCHAR, nativeErrorPtr *SQLINTEGER, messageText *SQLWCHAR, bufferLength SQLSMALLINT, textLengthPtr *SQLSMALLINT) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLGetDiagRec() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLGetDiagRec() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLGetDiagRecW"), uintptr(handleType), uintptr(handle), uintptr(recNumber), uintptr(unsafe.Pointer(sqlState)), uintptr(unsafe.Pointer(nativeErrorPtr)), uintptr(unsafe.Pointer(messageText)), uintptr(bufferLength), uintptr(unsafe.Pointer(textLengthPtr))) - + trc.Trace1("api/zapi_zos.go SQLGetDiagRec() - EXIT") return SQLRETURN(r) } func SQLNumParams(statementHandle SQLHSTMT, parameterCountPtr *SQLSMALLINT) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLNumParams() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLNumParams() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLNumParams"), uintptr(statementHandle), uintptr(unsafe.Pointer(parameterCountPtr))) - + trc.Trace1("api/zapi_zos.go SQLNumParams() - EXIT") return SQLRETURN(r) } func SQLNumResultCols(statementHandle SQLHSTMT, columnCountPtr *SQLSMALLINT) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLNumResultCols() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLNumResultCols() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLNumResultCols"), uintptr(statementHandle), uintptr(unsafe.Pointer(columnCountPtr))) - + trc.Trace1("api/zapi_zos.go SQLNumResultCols() - EXIT") return SQLRETURN(r) } func SQLPrepare(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLPrepare() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLPrepare() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLPrepareW"), uintptr(statementHandle), uintptr(unsafe.Pointer(statementText)), uintptr(textLength)) - + trc.Trace1("api/zapi_zos.go SQLPrepare() - EXIT") return SQLRETURN(r) } func SQLRowCount(statementHandle SQLHSTMT, rowCountPtr *SQLLEN) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLRowCount() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLRowCount() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLRowCount"), uintptr(statementHandle), uintptr(unsafe.Pointer(rowCountPtr))) - + trc.Trace1("api/zapi_zos.go SQLRowCount() - EXIT") return SQLRETURN(r) } func SQLSetEnvAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLSetEnvAttr() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLSetEnvAttr() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLSetEnvAttr"), uintptr(environmentHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength)) - + trc.Trace1("api/zapi_zos.go SQLSetEnvAttr() - EXIT") return SQLRETURN(r) } func SQLSetConnectAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLSetConnectAttr() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLSetConnectAttr() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLSetConnectAttrW"), uintptr(connectionHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength)) - + trc.Trace1("api/zapi_zos.go SQLSetConnectAttr() - EXIT") return SQLRETURN(r) } func SQLColAttribute(statementHandle SQLHSTMT, ColumnNumber SQLUSMALLINT, FieldIdentifier SQLUSMALLINT, CharacterAttributePtr SQLPOINTER, BufferLength SQLSMALLINT, StringLengthPtr *SQLSMALLINT, NumericAttributePtr SQLPOINTER) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLColAttribute() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLColAttribute() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLColAttribute"), uintptr(statementHandle), uintptr(ColumnNumber), uintptr(FieldIdentifier), uintptr(CharacterAttributePtr), uintptr(BufferLength), uintptr(unsafe.Pointer(StringLengthPtr)), uintptr(NumericAttributePtr)) - + trc.Trace1("api/zapi_zos.go SQLColAttribute() - EXIT") return SQLRETURN(r) } func SQLMoreResults(statementHandle SQLHSTMT) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLMoreResults() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLMoreResults() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLMoreResults"), uintptr(statementHandle)) - + trc.Trace1("api/zapi_zos.go SQLMoreResults() - EXIT") return SQLRETURN(r) } func SQLSetStmtAttr(statementHandle SQLHSTMT, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLSetStmtAttr() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLSetStmtAttr() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLSetStmtAttr"), uintptr(statementHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength)) - + trc.Trace1("api/zapi_zos.go SQLSetStmtAttr() - EXIT") return SQLRETURN(r) } func SQLCreateDb(connectionHandle SQLHDBC, dbnamePtr *SQLWCHAR, dbnameLen SQLINTEGER, codeSetPtr *SQLWCHAR, codeSetLen SQLINTEGER, modePtr *SQLWCHAR, modeLen SQLINTEGER) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLCreateDb() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLCreateDb() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLCreateDbW"), uintptr(connectionHandle), uintptr(unsafe.Pointer(dbnamePtr)), uintptr(dbnameLen), uintptr(unsafe.Pointer(codeSetPtr)), uintptr(codeSetLen), uintptr(unsafe.Pointer(modePtr)), uintptr(modeLen)) - + trc.Trace1("api/zapi_zos.go SQLCreateDb() - EXIT") return SQLRETURN(r) } func SQLDropDb(connectionHandle SQLHDBC, dbnamePtr *SQLWCHAR, dbnameLen SQLINTEGER) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLDropDb() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLDropDb() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLDropDbW"), uintptr(connectionHandle), uintptr(unsafe.Pointer(dbnamePtr)), uintptr(dbnameLen)) - + trc.Trace1("api/zapi_zos.go SQLDropDb() - EXIT") return SQLRETURN(r) } func SQLExecDirect(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (SQLRETURN) { - trc.Trace1("api/zapi_zos.go SQLExecDirect() - ENTRY") - + trc.Trace1("api/zapi_zos.go SQLExecDirect() - ENTRY") + r := utils.CfuncEbcdic(getFunc(&dll, "SQLExecDirectW"), uintptr(statementHandle), uintptr(unsafe.Pointer(statementText)), uintptr(textLength)) - + trc.Trace1("api/zapi_zos.go SQLExecDirect() - EXIT") return SQLRETURN(r) -} \ No newline at end of file +} diff --git a/column.go b/column.go index eb2b1a6..932c9b5 100644 --- a/column.go +++ b/column.go @@ -21,13 +21,13 @@ type BufferLen api.SQLLEN func (l *BufferLen) IsNull() bool { trc.Trace1("column.go: IsNull()") - + return int16(*l) == api.SQL_NULL_DATA } func (l *BufferLen) GetData(h api.SQLHSTMT, idx int, ctype api.SQLSMALLINT, buf []byte) api.SQLRETURN { - trc.Trace1("column.go: GetData()") - + trc.Trace1("column.go: GetData()") + return api.SQLGetData(h, api.SQLUSMALLINT(idx+1), ctype, api.SQLPOINTER(unsafe.Pointer(&buf[0])), api.SQLLEN(len(buf)), (*api.SQLLEN)(l)) @@ -35,7 +35,7 @@ func (l *BufferLen) GetData(h api.SQLHSTMT, idx int, ctype api.SQLSMALLINT, buf func (l *BufferLen) Bind(h api.SQLHSTMT, idx int, ctype api.SQLSMALLINT, buf []byte) api.SQLRETURN { trc.Trace1("column.go: Bind()- ENTRY") - + if len(buf) <= 2147483647 { return api.SQLBindCol(h, api.SQLUSMALLINT(idx+1), ctype, buf, api.SQLLEN(len(buf)), @@ -57,14 +57,14 @@ type Column interface { func describeColumn(h api.SQLHSTMT, idx int, namebuf []uint16) (namelen int, sqltype api.SQLSMALLINT, size api.SQLULEN, ret api.SQLRETURN) { trc.Trace1("column.go: describeColumn() - ENTRY") - + var l, decimal, nullable api.SQLSMALLINT ret = api.SQLDescribeCol(h, api.SQLUSMALLINT(idx+1), (*api.SQLWCHAR)(unsafe.Pointer(&namebuf[0])), api.SQLSMALLINT(len(namebuf)), &l, &sqltype, &size, &decimal, &nullable) - - trc.Trace1("column.go: describeColumn() - EXIT") + + trc.Trace1("column.go: describeColumn() - EXIT") return int(l), sqltype, size, ret } @@ -72,7 +72,7 @@ func describeColumn(h api.SQLHSTMT, idx int, namebuf []uint16) (namelen int, sql func NewColumn(h api.SQLHSTMT, idx int) (Column, error) { trc.Trace1("column.go: NewColumn() - ENTRY") - + namebuf := make([]uint16, 150) namelen, sqltype, size, ret := describeColumn(h, idx, namebuf) if ret == api.SQL_SUCCESS_WITH_INFO && namelen > len(namebuf) { @@ -91,9 +91,9 @@ func NewColumn(h api.SQLHSTMT, idx int) (Column, error) { name: api.UTF16ToString(namebuf[:namelen]), SType: sqltype, } - + trc.Trace1("column.go: NewColumn() - EXIT") - + switch sqltype { case api.SQL_BIT, api.SQL_BOOLEAN: return NewBindableColumn(b, api.SQL_C_BIT, 1), nil @@ -147,7 +147,7 @@ func (c *BaseColumn) Name() string { func (c *BaseColumn) TypeScan() reflect.Type { trc.Trace1("column.go: TypeScan()") - + //TODO(Akhil):This will return the golang type of a variable switch c.CType { case api.SQL_C_BIT: @@ -175,7 +175,7 @@ func (c *BaseColumn) TypeScan() reflect.Type { func (c *BaseColumn) Value(buf []byte) (driver.Value, error) { trc.Trace1("column.go: Value()") - + var p unsafe.Pointer if len(buf) > 0 { p = unsafe.Pointer(&buf[0]) @@ -250,7 +250,7 @@ type BindableColumn struct { func NewBindableColumn(b *BaseColumn, ctype api.SQLSMALLINT, bufSize int) *BindableColumn { trc.Trace1("column.go: NewBindableColumn() - ENTRY") trc.Trace1(fmt.Sprintf("bufSize = %d", bufSize)) - + b.CType = ctype c := &BindableColumn{BaseColumn: b, Size: bufSize} if c.Size <= len(c.smallBuf) { @@ -265,7 +265,7 @@ func NewBindableColumn(b *BaseColumn, ctype api.SQLSMALLINT, bufSize int) *Binda func NewVariableWidthColumn(b *BaseColumn, ctype api.SQLSMALLINT, colWidth api.SQLULEN) Column { trc.Trace1("column.go: NewVariableWidthColumn() - ENTRY") - + if colWidth == 0 { b.CType = ctype return &NonBindableColumn{b} @@ -296,7 +296,7 @@ func NewVariableWidthColumn(b *BaseColumn, ctype api.SQLSMALLINT, colWidth api.S func (c *BindableColumn) Bind(h api.SQLHSTMT, idx int) (bool, error) { trc.Trace1("column.go: Bind() - ENTRY") trc.Trace1(fmt.Sprintf("idx = %d", idx)) - + ret := c.Len.Bind(h, idx, c.CType, c.Buffer) if IsError(ret) { return false, NewError("SQLBindCol", h) @@ -309,7 +309,7 @@ func (c *BindableColumn) Bind(h api.SQLHSTMT, idx int) (bool, error) { func (c *BindableColumn) Value(h api.SQLHSTMT, idx int) (driver.Value, error) { trc.Trace1("column.go: Value() - ENTRY") trc.Trace1(fmt.Sprintf("idx = %d", idx)) - + if !c.IsBound { ret := c.Len.GetData(h, idx, c.CType, c.Buffer) if IsError(ret) { diff --git a/conn.go b/conn.go index 7fd7486..bfae54f 100644 --- a/conn.go +++ b/conn.go @@ -21,7 +21,7 @@ type Conn struct { func (d *Driver) Open(dsn string) (driver.Conn, error) { trc.Trace1("conn.go: Open() - ENTRY") trc.Trace1(fmt.Sprintf("dsn = %s", dsn)) - + var out api.SQLHANDLE ret := api.SQLAllocHandle(api.SQL_HANDLE_DBC, api.SQLHANDLE(d.h), &out) if IsError(ret) { @@ -50,7 +50,7 @@ func (d *Driver) Open(dsn string) (driver.Conn, error) { func (c *Conn) Close() error { trc.Trace1("conn.go: Close() - ENTRY") - + ret := api.SQLDisconnect(c.h) if IsError(ret) { return NewError("SQLDisconnect", c.h) @@ -65,7 +65,7 @@ func (c *Conn) Close() error { func (c *Conn) Query(query string, args []driver.Value) (driver.Rows, error) { trc.Trace1("conn.go: Query() - ENTRY") trc.Trace1(fmt.Sprintf("query = %s", query)) - + if len(args) > 0 { // Not implemented for queries with parameters return nil, driver.ErrSkip diff --git a/database.go b/database.go index 6eceb34..d8de26b 100644 --- a/database.go +++ b/database.go @@ -12,9 +12,9 @@ import ( // CreateDb function will take the db name and user details as parameters // and create the database. func CreateDb(dbname string, connStr string, options ...string) (bool, error) { - trc.Trace1("database.go: CreateDb() - ENTRY") + trc.Trace1("database.go: CreateDb() - ENTRY") trc.Trace1(fmt.Sprintf("dbname=%s, connStr=%s", dbname, connStr)) - + if dbname == "" { trc.Trace1("Error: Database name cannot be empty") trc.Trace1("database.go: CreateDb() - EXIT") @@ -81,7 +81,7 @@ func createDatabase(dbname string, connStr string, codeset string, mode string) return false, NewError("SQLCreateDb", hdbc) } defer releaseHandle(hdbc) - + trc.Trace1("database.go: createDatabase() - EXIT") return true, nil } @@ -89,9 +89,9 @@ func createDatabase(dbname string, connStr string, codeset string, mode string) // DropDb function will take the db name and user details as parameters // and drop the database. func DropDb(dbname string, connStr string) (bool, error) { - trc.Trace1("database.go: DropDb() - ENTRY") + trc.Trace1("database.go: DropDb() - ENTRY") trc.Trace1(fmt.Sprintf("dbname=%s, connStr=%s", dbname, connStr)) - + if dbname == "" { return false, fmt.Errorf("Database name cannot be empty") } @@ -101,9 +101,9 @@ func DropDb(dbname string, connStr string) (bool, error) { } func dropDatabase(dbname string, connStr string) (bool, error) { - trc.Trace1("database.go: dropDatabase() - ENTRY") + trc.Trace1("database.go: dropDatabase() - ENTRY") trc.Trace1(fmt.Sprintf("dbname=%s, connStr=%s", dbname, connStr)) - + var out api.SQLHANDLE in := api.SQLHANDLE(api.SQL_NULL_HANDLE) bufDBN := api.StringToUTF16(dbname) diff --git a/driver.go b/driver.go index f68623d..7f90b8a 100644 --- a/driver.go +++ b/driver.go @@ -13,6 +13,7 @@ import ( "os" "github.com/ibmdb/go_ibm_db/api" trc "github.com/ibmdb/go_ibm_db/log2" + "strings" ) var drv Driver @@ -23,7 +24,7 @@ type Driver struct { } func initDriver() error { - trc.Trace1("driver.go:InitDriver() - ENTRY") + trc.Trace1("driver.go:InitDriver() - ENTRY") //Allocate environment handle var out api.SQLHANDLE @@ -42,27 +43,39 @@ func initDriver() error { defer releaseHandle(drv.h) return NewError("SQLSetEnvAttr ODBC v3", drv.h) } - trc.Trace1("driver.go:InitDriver() - EXIT") + + trc.Trace1("driver.go:InitDriver() - EXIT") return nil } func (d *Driver) Close() error { trc.Trace1("driver.go: Close() - ENTRY") - + // TODO(brainman): who will call (*Driver).Close (to dispose all opened handles)? h := d.h d.h = api.SQLHENV(api.SQL_NULL_HENV) + trc.Trace1("driver.go: Close() - EXIT") return releaseHandle(h) } func init() { - wordPtr := flag.String("trace", "", "log/trace file name") + var cmdStr string = "" + + for e:=0; e 2 { - flag.Parse() + + if strings.Contains(cmdStr, "trace") { + wordPtr := flag.String("trace", "", "log/trace file name") + + if len(os.Args) > 2 { + flag.Parse() + } + trc.GetPath(*wordPtr, len(os.Args)) } - trc.GetPath(*wordPtr, len(os.Args)) + trc.Trace1("driver.go:init() - ENTRY") @@ -79,6 +92,6 @@ func init() { } //go's to databse/sql/sql.go 43 line sql.Register("go_ibm_db", &drv) - - trc.Trace1("driver.go:init() - EXIT") + + trc.Trace1("driver.go:init() - EXIT") } diff --git a/error.go b/error.go index ebb8269..ab54c2a 100644 --- a/error.go +++ b/error.go @@ -16,7 +16,7 @@ import ( ) func IsError(ret api.SQLRETURN) bool { - trc.Trace1("error.go: IsError() - ENTRY") + trc.Trace1("error.go: IsError() - ENTRY") if ret == api.SQL_SUCCESS { trc.Trace1("api.SQL_SUCCESS") } else if ret == api.SQL_SUCCESS_WITH_INFO { @@ -42,7 +42,7 @@ type Error struct { } func (e *Error) Error() string { - trc.Trace1("error.go: Error() - ENTRY") + trc.Trace1("error.go: Error() - ENTRY") ss := make([]string, len(e.Diag)) for i, r := range e.Diag { ss[i] = r.String() @@ -55,7 +55,7 @@ func (e *Error) Error() string { func NewError(apiName string, handle interface{}) error { trc.Trace1("error.go: NewError() - ENTRY") trc.Trace1(fmt.Sprintf("apiName=%s",apiName)) - + var ret api.SQLRETURN h, ht := ToHandleAndType(handle) err := &Error{APIName: apiName} diff --git a/go.mod b/go.mod deleted file mode 100644 index 5e0eccf..0000000 --- a/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module go_ibm_db - -go 1.21.6 - -require ( - github.com/ibmdb/go_ibm_db v0.4.5 - github.com/ibmruntimes/go-recordio/v2 v2.0.0-20240327185926-a9cddb84114f -) diff --git a/go.sum b/go.sum deleted file mode 100644 index c7a1b74..0000000 --- a/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/ibmdb/go_ibm_db v0.4.5 h1:a0qKWbA5shCRo5HRRnAuENwhjg6AkgfPNr9xx0IZ160= -github.com/ibmdb/go_ibm_db v0.4.5/go.mod h1:nl5aUh1IzBVExcqYXaZLApaq8RUvTEph3VP49UTmEvg= -github.com/ibmruntimes/go-recordio/v2 v2.0.0-20240327185926-a9cddb84114f h1:0bpe1R9upvXKZkUUNRXERsz1NVL/pg9FMydmHi6Hv8w= -github.com/ibmruntimes/go-recordio/v2 v2.0.0-20240327185926-a9cddb84114f/go.mod h1:NSpUK0x9IyEoM1EjTp2/S8ErxZfRHoA2DfwiYobFSkc= diff --git a/handle.go b/handle.go index 687ef0e..1eb67d1 100644 --- a/handle.go +++ b/handle.go @@ -12,7 +12,7 @@ import ( func ToHandleAndType(handle interface{}) (h api.SQLHANDLE, ht api.SQLSMALLINT) { trc.Trace1("handle.go: ToHandleAndType() - ENTRY") - + switch v := handle.(type) { case api.SQLHENV: if v == api.SQLHENV(api.SQL_NULL_HANDLE) { diff --git a/log2/logger1.go b/log2/logger1.go index 51b8a57..75b66cf 100644 --- a/log2/logger1.go +++ b/log2/logger1.go @@ -11,24 +11,24 @@ import ( "fmt" ) -var globalvar string -var globalArgsLen int +var globalvar string = "" +var globalArgsLen int = 0 func GetPath(filename string, argsLen int) { //fmt.Println("filename = ", filename) //fmt.Println("Args Length = ", argsLen) - + if _, err := os.Stat(filename); err == nil { //fmt.Println("File exits\n") e := os.Remove(filename) if e != nil { fmt.Println("Problem in removing existing log file") - } + } } - + globalvar = filename globalArgsLen = argsLen - + } func Trace1(msg1 string) { diff --git a/odbcstmt.go b/odbcstmt.go index 117014e..9b976fb 100644 --- a/odbcstmt.go +++ b/odbcstmt.go @@ -31,7 +31,7 @@ type ODBCStmt struct { func (c *Conn) PrepareODBCStmt(query string) (*ODBCStmt, error) { trc.Trace1("odbcstmt.go: PrepareODBCStmt() - ENTRY") trc.Trace1(fmt.Sprintf("query=%s", query)) - + var out api.SQLHANDLE ret := api.SQLAllocHandle(api.SQL_HANDLE_STMT, api.SQLHANDLE(c.h), &out) if IsError(ret) { @@ -51,7 +51,7 @@ func (c *Conn) PrepareODBCStmt(query string) (*ODBCStmt, error) { defer releaseHandle(h) return nil, err } - + trc.Trace1("odbcstmt.go: PrepareODBCStmt() - EXIT") return &ODBCStmt{ h: h, @@ -62,7 +62,7 @@ func (c *Conn) PrepareODBCStmt(query string) (*ODBCStmt, error) { func (s *ODBCStmt) closeByStmt() error { trc.Trace1("odbcstmt.go: closeByStmt() - ENTRY") - + s.mu.Lock() defer s.mu.Unlock() if s.usedByStmt { @@ -77,7 +77,7 @@ func (s *ODBCStmt) closeByStmt() error { func (s *ODBCStmt) closeByRows() error { trc.Trace1("odbcstmt.go: closeByRows()") - + s.mu.Lock() defer s.mu.Unlock() if s.usedByRows { @@ -97,7 +97,7 @@ func (s *ODBCStmt) closeByRows() error { func (s *ODBCStmt) releaseHandle() error { trc.Trace1("odbcstmt.go: releaseHandle()") - + h := s.h s.h = api.SQLHSTMT(api.SQL_NULL_HSTMT) return releaseHandle(h) @@ -107,7 +107,7 @@ var testingIssue5 bool // used during tests func (s *ODBCStmt) Exec(args []driver.Value) error { trc.Trace1("odbcstmt.go: Exec() - ENTRY") - + ArrayCheck := 0 ArrayLength := 0 if len(args) != len(s.Parameters) { @@ -222,7 +222,7 @@ func (s *ODBCStmt) Exec(args []driver.Value) error { func (s *ODBCStmt) BindColumns() error { trc.Trace1("odbcstmt.go: BindColumns() - ENTRY") - + // count columns var n api.SQLSMALLINT ret := api.SQLNumResultCols(s.h, &n) diff --git a/param.go b/param.go index 31fb787..542f421 100644 --- a/param.go +++ b/param.go @@ -30,8 +30,8 @@ type Parameter struct { // StoreStrLen_or_IndPtr stores v into StrLen_or_IndPtr field of p // and returns address of that field. func (p *Parameter) StoreStrLen_or_IndPtr(v api.SQLLEN) *api.SQLLEN { - trc.Trace1("param.go: StoreStrLen_or_IndPtr()") - + trc.Trace1("param.go: StoreStrLen_or_IndPtr()") + p.StrLen_or_IndPtr = v return &p.StrLen_or_IndPtr @@ -41,7 +41,7 @@ func (p *Parameter) BindValue(h api.SQLHSTMT, idx int, v driver.Value) error { // TODO(brainman): Reuse memory for previously bound values. If memory // is reused, we, probably, do not need to call SQLBindParameter either. trc.Trace1("param.go: BindValue() - ENTRY") - + var ctype, sqltype, decimal api.SQLSMALLINT var size api.SQLULEN var buflen api.SQLLEN @@ -267,7 +267,7 @@ func (p *Parameter) BindValue(h api.SQLHSTMT, idx int, v driver.Value) error { if IsError(ret) { return NewError("SQLBindParameter", h) } - + trc.Trace1("param.go: BindValue() - EXIT") return nil } @@ -276,7 +276,7 @@ func (p *Parameter) BindValue(h api.SQLHSTMT, idx int, v driver.Value) error { func ExtractParameters(h api.SQLHSTMT) ([]Parameter, error) { // count parameters trc.Trace1("param.go: ExtractParameters() - ENTRY") - + var n, nullable api.SQLSMALLINT ret := api.SQLNumParams(h, &n) if IsError(ret) { @@ -307,8 +307,8 @@ func ExtractParameters(h api.SQLHSTMT) ([]Parameter, error) { //SqltoCtype function will convert the sql type to c type func SqltoCtype(sqltype api.SQLSMALLINT) api.SQLSMALLINT { - trc.Trace1("param.go: SqltoCtype()") - + trc.Trace1("param.go: SqltoCtype()") + switch sqltype { case api.SQL_BIT: return api.SQL_C_BIT diff --git a/pooling.go b/pooling.go index a976431..02f7b5f 100644 --- a/pooling.go +++ b/pooling.go @@ -5,9 +5,9 @@ import ( "fmt" "strconv" "strings" - "time" - "sync" - trc "github.com/ibmdb/go_ibm_db/log2" + "time" + "sync" + trc "github.com/ibmdb/go_ibm_db/log2" ) //DBP struct type contains the timeout, dbinstance and connection string @@ -32,9 +32,9 @@ const defaultConnMaxLifetime = 60 //Pconnect will return the pool instance func Pconnect(poolSize string) *Pool { - trc.Trace1("pooling.go: Pconnect() - ENTRY") + trc.Trace1("pooling.go: Pconnect() - ENTRY") trc.Trace1(fmt.Sprintf("poolSize=%s", poolSize)) - + var size int count := len(poolSize) if count > 0 { @@ -57,7 +57,7 @@ func Pconnect(poolSize string) *Pool { } b = p - trc.Trace1("pooling.go: Pconnect() - EXIT") + trc.Trace1("pooling.go: Pconnect() - EXIT") return p } @@ -67,9 +67,9 @@ var pSize int //Open will check for the connection in the pool //If not opens a new connection and stores in the pool func (p *Pool) Open(connStr string, options ...string) *DBP { - trc.Trace1("pooling.go: Open() - ENTRY") + trc.Trace1("pooling.go: Open() - ENTRY") trc.Trace1(fmt.Sprintf("connStr=%s",connStr)) - + var Time time.Duration count := len(options) if count > 0 { @@ -164,9 +164,9 @@ func (p *Pool) Open(connStr string, options ...string) *DBP { } func (p *Pool) Init(numConn int, connStr string) bool{ - trc.Trace1("pooling.go: Init() - ENTRY") + trc.Trace1("pooling.go: Init() - ENTRY") trc.Trace1(fmt.Sprintf("numConn=%d, connStr=%s", numConn, connStr)) - + var Time time.Duration if connMaxLifetime <= 0 { @@ -197,8 +197,8 @@ func (p *Pool) Init(numConn int, connStr string) bool{ //Close will make the connection available for the next release func (d *DBP) Close() { - trc.Trace1("pooling.go: Close() - ENTRY") - + trc.Trace1("pooling.go: Close() - ENTRY") + pSize = pSize - 1 var pos int i := -1 @@ -226,14 +226,14 @@ func (d *DBP) Close() { } else { d.DB.Close() } - b.mu.Unlock() - trc.Trace1("pooling.go: Close() - EXIT") + b.mu.Unlock() + trc.Trace1("pooling.go: Close() - EXIT") } //Timeout for closing the connection in pool func (d *DBP) Timeout() { - trc.Trace1("pooling.go: Timeout() - ENTRY") - + trc.Trace1("pooling.go: Timeout() - ENTRY") + var pos int i := -1 select { @@ -261,13 +261,13 @@ func (d *DBP) Timeout() { } b.mu.Unlock() } - trc.Trace1("pooling.go: Timeout() - EXIT") + trc.Trace1("pooling.go: Timeout() - EXIT") } //Release will close all the connections in the pool func (p *Pool) Release() { - trc.Trace1("pooling.go: Release() - ENTRY") - + trc.Trace1("pooling.go: Release() - ENTRY") + if p.availablePool != nil { for _, vala := range p.availablePool { for _, dbpr := range vala { @@ -289,9 +289,9 @@ func (p *Pool) Release() { //Set the connMaxLifetime func (p *Pool) SetConnMaxLifetime(num int) { - trc.Trace1("pooling.go: SetConnMaxLifetime()") + trc.Trace1("pooling.go: SetConnMaxLifetime()") trc.Trace1(fmt.Sprintf("connMaxLifetime=%d", num)) - + connMaxLifetime = num } diff --git a/rows.go b/rows.go index 417351c..af4cdd7 100644 --- a/rows.go +++ b/rows.go @@ -20,8 +20,8 @@ type Rows struct { } func (r *Rows) Columns() []string { - trc.Trace1("rows.go: Columns()") - + trc.Trace1("rows.go: Columns()") + names := make([]string, len(r.os.Cols)) for i := 0; i < len(names); i++ { names[i] = r.os.Cols[i].Name() @@ -33,7 +33,7 @@ func (r *Rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok b //TODO(Akhil):This functions retuns the precision and scale of column. trc.Trace1("rows.go: ColumnTypePrecisionScale() - ENTRY") trc.Trace1(fmt.Sprintf("index=%d", index)) - + ok = false; var namelen api.SQLSMALLINT namebuf := make([]byte, api.MAX_FIELD_SIZE) @@ -65,7 +65,7 @@ func (r *Rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok b ok = true; } - trc.Trace1(fmt.Sprintf("precision=%d, scale=%d", precision, scale)) + trc.Trace1(fmt.Sprintf("precision=%d, scale=%d", precision, scale)) trc.Trace1("rows.go: ColumnTypePrecisionScale() - EXIT") return precision, scale, ok } @@ -73,7 +73,7 @@ func (r *Rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok b func (r *Rows) ColumnTypeLength(index int) (length int64, ok bool) { //ToDo(Akhil):This functions retuns the length of column. trc.Trace1("rows.go: ColumnTypeLength() - ENTRY") - + ret := api.SQLColAttribute(r.os.h, api.SQLUSMALLINT(index+1), api.SQL_DESC_LENGTH, api.SQLPOINTER(unsafe.Pointer(nil)), 0, (*api.SQLSMALLINT)(nil), (api.SQLPOINTER)(unsafe.Pointer(&length))) if IsError(ret) { fmt.Println(ret) @@ -86,7 +86,7 @@ func (r *Rows) ColumnTypeLength(index int) (length int64, ok bool) { func (r *Rows) ColumnTypeNullable(index int) (nullable, ok bool) { //TODO(Akhil):This functions retuns whether the column is nullable or not trc.Trace1("rows.go: ColumnTypeNullable() - ENTRY") - + var null int64 ret := api.SQLColAttribute(r.os.h, api.SQLUSMALLINT(index+1), api.SQL_DESC_NULLABLE, api.SQLPOINTER(unsafe.Pointer(nil)), 0, (*api.SQLSMALLINT)(nil), (api.SQLPOINTER)(unsafe.Pointer(&null))) if IsError(ret) { @@ -105,7 +105,7 @@ func (r *Rows) ColumnTypeScanType(index int) reflect.Type { //the data to the golang variable. trc.Trace1("rows.go: ColumnTypeScanType()") trc.Trace1(fmt.Sprintf("index=%d", index)) - + a := r.os.Cols[index].TypeScan() return (a) } @@ -114,7 +114,7 @@ func (r *Rows) ColumnTypeDatabaseTypeName(index int) string { //TODO(AKHIL):This functions retuns the dbtype(VARCHAR,DECIMAL etc..) of column. //namebuf can be of uint8 or byte trc.Trace1("rows.go: ColumnTypeDatabaseTypeName() - ENTRY") - + var namelen api.SQLSMALLINT namebuf := make([]byte, api.MAX_FIELD_SIZE) ret := api.SQLColAttribute(r.os.h, api.SQLUSMALLINT(index+1), api.SQL_DESC_TYPE_NAME, api.SQLPOINTER(unsafe.Pointer(&namebuf[0])), (api.MAX_FIELD_SIZE), (*api.SQLSMALLINT)(&namelen), (api.SQLPOINTER)(unsafe.Pointer(nil))) @@ -129,8 +129,8 @@ func (r *Rows) ColumnTypeDatabaseTypeName(index int) string { } func (r *Rows) Next(dest []driver.Value) error { - trc.Trace1("rows.go: Next() - ENTRY") - + trc.Trace1("rows.go: Next() - ENTRY") + ret := api.SQLFetch(r.os.h) if ret == api.SQL_NO_DATA { return io.EOF @@ -150,14 +150,14 @@ func (r *Rows) Next(dest []driver.Value) error { } func (r *Rows) HasNextResultSet() bool { - trc.Trace1("rows.go: ()") - + trc.Trace1("rows.go: HasVextResultSet()") + return true } func (r *Rows) NextResultSet() error { - trc.Trace1("rows.go: () - ENTRY") - + trc.Trace1("rows.go: NextResultSet() - ENTRY") + ret := api.SQLMoreResults(r.os.h) if ret == api.SQL_NO_DATA { return io.EOF @@ -170,12 +170,12 @@ func (r *Rows) NextResultSet() error { if err != nil { return err } - trc.Trace1("rows.go: () - EXIT") + trc.Trace1("rows.go: NextResultSet() - EXIT") return nil } func (r *Rows) Close() error { - trc.Trace1("rows.go: Close()") - + trc.Trace1("rows.go: Close()") + return r.os.closeByRows() } diff --git a/sqlOut.go b/sqlOut.go index 64bfe3d..9fbed48 100644 --- a/sqlOut.go +++ b/sqlOut.go @@ -31,9 +31,9 @@ type Out struct { } func newOut(hstmt api.SQLHSTMT, sqlOut *sql.Out, idx int) (*Out, error) { - trc.Trace1("sqlOut.go: newOut() - ENTRY") + trc.Trace1("sqlOut.go: newOut() - ENTRY") trc.Trace1(fmt.Sprintf("idx=%d", idx)) - + var ctype, sqltype, decimalDigits, nullable, inputOutputType api.SQLSMALLINT var parameterSize api.SQLULEN var buflen api.SQLLEN @@ -142,7 +142,7 @@ func newOut(hstmt api.SQLHSTMT, sqlOut *sql.Out, idx int) (*Out, error) { plen = &buflen } - trc.Trace1("sqlOut.go: newOut() - EXIT") + trc.Trace1("sqlOut.go: newOut() - EXIT") return &Out{ sqlOut: sqlOut, idx: idx + 1, @@ -160,8 +160,8 @@ func newOut(hstmt api.SQLHSTMT, sqlOut *sql.Out, idx int) (*Out, error) { // Value function converts the database value to driver.value func (o *Out) Value() (driver.Value, error) { - trc.Trace1("sqlOut.go: Value() - ENTRY") - + trc.Trace1("sqlOut.go: Value() - ENTRY") + var p unsafe.Pointer buf := o.data if len(buf) > 0 { @@ -220,8 +220,8 @@ func (o *Out) Value() (driver.Value, error) { // ConvertAssign function copies the database data to Dest field in stored procedure. func (o *Out) ConvertAssign() error { - trc.Trace1("sqlOut.go: ConvertAssign() - ENTRY") - + trc.Trace1("sqlOut.go: ConvertAssign() - ENTRY") + if o.sqlOut == nil { return fmt.Errorf("sql.Out is nil at OUT param index %d", o.idx) } @@ -245,8 +245,8 @@ func (o *Out) ConvertAssign() error { // ConvertAssign function copies the database data to Dest field in stored procedure. func ConvertAssign(dest, src interface{}) error { - trc.Trace1("sqlOut.go: ConvertAssign() - ENTRY") - + trc.Trace1("sqlOut.go: ConvertAssign() - ENTRY") + switch s := src.(type) { case string: switch d := dest.(type) { @@ -440,12 +440,12 @@ func ConvertAssign(dest, src interface{}) error { } } - trc.Trace1("sqlOut.go: ConvertAssign() - EXIT") + trc.Trace1("sqlOut.go: ConvertAssign() - EXIT") return fmt.Errorf("unsupported Scan, storing driver.Value type %T into type %T", src, dest) } func strconvErr(err error) error { - trc.Trace1("sqlOut.go: strconvErr()") + trc.Trace1("sqlOut.go: strconvErr()") trc.Trace1(fmt.Sprintf("Error:%s", err)) if ne, ok := err.(*strconv.NumError); ok { @@ -455,8 +455,8 @@ func strconvErr(err error) error { } func copyBytes(b []byte) []byte { - trc.Trace1("sqlOut.go: copyBytes()") - + trc.Trace1("sqlOut.go: copyBytes()") + if b == nil { return nil } @@ -466,8 +466,8 @@ func copyBytes(b []byte) []byte { } func asString(src interface{}) string { - trc.Trace1("sqlOut.go: asString()") - + trc.Trace1("sqlOut.go: asString()") + switch v := src.(type) { case string: return v @@ -491,8 +491,8 @@ func asString(src interface{}) string { } func asBytes(buf []byte, rv reflect.Value) (b []byte, ok bool) { - trc.Trace1("sqlOut.go: asBytes()") - + trc.Trace1("sqlOut.go: asBytes()") + switch rv.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return strconv.AppendInt(buf, rv.Int(), 10), true @@ -513,8 +513,8 @@ func asBytes(buf []byte, rv reflect.Value) (b []byte, ok bool) { // This function is mirrored in the database/sql/driver package. func callValuerValue(vr driver.Valuer) (v driver.Value, err error) { - trc.Trace1("sqlOut.go: callValuerValue()") - + trc.Trace1("sqlOut.go: callValuerValue()") + if rv := reflect.ValueOf(vr); rv.Kind() == reflect.Ptr && rv.IsNil() && rv.Type().Elem().Implements(reflect.TypeOf((*driver.Valuer)(nil)).Elem()) { diff --git a/stats.go b/stats.go index 947f982..323642f 100644 --- a/stats.go +++ b/stats.go @@ -20,9 +20,9 @@ type Stats struct { } func (s *Stats) updateHandleCount(handleType api.SQLSMALLINT, change int) { - trc.Trace1("stats.go: updateHandleCount() - ENTRY") + trc.Trace1("stats.go: updateHandleCount() - ENTRY") trc.Trace1(fmt.Sprintf("change=%d", change)) - + s.mu.Lock() defer s.mu.Unlock() switch handleType { @@ -36,6 +36,6 @@ func (s *Stats) updateHandleCount(handleType api.SQLSMALLINT, change int) { trc.Trace1(fmt.Sprintf("unexpected handle type %d", handleType)) panic(fmt.Errorf("unexpected handle type %d", handleType)) } - + trc.Trace1("stats.go: updateHandleCount() - EXIT") } diff --git a/testdata/main.go b/testdata/main.go index 46ee786..58157f9 100755 --- a/testdata/main.go +++ b/testdata/main.go @@ -108,8 +108,8 @@ func UpdateConnectionVariables() { //Createconnection will return the db instance func Createconnection() (db *sql.DB) { UpdateConnectionVariables() - //connStr = "PROTOCOL=tcpip;HOSTNAME=" + host + ";PORT=" + port + ";DATABASE=" + database + ";UID=" + uid + ";PWD=" + pwd - connStr = "PROTOCOL=tcpip;HOSTNAME=" + host + ";PORT=" + port + ";DATABASE=" + database + ";UID=" + uid + ";PWD=" + pwd +";Security=ssl" + connStr = "PROTOCOL=tcpip;HOSTNAME=" + host + ";PORT=" + port + ";DATABASE=" + database + ";UID=" + uid + ";PWD=" + pwd + //connStr = "PROTOCOL=tcpip;HOSTNAME=" + host + ";PORT=" + port + ";DATABASE=" + database + ";UID=" + uid + ";PWD=" + pwd +";Security=ssl" db, _ = sql.Open("go_ibm_db", connStr) return db } @@ -119,11 +119,17 @@ func Createtable() error { db := Createconnection() defer db.Close() db.Exec("DROP table rocket") - _, err := db.Exec("create table rocket(a int)") - _, err = db.Exec("create table rocket1(a int)") - if err != nil { - return err + db.Exec("DROP table rocket1") + _, err1 := db.Exec("create table rocket(a int)") + if err1 != nil { + return err1 } + + _, err2 := db.Exec("create table rocket1(a int)") + if err2 != nil { + return err2 + } + return nil }