From 30028d8052301b41241260bbfe5d752030fc5051 Mon Sep 17 00:00:00 2001 From: VIKAS MATHUR <97077039+vmathur12@users.noreply.github.com> Date: Fri, 28 Jun 2024 12:32:53 +0530 Subject: [PATCH] Logs at API Level (#241) * Update go.yml * Added trace logs at API level --------- Co-authored-by: Vikas Mathur --- .github/workflows/go.yml | 64 ++++++ api/api.go | 20 +- api/api_unix.go | 17 ++ api/api_windows.go | 14 ++ api/api_zos.go | 14 +- api/zapi_unix.go | 157 ++++++++++++++- api/zapi_windows.go | 182 +++++++++++++++++- api/zapi_zos.go | 162 +++++++++++++--- column.go | 39 +++- conn.go | 16 +- database.go | 18 ++ driver.go | 23 ++- error.go | 17 ++ handle.go | 9 +- log2/logger1.go | 49 +++++ odbcstmt.go | 19 ++ param.go | 13 ++ pooling.go | 32 ++- rows.go | 34 ++++ sqlOut.go | 25 +++ stats.go | 7 + stmt.go | 33 +++- .../connectioninvaliddatabasename_test.go | 13 -- testdata/connectioninvalidportno_test.go | 11 -- testdata/connectioninvaliduserid_test.go | 11 -- testdata/connectioninvaliduserpwd_test.go | 11 -- testdata/main.go | 3 +- testdata/queryContext_test.go | 22 --- testdata/query_test.go | 9 - testdata/scan_test.go | 9 - testdata/spArray_test.go | 73 ------- testdata/spInOut_test.go | 37 ---- testdata/sp_test.go | 31 --- 33 files changed, 921 insertions(+), 273 deletions(-) create mode 100644 .github/workflows/go.yml create mode 100644 log2/logger1.go delete mode 100755 testdata/connectioninvaliddatabasename_test.go delete mode 100755 testdata/connectioninvalidportno_test.go delete mode 100755 testdata/connectioninvaliduserid_test.go delete mode 100755 testdata/connectioninvaliduserpwd_test.go delete mode 100644 testdata/queryContext_test.go delete mode 100644 testdata/query_test.go delete mode 100644 testdata/scan_test.go delete mode 100755 testdata/spArray_test.go delete mode 100644 testdata/spInOut_test.go delete mode 100644 testdata/sp_test.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..4dbbb93 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,64 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.19.3' + + - name: Install clidriver + run: | + pwd + go run installer/setup.go + pwd + ibm_db_home=/home/runner/work/clidriver + cgo_cflags=-I$ibm_db_home/include + cgo_ldflags=-L$ibm_db_home/lib + ld_library_path=$ibm_db_home/lib + echo "IBM_DB_HOME=$ibm_db_home" >> "$GITHUB_ENV" + echo "CGO_CFLAGS=$cgo_cflags" >> "$GITHUB_ENV" + echo "CGO_LDFLAGS=$cgo_ldflags" >> "$GITHUB_ENV" + echo "LD_LIBRARY_PATH=$ld_library_path" >> "$GITHUB_ENV" + + db2_user= + db2_passwd= + db2_database= + db2_hostname= + db2_port= + echo "DB2_USER=$db2_user" >> "$GITHUB_ENV" + echo "DB2_PASSWD=$db2_passwd" >> "$GITHUB_ENV" + echo "DB2_DATABASE=$db2_database" >> "$GITHUB_ENV" + echo "DB2_HOSTNAME=$db2_hostname" >> "$GITHUB_ENV" + echo "DB2_PORT=$db2_port" >> "$GITHUB_ENV" + + + - name: Test + run: | + pwd + cd testdata + go mod init t2 + go mod tidy + echo "============TEST CASES ======" + #echo "CGO_LDFLAGS = " $CGO_LDFLAGS + #echo "DB2_USER = " $DB2_USER + go test -v + #go test createdroptable_test.go main.go + #go test alldatatypes_test.go main.go + #go test chinesechar_test.go main.go + #go test hugequery_test.go main.go + #go test decimal_test.go main.go diff --git a/api/api.go b/api/api.go index 08841e3..0b7e3fd 100644 --- a/api/api.go +++ b/api/api.go @@ -8,6 +8,8 @@ import ( "unicode/utf16" "unsafe" "runtime" + trc "github.com/ibmdb/go_ibm_db/log2" + "fmt" ) type ( @@ -57,44 +59,58 @@ 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") for i, v := range s { if v == 0 { s = s[0:i] break } } + trc.Trace1("api/api.go UTF16ToString() - EXIT") return string(utf16.Decode(s)) } // StringToUTF16 returns the UTF-16 encoding of the UTF-8 string s, // with a terminating NUL added. -func StringToUTF16(s string) []uint16 { +//func StringToUTF16(s string) []uint16 { return utf16.Encode([]rune(s + "\u0000")) } +func StringToUTF16(s string) []uint16 { + 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 { - return utf16.Encode([]rune(s + "\u0000")) } } + // StringToUTF16Ptr returns pointer to the UTF-16 encoding of // the UTF-8 string s, with a terminating NUL added. 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") + 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 40259e8..bd73c15 100644 --- a/api/api_unix.go +++ b/api/api_unix.go @@ -8,6 +8,11 @@ package api +import ( + trc "github.com/ibmdb/go_ibm_db/log2" + "fmt" +) + // #cgo aix LDFLAGS: -ldb2 // #cgo darwin LDFLAGS: -ldb2 // #cgo linux LDFLAGS: -ldb2 @@ -172,11 +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(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) 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(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) return SQLRETURN(r) } diff --git a/api/api_windows.go b/api/api_windows.go index cb2ba75..711a55c 100644 --- a/api/api_windows.go +++ b/api/api_windows.go @@ -6,6 +6,8 @@ package api import ( "syscall" + trc "github.com/ibmdb/go_ibm_db/log2" + "fmt" ) const ( @@ -161,13 +163,25 @@ type ( ) func SQLSetEnvUIntPtrAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) { + 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("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(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 d87ca9d..f96be74 100644 --- a/api/api_zos.go +++ b/api/api_zos.go @@ -12,6 +12,8 @@ import ( "unsafe" "github.com/ibmruntimes/go-recordio/v2/utils" + trc "github.com/ibmdb/go_ibm_db/log2" + "fmt" ) func getFunc(dll *utils.Dll, str string) uintptr { @@ -164,11 +166,21 @@ type ( ) func SQLSetEnvUIntPtrAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) { + 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") + 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 0595c9b..0b75de3 100644 --- a/api/zapi_unix.go +++ b/api/zapi_unix.go @@ -11,7 +11,9 @@ package api import ( + "fmt" "unsafe" + trc "github.com/ibmdb/go_ibm_db/log2" ) // #cgo aix LDFLAGS: -ldb2 @@ -21,131 +23,280 @@ import ( import "C" func SQLAllocHandle(handleType SQLSMALLINT, inputHandle SQLHANDLE, outputHandle *SQLHANDLE) (ret SQLRETURN) { + 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(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(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") + 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)) + 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(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") + 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)) + 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)) + r := C.SQLEndTran(C.SQLSMALLINT(handleType), C.SQLHANDLE(handle), C.SQLSMALLINT(completionType)) + + trc.Trace1(fmt.Sprintf("r = %d", r)) + trc.Trace1("api/zapi_unix.go SQLEndTran() - EXIT") return SQLRETURN(r) } func SQLExecute(statementHandle SQLHSTMT) (ret SQLRETURN) { + 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") + 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(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)) + 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)) + 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)) + r := C.SQLNumParams(C.SQLHSTMT(statementHandle), (*C.SQLSMALLINT)(parameterCountPtr)) + + 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(fmt.Sprintf("columnCountPtr=%x", columnCountPtr)) + r := C.SQLNumResultCols(C.SQLHSTMT(statementHandle), (*C.SQLSMALLINT)(columnCountPtr)) - return SQLRETURN(r) + + trc.Trace1(fmt.Sprintf("r = %d", r)) + trc.Trace1("api/zapi_unix.go SQLNumResultCols() - EXIT") + 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)) + 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") + 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)) + 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) { - r := C.SQLSetConnectAttrW(C.SQLHDBC(connectionHandle), C.SQLINTEGER(attribute), C.SQLPOINTER(valuePtr), C.SQLINTEGER(stringLength)) + 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)) + + 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) { - 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("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)) + + 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") + 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(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(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(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(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 dae4bd4..3b29d91 100644 --- a/api/zapi_windows.go +++ b/api/zapi_windows.go @@ -7,6 +7,8 @@ import ( "os" "syscall" "unsafe" + trc "github.com/ibmdb/go_ibm_db/log2" + "fmt" ) var ( @@ -41,165 +43,343 @@ var ( ) func GetDllName() string { + 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" } else { + trc.Trace1("db2cli64.dll") return "db2cli64.dll" } } func SQLAllocHandle(handleType SQLSMALLINT, inputHandle SQLHANDLE, outputHandle *SQLHANDLE) (ret SQLRETURN) { + 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("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(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(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") + 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(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(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") + 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(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(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") + 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") + 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 SQLFreeHandle(handleType SQLSMALLINT, handle SQLHANDLE) (ret SQLRETURN) { + 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(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(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(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(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(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(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(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(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(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") + 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 } func SQLSetStmtAttr(statementHandle SQLHSTMT, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (ret SQLRETURN) { - r0, _, _ := syscall.Syscall6(procSQLSetStmtAttrW.Addr(), 4, uintptr(statementHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength), 0, 0) + 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 SQLSetPos(statementHandle SQLHSTMT, rowNumber SQLSETPOSIROW, operation SQLUSMALLINT, lockType SQLUSMALLINT) (ret SQLRETURN) { + 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(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(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(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(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 9b9eaaf..f76e77c 100644 --- a/api/zapi_zos.go +++ b/api/zapi_zos.go @@ -12,6 +12,7 @@ import ( "unsafe" "github.com/ibmruntimes/go-recordio/v2/utils" + trc "github.com/ibmdb/go_ibm_db/log2" ) var dll utils.Dll @@ -25,132 +26,239 @@ func init() { } } -func SQLAllocHandle(handleType SQLSMALLINT, inputHandle SQLHANDLE, outputHandle *SQLHANDLE) SQLRETURN { +func SQLAllocHandle(handleType SQLSMALLINT, inputHandle SQLHANDLE, outputHandle *SQLHANDLE) (SQLRETURN) { + 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 { +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(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 { +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") + 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 { +func SQLCloseCursor(statementHandle SQLHSTMT) (SQLRETURN) { + 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") + 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 { +func SQLDescribeParam(statementHandle SQLHSTMT, parameterNumber SQLUSMALLINT, dataTypePtr *SQLSMALLINT, parameterSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (SQLRETURN) { + 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 { +func SQLDisconnect(connectionHandle SQLHDBC) (SQLRETURN) { + 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 { - 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)) +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") + + 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 { +func SQLEndTran(handleType SQLSMALLINT, handle SQLHANDLE, completionType SQLSMALLINT) (SQLRETURN) { + 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 { +func SQLExecute(statementHandle SQLHSTMT) (SQLRETURN) { + 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 { +func SQLFetch(statementHandle SQLHSTMT) (SQLRETURN) { + 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 { +func SQLFreeHandle(handleType SQLSMALLINT, handle SQLHANDLE) (SQLRETURN) { + 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 { +func SQLGetData(statementHandle SQLHSTMT, colOrParamNum SQLUSMALLINT, targetType SQLSMALLINT, targetValuePtr SQLPOINTER, bufferLength SQLLEN, vallen *SQLLEN) (SQLRETURN) { + 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 { +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") + 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 { +func SQLNumParams(statementHandle SQLHSTMT, parameterCountPtr *SQLSMALLINT) (SQLRETURN) { + 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 { +func SQLNumResultCols(statementHandle SQLHSTMT, columnCountPtr *SQLSMALLINT) (SQLRETURN) { + 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 { +func SQLPrepare(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (SQLRETURN) { + 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 { +func SQLRowCount(statementHandle SQLHSTMT, rowCountPtr *SQLLEN) (SQLRETURN) { + 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 { +func SQLSetEnvAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (SQLRETURN) { + 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 { +func SQLSetConnectAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (SQLRETURN) { + 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 { +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") + 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 { +func SQLMoreResults(statementHandle SQLHSTMT) (SQLRETURN) { + 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 { +func SQLSetStmtAttr(statementHandle SQLHSTMT, attribute SQLINTEGER, valuePtr SQLPOINTER, stringLength SQLINTEGER) (SQLRETURN) { + 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 { +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") + 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 { +func SQLDropDb(connectionHandle SQLHDBC, dbnamePtr *SQLWCHAR, dbnameLen SQLINTEGER) (SQLRETURN) { + 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 { +func SQLExecDirect(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (SQLRETURN) { + 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 5533f57..eb2b1a6 100644 --- a/column.go +++ b/column.go @@ -14,26 +14,34 @@ import ( "bytes" "github.com/ibmdb/go_ibm_db/api" + trc "github.com/ibmdb/go_ibm_db/log2" ) 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()") + return api.SQLGetData(h, api.SQLUSMALLINT(idx+1), ctype, api.SQLPOINTER(unsafe.Pointer(&buf[0])), api.SQLLEN(len(buf)), (*api.SQLLEN)(l)) } 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)), (*api.SQLLEN)(l)) } + trc.Trace1("column.go: Bind()- EXIT") return api.SQLBindCol(h, api.SQLUSMALLINT(idx+1), ctype, buf, api.SQLLEN(len(buf)-1), (*api.SQLLEN)(l)) @@ -48,17 +56,23 @@ 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") return int(l), sqltype, size, ret } // TODO(brainman): did not check for MS SQL timestamp 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) { @@ -77,6 +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 @@ -129,6 +146,8 @@ 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: @@ -155,6 +174,8 @@ 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]) @@ -227,6 +248,9 @@ 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) { @@ -235,10 +259,13 @@ func NewBindableColumn(b *BaseColumn, ctype api.SQLSMALLINT, bufSize int) *Binda } else { c.Buffer = make([]byte, c.Size) } + trc.Trace1("column.go: NewBindableColumn() - EXIT") return c } 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} @@ -262,19 +289,27 @@ func NewVariableWidthColumn(b *BaseColumn, ctype api.SQLSMALLINT, colWidth api.S } c := NewBindableColumn(b, ctype, l) c.IsVariableWidth = true + trc.Trace1("column.go: NewVariableWidthColumn() - EXIT") return c } 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) } c.IsBound = true + trc.Trace1("column.go: Bind() - EXIT") return true, nil } 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) { @@ -293,7 +328,7 @@ func (c *BindableColumn) Value(h api.SQLHSTMT, idx int) (driver.Value, error) { if len(c.Buffer) < bufferLen { bufferLen = len(c.Buffer) } - + trc.Trace1("column.go: Value() - EXIT") return c.BaseColumn.Value(c.Buffer[:bufferLen]) } @@ -312,6 +347,7 @@ func (c *NonBindableColumn) Value(h api.SQLHSTMT, idx int) (driver.Value, error) var l BufferLen var total []byte b := make([]byte, 1024) + trc.Trace1("column.go: Value() - ENTRY") loop: for { ret := l.GetData(h, idx, c.CType, b) @@ -350,5 +386,6 @@ loop: return nil, NewError("SQLGetData", h) } } + trc.Trace1("column.go: Value() - EXIT") return c.BaseColumn.Value(total) } diff --git a/conn.go b/conn.go index 5a65bf1..7fd7486 100644 --- a/conn.go +++ b/conn.go @@ -8,8 +8,9 @@ import ( "database/sql/driver" "runtime" "unsafe" - + "fmt" "github.com/ibmdb/go_ibm_db/api" + trc "github.com/ibmdb/go_ibm_db/log2" ) type Conn struct { @@ -18,6 +19,9 @@ 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) { @@ -40,21 +44,28 @@ func (d *Driver) Open(dsn string) (driver.Conn, error) { defer releaseHandle(h) return nil, NewError("SQLDriverConnect", h) } + trc.Trace1("conn.go: Open() - EXIT") return &Conn{h: h}, nil } func (c *Conn) Close() error { + trc.Trace1("conn.go: Close() - ENTRY") + ret := api.SQLDisconnect(c.h) if IsError(ret) { return NewError("SQLDisconnect", c.h) } h := c.h c.h = api.SQLHDBC(api.SQL_NULL_HDBC) + trc.Trace1("conn.go: Close() - EXIT") return releaseHandle(h) } -// Query method executes the statement with out prepare if no args provided, and a driver.ErrSkip otherwise (handled by sql.go to execute usual preparedStmt) +//Query method executes the statement with out prepare if no args provided, and a driver.ErrSkip otherwise (handled by sql.go to execute usual preparedStmt) 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 @@ -87,5 +98,6 @@ func (c *Conn) Query(query string, args []driver.Value) (driver.Rows, error) { if err != nil { return nil, err } + trc.Trace1("conn.go: Query() - EXIT") return &Rows{os: os}, nil } diff --git a/database.go b/database.go index dbf3957..6eceb34 100644 --- a/database.go +++ b/database.go @@ -6,12 +6,18 @@ import ( "unsafe" "github.com/ibmdb/go_ibm_db/api" + trc "github.com/ibmdb/go_ibm_db/log2" ) // 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(fmt.Sprintf("dbname=%s, connStr=%s", dbname, connStr)) + if dbname == "" { + trc.Trace1("Error: Database name cannot be empty") + trc.Trace1("database.go: CreateDb() - EXIT") return false, fmt.Errorf("Database name cannot be empty") } var codeset, mode string @@ -29,10 +35,13 @@ func CreateDb(dbname string, connStr string, options ...string) (bool, error) { } } connStr = connStr + ";" + "ATTACH=true" + trc.Trace1("database.go: CreateDb() - EXIT") return createDatabase(dbname, connStr, codeset, mode) } func createDatabase(dbname string, connStr string, codeset string, mode string) (bool, error) { + trc.Trace1("database.go: createDatabase() - ENTRY") + trc.Trace1(fmt.Sprintf("dbname=%s, connStr=%s, codeset=%s, mode=%s", dbname, connStr, codeset, mode)) var out api.SQLHANDLE in := api.SQLHANDLE(api.SQL_NULL_HANDLE) bufDBN := api.StringToUTF16(dbname) @@ -72,20 +81,29 @@ 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 } // 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(fmt.Sprintf("dbname=%s, connStr=%s", dbname, connStr)) + if dbname == "" { return false, fmt.Errorf("Database name cannot be empty") } connStr = connStr + ";" + "ATTACH=true" + trc.Trace1("database.go: DropDb() - EXIT") return dropDatabase(dbname, connStr) } func dropDatabase(dbname string, connStr string) (bool, error) { + 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 ddb7465..f68623d 100644 --- a/driver.go +++ b/driver.go @@ -9,8 +9,10 @@ package go_ibm_db import ( "database/sql" "fmt" - + "flag" + "os" "github.com/ibmdb/go_ibm_db/api" + trc "github.com/ibmdb/go_ibm_db/log2" ) var drv Driver @@ -21,6 +23,7 @@ type Driver struct { } func initDriver() error { + trc.Trace1("driver.go:InitDriver() - ENTRY") //Allocate environment handle var out api.SQLHANDLE @@ -39,22 +42,33 @@ func initDriver() error { defer releaseHandle(drv.h) return NewError("SQLSetEnvAttr ODBC v3", drv.h) } - + 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") + + if len(os.Args) > 2 { + flag.Parse() + } + trc.GetPath(*wordPtr, len(os.Args)) + + trc.Trace1("driver.go:init() - ENTRY") // Recover from panic to avoid stop an application when can't get the db2 cli defer func() { - if err := recover(); err != nil { + if err := recover(); err != nil { fmt.Println(fmt.Sprintf("%s\nThe go_ibm_db driver cannot be registered", err)) } }() @@ -65,5 +79,6 @@ func init() { } //go's to databse/sql/sql.go 43 line sql.Register("go_ibm_db", &drv) - + + trc.Trace1("driver.go:init() - EXIT") } diff --git a/error.go b/error.go index 39d9aea..ebb8269 100644 --- a/error.go +++ b/error.go @@ -12,9 +12,17 @@ import ( "unsafe" "github.com/ibmdb/go_ibm_db/api" + trc "github.com/ibmdb/go_ibm_db/log2" ) func IsError(ret api.SQLRETURN) bool { + trc.Trace1("error.go: IsError() - ENTRY") + if ret == api.SQL_SUCCESS { + trc.Trace1("api.SQL_SUCCESS") + } else if ret == api.SQL_SUCCESS_WITH_INFO { + trc.Trace1("api.SQL_SUCCESS_WITH_INFO") + } + trc.Trace1("error.go: IsError() - EXIT") return !(ret == api.SQL_SUCCESS || ret == api.SQL_SUCCESS_WITH_INFO) } @@ -34,14 +42,20 @@ type Error struct { } func (e *Error) Error() string { + trc.Trace1("error.go: Error() - ENTRY") ss := make([]string, len(e.Diag)) for i, r := range e.Diag { ss[i] = r.String() } + trc.Trace1(fmt.Sprintf("%s : %s", e.APIName, ss)) + trc.Trace1("error.go: Error() - EXIT") return e.APIName + ": " + strings.Join(ss, "\n") } 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} @@ -64,6 +78,7 @@ func NewError(apiName string, handle interface{}) error { break } if IsError(ret) { + trc.Trace1(fmt.Sprintf("SQLGetDiagRec failed: ret=%d", ret)) panic(fmt.Errorf("SQLGetDiagRec failed: ret=%d", ret)) } r := DiagRecord{ @@ -78,5 +93,7 @@ func NewError(apiName string, handle interface{}) error { } err.Diag = append(err.Diag, r) } + trc.Trace1(fmt.Sprintf("Error: %s", err)) + trc.Trace1("error.go: NewError() - EXIT") return err } diff --git a/handle.go b/handle.go index 68ff0d4..687ef0e 100644 --- a/handle.go +++ b/handle.go @@ -6,11 +6,13 @@ package go_ibm_db import ( "fmt" - "github.com/ibmdb/go_ibm_db/api" + trc "github.com/ibmdb/go_ibm_db/log2" ) 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) { @@ -28,10 +30,13 @@ func ToHandleAndType(handle interface{}) (h api.SQLHANDLE, ht api.SQLSMALLINT) { default: panic(fmt.Errorf("unexpected handle type %T", v)) } + trc.Trace1("handle.go: ToHandleAndType() - EXIT") return h, ht } func releaseHandle(handle interface{}) error { + trc.Trace1("handle.go: releaseHandle() - ENTRY") + h, ht := ToHandleAndType(handle) ret := api.SQLFreeHandle(ht, h) if ret == api.SQL_INVALID_HANDLE { @@ -41,5 +46,7 @@ func releaseHandle(handle interface{}) error { return NewError("SQLFreeHandle", handle) } drv.Stats.updateHandleCount(ht, -1) + + trc.Trace1("handle.go: releaseHandle() - EXIT") return nil } diff --git a/log2/logger1.go b/log2/logger1.go new file mode 100644 index 0000000..51b8a57 --- /dev/null +++ b/log2/logger1.go @@ -0,0 +1,49 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package odbc implements database/sql driver to access data via odbc interface. +package log2 + +import ( + "log" + "os" + "fmt" +) + +var globalvar string +var globalArgsLen int + +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) { + if globalvar != "" { + //file, errlog := os.OpenFile("C:\\temp\\testlogs2.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) + file, errlog := os.OpenFile(globalvar, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) + if errlog != nil { + log.Fatal(errlog) + } + log.SetOutput(file) + log.Println(msg1) + } else if globalArgsLen > 1 { + log.SetOutput(os.Stdout) + log.Println(msg1) + } + +} + diff --git a/odbcstmt.go b/odbcstmt.go index 95c8a8f..117014e 100644 --- a/odbcstmt.go +++ b/odbcstmt.go @@ -13,6 +13,7 @@ import ( "unsafe" "github.com/ibmdb/go_ibm_db/api" + trc "github.com/ibmdb/go_ibm_db/log2" ) // TODO(brainman): see if I could use SQLExecDirect anywhere @@ -28,6 +29,9 @@ 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) { @@ -47,6 +51,8 @@ func (c *Conn) PrepareODBCStmt(query string) (*ODBCStmt, error) { defer releaseHandle(h) return nil, err } + + trc.Trace1("odbcstmt.go: PrepareODBCStmt() - EXIT") return &ODBCStmt{ h: h, Parameters: ps, @@ -55,6 +61,8 @@ 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 { @@ -63,10 +71,13 @@ func (s *ODBCStmt) closeByStmt() error { return s.releaseHandle() } } + trc.Trace1("odbcstmt.go: closeByStmt() - EXIT") return nil } func (s *ODBCStmt) closeByRows() error { + trc.Trace1("odbcstmt.go: closeByRows()") + s.mu.Lock() defer s.mu.Unlock() if s.usedByRows { @@ -85,6 +96,8 @@ 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) @@ -93,6 +106,8 @@ func (s *ODBCStmt) releaseHandle() error { 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) { @@ -201,10 +216,13 @@ func (s *ODBCStmt) Exec(args []driver.Value) error { } } } + trc.Trace1("odbcstmt.go: Exec() - EXIT") return nil } func (s *ODBCStmt) BindColumns() error { + trc.Trace1("odbcstmt.go: BindColumns() - ENTRY") + // count columns var n api.SQLSMALLINT ret := api.SQLNumResultCols(s.h, &n) @@ -237,5 +255,6 @@ func (s *ODBCStmt) BindColumns() error { binding = false } } + trc.Trace1("odbcstmt.go: BindColumns() - EXIT") return nil } diff --git a/param.go b/param.go index 5e618ef..31fb787 100644 --- a/param.go +++ b/param.go @@ -12,6 +12,7 @@ import ( "unsafe" "github.com/ibmdb/go_ibm_db/api" + trc "github.com/ibmdb/go_ibm_db/log2" ) type Parameter struct { @@ -29,6 +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()") + p.StrLen_or_IndPtr = v return &p.StrLen_or_IndPtr @@ -37,6 +40,8 @@ func (p *Parameter) StoreStrLen_or_IndPtr(v api.SQLLEN) *api.SQLLEN { 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 @@ -262,12 +267,16 @@ 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 } // ExtractParameters will describe all the parameters 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) { @@ -275,6 +284,7 @@ func ExtractParameters(h api.SQLHSTMT) ([]Parameter, error) { } if n <= 0 { // no parameters + trc.Trace1("param.go: ExtractParameters() - no parameters") return nil, nil } ps := make([]Parameter, n) @@ -291,11 +301,14 @@ func ExtractParameters(h api.SQLHSTMT) ([]Parameter, error) { } p.isDescribed = true } + trc.Trace1("param.go: ExtractParameters() - EXIT") return ps, nil } //SqltoCtype function will convert the sql type to c type func SqltoCtype(sqltype api.SQLSMALLINT) api.SQLSMALLINT { + 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 de6a59e..a976431 100644 --- a/pooling.go +++ b/pooling.go @@ -5,8 +5,9 @@ import ( "fmt" "strconv" "strings" - "time" - "sync" + "time" + "sync" + trc "github.com/ibmdb/go_ibm_db/log2" ) //DBP struct type contains the timeout, dbinstance and connection string @@ -31,6 +32,9 @@ const defaultConnMaxLifetime = 60 //Pconnect will return the pool instance func Pconnect(poolSize string) *Pool { + trc.Trace1("pooling.go: Pconnect() - ENTRY") + trc.Trace1(fmt.Sprintf("poolSize=%s", poolSize)) + var size int count := len(poolSize) if count > 0 { @@ -53,6 +57,7 @@ func Pconnect(poolSize string) *Pool { } b = p + trc.Trace1("pooling.go: Pconnect() - EXIT") return p } @@ -62,6 +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(fmt.Sprintf("connStr=%s",connStr)) + var Time time.Duration count := len(options) if count > 0 { @@ -147,12 +155,18 @@ func (p *Pool) Open(connStr string, options ...string) *DBP { } } fmt.Println("Connection timeout") + trc.Trace1("Connection timeout") + trc.Trace1("pooling.go: Open() - EXIT") return nil } + trc.Trace1("pooling.go: Open() - EXIT") return nil } func (p *Pool) Init(numConn int, connStr string) bool{ + trc.Trace1("pooling.go: Init() - ENTRY") + trc.Trace1(fmt.Sprintf("numConn=%d, connStr=%s", numConn, connStr)) + var Time time.Duration if connMaxLifetime <= 0 { @@ -164,6 +178,7 @@ func (p *Pool) Init(numConn int, connStr string) bool{ for i := 0; i < numConn; i++ { db, err := sql.Open("go_ibm_db", connStr) if err != nil { + trc.Trace1("pooling.go: Init() - return false") return false } dbi := &DBP{ @@ -176,11 +191,14 @@ func (p *Pool) Init(numConn int, connStr string) bool{ dbi.SetConnMaxLifetime(Time) p.mu.Unlock() } + trc.Trace1("pooling.go: Init() - EXIT") return true } //Close will make the connection available for the next release func (d *DBP) Close() { + trc.Trace1("pooling.go: Close() - ENTRY") + pSize = pSize - 1 var pos int i := -1 @@ -209,10 +227,13 @@ func (d *DBP) Close() { d.DB.Close() } 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") + var pos int i := -1 select { @@ -240,10 +261,13 @@ func (d *DBP) Timeout() { } b.mu.Unlock() } + 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") + if p.availablePool != nil { for _, vala := range p.availablePool { for _, dbpr := range vala { @@ -260,10 +284,14 @@ func (p *Pool) Release() { } p.usedPool = nil } + trc.Trace1("pooling.go: Release() - EXIT") } //Set the connMaxLifetime func (p *Pool) SetConnMaxLifetime(num int) { + trc.Trace1("pooling.go: SetConnMaxLifetime()") + trc.Trace1(fmt.Sprintf("connMaxLifetime=%d", num)) + connMaxLifetime = num } diff --git a/rows.go b/rows.go index 833aceb..417351c 100644 --- a/rows.go +++ b/rows.go @@ -12,6 +12,7 @@ import ( "unsafe" "github.com/ibmdb/go_ibm_db/api" + trc "github.com/ibmdb/go_ibm_db/log2" ) type Rows struct { @@ -19,6 +20,8 @@ type Rows struct { } func (r *Rows) Columns() []string { + 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() @@ -28,6 +31,9 @@ func (r *Rows) Columns() []string { func (r *Rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) { //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) @@ -35,17 +41,20 @@ func (r *Rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok b if IsError(ret) { fmt.Println(ret) + trc.Trace1(fmt.Sprintf("Error: %s",ret)) return 0, 0, false } dbtype := string(namebuf[:namelen]) ret = api.SQLColAttribute(r.os.h, api.SQLUSMALLINT(index+1), api.SQL_DESC_PRECISION, api.SQLPOINTER(unsafe.Pointer(nil)), 0, (*api.SQLSMALLINT)(nil), (api.SQLPOINTER)(unsafe.Pointer(&precision))) if IsError(ret) { fmt.Println(ret) + trc.Trace1(fmt.Sprintf("Error: %s",ret)) return 0, 0, false } ret = api.SQLColAttribute(r.os.h, api.SQLUSMALLINT(index+1), api.SQL_DESC_SCALE, api.SQLPOINTER(unsafe.Pointer(nil)), 0, (*api.SQLSMALLINT)(nil), (api.SQLPOINTER)(unsafe.Pointer(&scale))) if IsError(ret) { fmt.Println(ret) + trc.Trace1(fmt.Sprintf("Error: %s",ret)) return 0, 0, false } if dbtype == "DECIMAL" { @@ -55,21 +64,29 @@ func (r *Rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok b } else if dbtype == "TIMESTAMP" { ok = true; } + + trc.Trace1(fmt.Sprintf("precision=%d, scale=%d", precision, scale)) + trc.Trace1("rows.go: ColumnTypePrecisionScale() - EXIT") return precision, scale, ok } 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) return 0, false } + trc.Trace1("rows.go: ColumnTypeLength() - EXIT") return length, true } 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) { @@ -79,12 +96,16 @@ func (r *Rows) ColumnTypeNullable(index int) (nullable, ok bool) { if null == api.SQL_NULLABLE { return true, true } + trc.Trace1("rows.go: ColumnTypeNullable() - EXIT") return false, true } func (r *Rows) ColumnTypeScanType(index int) reflect.Type { //TODO(AKHIL):This function will return the scantype that can be used to scan //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) } @@ -92,6 +113,8 @@ func (r *Rows) ColumnTypeScanType(index int) reflect.Type { 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))) @@ -101,10 +124,13 @@ func (r *Rows) ColumnTypeDatabaseTypeName(index int) string { return "" } dbtype := string(namebuf[:namelen]) + trc.Trace1("rows.go: ColumnTypeDatabaseTypeName() - EXIT") return dbtype } func (r *Rows) Next(dest []driver.Value) error { + trc.Trace1("rows.go: Next() - ENTRY") + ret := api.SQLFetch(r.os.h) if ret == api.SQL_NO_DATA { return io.EOF @@ -119,14 +145,19 @@ func (r *Rows) Next(dest []driver.Value) error { } dest[i] = v } + trc.Trace1("rows.go: Next() - EXIT") return nil } func (r *Rows) HasNextResultSet() bool { + trc.Trace1("rows.go: ()") + return true } func (r *Rows) NextResultSet() error { + trc.Trace1("rows.go: () - ENTRY") + ret := api.SQLMoreResults(r.os.h) if ret == api.SQL_NO_DATA { return io.EOF @@ -139,9 +170,12 @@ func (r *Rows) NextResultSet() error { if err != nil { return err } + trc.Trace1("rows.go: () - EXIT") return nil } func (r *Rows) Close() error { + trc.Trace1("rows.go: Close()") + return r.os.closeByRows() } diff --git a/sqlOut.go b/sqlOut.go index c428a5e..64bfe3d 100644 --- a/sqlOut.go +++ b/sqlOut.go @@ -12,6 +12,7 @@ import ( "unsafe" "github.com/ibmdb/go_ibm_db/api" + trc "github.com/ibmdb/go_ibm_db/log2" ) // Out struct is used to store the value of a OUT parameter in Stored Procedure @@ -30,6 +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(fmt.Sprintf("idx=%d", idx)) + var ctype, sqltype, decimalDigits, nullable, inputOutputType api.SQLSMALLINT var parameterSize api.SQLULEN var buflen api.SQLLEN @@ -138,6 +142,7 @@ func newOut(hstmt api.SQLHSTMT, sqlOut *sql.Out, idx int) (*Out, error) { plen = &buflen } + trc.Trace1("sqlOut.go: newOut() - EXIT") return &Out{ sqlOut: sqlOut, idx: idx + 1, @@ -155,6 +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") + var p unsafe.Pointer buf := o.data if len(buf) > 0 { @@ -207,11 +214,14 @@ func (o *Out) Value() (driver.Value, error) { case api.SQL_C_BINARY: return buf, nil } + trc.Trace1("sqlOut.go: Value() - EXIT") return nil, fmt.Errorf("unsupported ctype %d for OUT parameter", o.ctype) } // ConvertAssign function copies the database data to Dest field in stored procedure. func (o *Out) ConvertAssign() error { + trc.Trace1("sqlOut.go: ConvertAssign() - ENTRY") + if o.sqlOut == nil { return fmt.Errorf("sql.Out is nil at OUT param index %d", o.idx) } @@ -229,11 +239,14 @@ func (o *Out) ConvertAssign() error { if err != nil { return err } + trc.Trace1("sqlOut.go: ConvertAssign() - EXIT") return ConvertAssign(o.sqlOut.Dest, dv) } // ConvertAssign function copies the database data to Dest field in stored procedure. func ConvertAssign(dest, src interface{}) error { + trc.Trace1("sqlOut.go: ConvertAssign() - ENTRY") + switch s := src.(type) { case string: switch d := dest.(type) { @@ -427,10 +440,14 @@ func ConvertAssign(dest, src interface{}) error { } } + 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(fmt.Sprintf("Error:%s", err)) + if ne, ok := err.(*strconv.NumError); ok { return ne.Err } @@ -438,6 +455,8 @@ func strconvErr(err error) error { } func copyBytes(b []byte) []byte { + trc.Trace1("sqlOut.go: copyBytes()") + if b == nil { return nil } @@ -447,6 +466,8 @@ func copyBytes(b []byte) []byte { } func asString(src interface{}) string { + trc.Trace1("sqlOut.go: asString()") + switch v := src.(type) { case string: return v @@ -470,6 +491,8 @@ func asString(src interface{}) string { } func asBytes(buf []byte, rv reflect.Value) (b []byte, ok bool) { + 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 @@ -490,6 +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()") + 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 76f1ede..947f982 100644 --- a/stats.go +++ b/stats.go @@ -9,6 +9,7 @@ import ( "sync" "github.com/ibmdb/go_ibm_db/api" + trc "github.com/ibmdb/go_ibm_db/log2" ) type Stats struct { @@ -19,6 +20,9 @@ type Stats struct { } func (s *Stats) updateHandleCount(handleType api.SQLSMALLINT, change int) { + trc.Trace1("stats.go: updateHandleCount() - ENTRY") + trc.Trace1(fmt.Sprintf("change=%d", change)) + s.mu.Lock() defer s.mu.Unlock() switch handleType { @@ -29,6 +33,9 @@ func (s *Stats) updateHandleCount(handleType api.SQLSMALLINT, change int) { case api.SQL_HANDLE_STMT: s.StmtCount += change default: + 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/stmt.go b/stmt.go index 5459e5b..568c33e 100644 --- a/stmt.go +++ b/stmt.go @@ -12,6 +12,8 @@ import ( "time" "context" "github.com/ibmdb/go_ibm_db/api" + "fmt" + trc "github.com/ibmdb/go_ibm_db/log2" ) type Stmt struct { @@ -22,10 +24,17 @@ type Stmt struct { } func (c *Conn) Prepare( query string) (driver.Stmt, error) { + trc.Trace1("stmt.go: Prepare()") + trc.Trace1(fmt.Sprintf("query=%s", query)) + return c.PrepareContext(context.Background(), query) } + func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { + trc.Trace1("stmt.go: PrepareContext() - ENTRY") + trc.Trace1(fmt.Sprintf("query=%s", query)) + os, err := c.PrepareODBCStmt(query) if err != nil { return nil, err @@ -36,11 +45,13 @@ func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, e case <-ctx.Done(): return nil, ctx.Err() } - + trc.Trace1("stmt.go: PrepareContext() - EXIT") return &Stmt{c: c, os: os, query: query}, nil } func (s *Stmt) NumInput() int { + trc.Trace1("stmt.go: NumInput()") + if s.os == nil { return -1 } @@ -49,21 +60,29 @@ func (s *Stmt) NumInput() int { // Close closes the opened statement func (s *Stmt) Close() error { + trc.Trace1("stmt.go: Close() - ENTRY") + if s.os == nil { return errors.New("Stmt is already closed") } ret := s.os.closeByStmt() s.os = nil + + trc.Trace1("stmt.go: Close() - EXIT") return ret } // Exec executes the the sql but does not return the rows func (s *Stmt) Exec(args []driver.Value) (driver.Result, error) { + trc.Trace1("stmt.go: Exec()") + return s.exec(context.Background(), args) } // ExecContext implements driver.StmtExecContext interface func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) { + trc.Trace1("stmt.go: ExecContext()") + dargs := make([]driver.Value, len(args)) for n, param := range args { dargs[n] = param.Value @@ -72,6 +91,8 @@ func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (drive return s.exec(ctx, dargs) } func (s *Stmt) exec(ctx context.Context, args []driver.Value) (driver.Result, error) { + trc.Trace1("stmt.go: exec()- ENTRY") + if s.os == nil { return nil, errors.New("Stmt is closed") } @@ -110,16 +131,21 @@ func (s *Stmt) exec(ctx context.Context, args []driver.Value) (driver.Result, er return nil, ctx.Err() } + trc.Trace1("stmt.go: exec()- EXIT") return &Result{rowCount: sumRowCount}, nil } // Query function executes the sql and return rows if rows are present func (s *Stmt) Query(args []driver.Value) (driver.Rows, error) { + trc.Trace1("stmt.go: Query()") + return s.query1(context.Background(), args) } // QueryContext implements driver.StmtQueryContext interface func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) { + trc.Trace1("stmt.go: QueryContext()") + dargs := make([]driver.Value, len(args)) for n, param := range args { dargs[n] = param.Value @@ -129,6 +155,8 @@ func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driv } func (s *Stmt) query1(ctx context.Context, args []driver.Value) (driver.Rows, error) { + trc.Trace1("stmt.go: query1()") + if s.os == nil { return nil, errors.New("Stmt is closed") } @@ -164,6 +192,8 @@ func (s *Stmt) query1(ctx context.Context, args []driver.Value) (driver.Rows, er // CheckNamedValue implementes driver.NamedValueChecker. func (s *Stmt) CheckNamedValue(nv *driver.NamedValue) (err error) { + trc.Trace1("stmt.go: CheckNamedValue() - ENTRY") + switch d := nv.Value.(type) { case sql.Out: err = nil @@ -215,5 +245,6 @@ func (s *Stmt) CheckNamedValue(nv *driver.NamedValue) (err error) { default: nv.Value, err = driver.DefaultParameterConverter.ConvertValue(nv.Value) } + trc.Trace1("stmt.go: CheckNamedValue() - EXIT") return err } diff --git a/testdata/connectioninvaliddatabasename_test.go b/testdata/connectioninvaliddatabasename_test.go deleted file mode 100755 index 39c10b2..0000000 --- a/testdata/connectioninvaliddatabasename_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package main - -import ( - "testing" -) - -func TestConnectionInvalidDatabaseName(t *testing.T) { - if ConnectionInvalidDatabaseName() != 1 { - t.Error("Error at ConnectionInvalidDatabaseName") - } -} - - diff --git a/testdata/connectioninvalidportno_test.go b/testdata/connectioninvalidportno_test.go deleted file mode 100755 index 4e8fe06..0000000 --- a/testdata/connectioninvalidportno_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "testing" -) - -func TestConnectionInvalidPortNumber(t *testing.T) { - if ConnectionInvalidPortNumber() != 1 { - t.Error("Error at ConnectionInvalidPortNumber") - } -} diff --git a/testdata/connectioninvaliduserid_test.go b/testdata/connectioninvaliduserid_test.go deleted file mode 100755 index 4f70a3b..0000000 --- a/testdata/connectioninvaliduserid_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "testing" -) - -func TestConnectionInvalidUserID(t *testing.T) { - if ConnectionInvalidUserID() != 1 { - t.Error("Error at ConnectionInvalidUserID") - } -} diff --git a/testdata/connectioninvaliduserpwd_test.go b/testdata/connectioninvaliduserpwd_test.go deleted file mode 100755 index 39fea2d..0000000 --- a/testdata/connectioninvaliduserpwd_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "testing" -) - -func TestConnectionInvalidUserPassword(t *testing.T) { - if ConnectionInvalidUserPassword() != 1 { - t.Error("Error at ConnectionInvalidUserPassword") - } -} diff --git a/testdata/main.go b/testdata/main.go index c069e19..46ee786 100755 --- a/testdata/main.go +++ b/testdata/main.go @@ -108,7 +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 + connStr = "PROTOCOL=tcpip;HOSTNAME=" + host + ";PORT=" + port + ";DATABASE=" + database + ";UID=" + uid + ";PWD=" + pwd +";Security=ssl" db, _ = sql.Open("go_ibm_db", connStr) return db } diff --git a/testdata/queryContext_test.go b/testdata/queryContext_test.go deleted file mode 100644 index 8ff66c9..0000000 --- a/testdata/queryContext_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import "testing" - -func TestQueryContext(t *testing.T){ - if(QueryContext() != nil){ - t.Error("table not displayed") - } -} - -//QueryContext will execute the prepared statement -func QueryContext() error { - db := Createconnection() - defer db.Close() - st, _ := db.PrepareContext(ctx, "select * from rocket") - _, err := st.QueryContext(ctx) - if err != nil { - return err - } - return nil -} - diff --git a/testdata/query_test.go b/testdata/query_test.go deleted file mode 100644 index 906bff0..0000000 --- a/testdata/query_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import "testing" - -func TestQuery(t *testing.T){ - if(Query() != nil){ - t.Error("table not displayed") -} -} \ No newline at end of file diff --git a/testdata/scan_test.go b/testdata/scan_test.go deleted file mode 100644 index d590804..0000000 --- a/testdata/scan_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import "testing" - -func TestScan(t *testing.T) { - if Scan() != nil { - t.Error("Error in Scanning Query") - } -} diff --git a/testdata/spArray_test.go b/testdata/spArray_test.go deleted file mode 100755 index ff1be07..0000000 --- a/testdata/spArray_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - //"database/sql" - "fmt" - "strings" - "testing" -) - -func TestStoredProcedureArray(t *testing.T) { - if StoredProcedureArray_1() != nil { - t.Error("Error at stored procedure array") - } -} - -func StoredProcedureArray_1() error{ - db := Createconnection() - - var arr1 = []int{10, 20, 30, 40, 50} - var arr2 = []string{"Row 10", "Row 20", "Row 30", "Row 40", "Row 50"} - - db.Exec("Drop table TT") - - _, err1 := db.Exec("Drop procedure sp1(INTEGER, VARCHAR(10))") - if err1 != nil { - fmt.Println("Drop procedure error : ", err1) - return err1 - } - - _, err := db.Exec("create table TT(C1 INTEGER NOT NULL, C2 VARCHAR(10))"); - if err != nil { - fmt.Println("Error: ", err) - return err - } - - st, err := db.Prepare("create procedure sp1(in arr1 INTEGER, in arr2 VARCHAR(10)) LANGUAGE SQL BEGIN INSERT INTO TT VALUES(arr1, arr2); END") - if err != nil { - fmt.Println("Error: ", err) - return err - } - - _, err = st.Query() - if !strings.Contains(fmt.Sprint(err), "did not create a result set") { - return err - } - - _, err = db.Exec("CALL sp1(?,?)", arr1, arr2) - if err != nil { - fmt.Println("Error: ", err) - return err - } -/* - queryTypes := "select * from TT;" - - rows, err := db.Query(queryTypes) - if err != nil { - fmt.Println("Error:", err) - return err - } - - for rows.Next() { - var c1 int - var c2 string - err = rows.Scan(&c1, &c2) - if err != nil { - fmt.Println("Error:", err) - } - fmt.Printf("C1=: %v\t C2: %v\n", c1, c2) - } -*/ - return nil -} - diff --git a/testdata/spInOut_test.go b/testdata/spInOut_test.go deleted file mode 100644 index 62adf8e..0000000 --- a/testdata/spInOut_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package main - -import ( - "database/sql" - "fmt" - "testing" -) - -func TestStoredProcedureInOut(t *testing.T) { - if StoredProcedureInOut() != nil { - t.Error("Error at stored procedure") - } -} - -//StoredProcedureInOut function tests OUT Parameter by calling get_dbsize_info. -func StoredProcedureInOut() error { - db := Createconnection() - defer db.Close() - in1 := 10 - inout1 := 2 - var out1, out2 int - st, err := db.Prepare("create or replace procedure sp2(in var1 integer, inout var2 integer, out var3 integer, out var4 integer) LANGUAGE SQL BEGIN SET var2 = var1 + var2; SET var3 = var1 - var2; SET var4 = var1 * var2; END") - if err != nil { - return err - } - st.Query() - _, err = db.Exec("CALL sp2(?,?,?,?)", in1, sql.Out{Dest: &inout1, In: true}, sql.Out{Dest: &out1}, sql.Out{Dest: &out2}) - if err != nil { - return err - } - if inout1 != 12 || out1 != -2 || out2 != 120 { - return fmt.Errorf("Wrong data retrieved") - } - return nil -} - - diff --git a/testdata/sp_test.go b/testdata/sp_test.go deleted file mode 100644 index 7bd5bc5..0000000 --- a/testdata/sp_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "database/sql" - "time" - "testing" -) - -func TestStoredProcedure(t *testing.T) { - if StoredProcedure() != nil { - t.Error("Error at stored procedure") - } -} - - -//StoredProcedure function tests OUT Parameter by calling get_dbsize_info. -func StoredProcedure() error { - var ( - snapTime time.Time - dbsize int64 - dbcapacity int64 - ) - db := Createconnection() - defer db.Close() - _, err := db.Exec("call sysproc.get_dbsize_info(?, ?, ?,0)", sql.Out{Dest: &snapTime}, sql.Out{Dest: &dbsize}, sql.Out{Dest: &dbcapacity}) - if err != nil { - return err - } - return nil -} -