From 3cfc5683cac058d99eceee88294fd2e3da2d2379 Mon Sep 17 00:00:00 2001 From: hydernaqvi Date: Mon, 13 May 2024 04:02:18 -0700 Subject: [PATCH] Cleanup Files and README (#240) This commit fixes the README files with special attention to instructions and sample code along with useful comments. All recently changed and created files have also had their copyright years updated. Spacing in files has also been modified to make the files easier to read. Build tags updated Signed-off-by: Hyder Naqvi Co-authored-by: Hyder Naqvi --- LICENSE.md | 2 +- README.md | 13 ++- api/api_zos.go | 267 +++++++++++++++++++++++++----------------------- api/zapi_zos.go | 56 +++++----- conn.go | 14 +-- error.go | 8 +- 6 files changed, 185 insertions(+), 175 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 7448756..60a01d6 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2012 The Go Authors. All rights reserved. +Copyright (c) 2024 The Go Authors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are diff --git a/README.md b/README.md index 7554829..6f67d49 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ or go install github.com/ibmdb/go_ibm_db/installer@latest ``` -## How to Install in Windows +## How to Install in z/OS - You may install go_ibm_db using the below command @@ -347,7 +347,7 @@ func create(db *sql.DB) error { // Inserting row. func insert(db *sql.DB) error { - st, err := db.Prepare("Insert into SAMPLE(ID,NAME,LOCATION,POSITION) values('3242','mike','hyd','manager')") + st, err := db.Prepare("Insert into SAMPLE(ID,NAME,LOCATION,POSITION) values('3242','Mike','Hyderabad','Manager')") if err != nil { return err } @@ -384,7 +384,7 @@ func execquery(st *sql.Stmt) error { if err != nil { return err } - fmt.Printf("%v %v %v %v\n", t, x, m, n) + fmt.Printf("%v %v %v %v\n", t, x, m, n) } return nil } @@ -422,6 +422,9 @@ import ( ) func main() { + // Defining connection string + // Depending on your connection type + // you may wish to add: MULTICONTEXT=0 con := "HOSTNAME=host;PORT=number;DATABASE=name;UID=username;PWD=password" pool := a.Pconnect("PoolSize=100") @@ -444,7 +447,7 @@ func main() { db1.Close() db.Close() pool.Release() - fmt.println("success") + fmt.Println("success") } ``` To run the sample:- go run example3.go @@ -495,7 +498,7 @@ func main() { fmt.Println("err1 : ", err1) }else{ go func() { - execquery(st1) + ExecQuery(st1) db1.Close() }() } diff --git a/api/api_zos.go b/api/api_zos.go index 3fbc0b1..d87ca9d 100644 --- a/api/api_zos.go +++ b/api/api_zos.go @@ -1,9 +1,16 @@ -package api +// Copyright 2024 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. + +//go:build zos + +package api import ( - "runtime" "log" + "runtime" "unsafe" + "github.com/ibmruntimes/go-recordio/v2/utils" ) @@ -17,143 +24,143 @@ func getFunc(dll *utils.Dll, str string) uintptr { } const ( - SQL_MAX_OPTION_STRING_LENGTH = 256 - SQL_OV_ODBC3= 3 - SQL_ATTR_ODBC_VERSION= 200 - SQL_DRIVER_NOPROMPT= 0 - SQL_HANDLE_ENV= 1 - SQL_HANDLE_DBC= 2 - SQL_HANDLE_STMT= 3 - SQL_SUCCESS= 0 - SQL_SUCCESS_WITH_INFO= 1 - SQL_INVALID_HANDLE= -2 - SQL_NO_DATA= 100 - SQL_NO_TOTAL= -4 - SQL_NTS= -3 - SQL_MAX_MESSAGE_LENGTH= 1024 - SQL_NULL_HANDLE= 0 - SQL_NULL_HENV= 0 - SQL_NULL_HDBC= 0 - SQL_NULL_HSTMT= 0 - SQL_PARAM_INPUT= 1 - SQL_PARAM_OUTPUT= 4 - SQL_PARAM_INPUT_OUTPUT= 2 - SQL_NULL_DATA= -1 - SQL_DATA_AT_EXEC= -2 - SQL_CHAR= 1 - SQL_NUMERIC= 2 - SQL_DECIMAL= 3 - SQL_INTEGER= 4 - SQL_SMALLINT= 5 - SQL_FLOAT= 6 - SQL_REAL= 7 - SQL_DOUBLE= 8 - SQL_DATETIME= 9 - SQL_DATE= 9 - SQL_TIME= 10 - SQL_VARCHAR= 12 - SQL_TYPE_DATE= 91 - SQL_TYPE_TIME= 92 - SQL_TYPE_TIMESTAMP= 93 - SQL_TIMESTAMP= 11 - SQL_LONGVARCHAR= -1 - SQL_BINARY= -2 - SQL_VARBINARY= -3 - SQL_LONGVARBINARY= -4 - SQL_BIGINT= -5 - SQL_TINYINT= -6 - SQL_BIT= -7 - SQL_WCHAR= -8 - SQL_WVARCHAR= -9 - SQL_WLONGVARCHAR= -10 - SQL_BLOB= -98 - SQL_CLOB= -99 - SQL_SIGNED_OFFSET= -20 - SQL_UNSIGNED_OFFSET= -22 - SQL_DBCLOB= -350 - SQL_XML= -370 - SQL_COMMIT= 0 - SQL_ROLLBACK= 1 - SQL_AUTOCOMMIT= 102 - SQL_ATTR_AUTOCOMMIT= 102 - SQL_AUTOCOMMIT_OFF= 0 - SQL_AUTOCOMMIT_ON= 1 - SQL_AUTOCOMMIT_DEFAULT= 1 - SQL_DESC_PRECISION= 1005 - SQL_DESC_SCALE= 1006 - SQL_DESC_LENGTH= 1003 - SQL_DESC_CONCISE_TYPE= 2 - SQL_DESC_TYPE_NAME= 14 - SQL_COLUMN_TYPE= 2 - SQL_COLUMN_TYPE_NAME= 14 - SQL_DESC_NULLABLE= 1008 - SQL_NULLABLE= 1 - SQL_NO_NULLS= 0 - SQL_DECFLOAT= -360 - SQL_ATTR_PARAMSET_SIZE= 22 - SQL_IS_UINTEGER= -5 - SQL_IS_INTEGER= -6 - SQL_ATTR_CONNECTION_POOLING= 201 - SQL_ATTR_CP_MATCH= 202 - SQL_CP_OFF= 0 - SQL_CP_ONE_PER_DRIVER= 1 - SQL_CP_ONE_PER_HENV= 2 - SQL_CP_DEFAULT= 0 - SQL_CP_STRICT_MATCH= 0 - SQL_CP_RELAXED_MATCH= 1 - SQL_C_CHAR= 1 - SQL_C_LONG= 4 - SQL_C_SHORT= 5 - SQL_C_FLOAT= 7 - SQL_C_DOUBLE= 8 - SQL_C_NUMERIC= 2 - SQL_C_DATE= 9 - SQL_C_TIME= 10 - SQL_C_TYPE_TIMESTAMP= 93 - SQL_C_TIMESTAMP= 11 - SQL_C_BINARY= -2 - SQL_C_BIT= -7 - SQL_C_WCHAR= -8 - SQL_C_DEFAULT= 99 - SQL_C_SBIGINT= -25 - SQL_C_UBIGINT= -27 - SQL_C_DBCHAR= -350 - SQL_C_TYPE_DATE= 91 - SQL_C_TYPE_TIME= 92 + SQL_MAX_OPTION_STRING_LENGTH = 256 + SQL_OV_ODBC3 = 3 + SQL_ATTR_ODBC_VERSION = 200 + SQL_DRIVER_NOPROMPT = 0 + SQL_HANDLE_ENV = 1 + SQL_HANDLE_DBC = 2 + SQL_HANDLE_STMT = 3 + SQL_SUCCESS = 0 + SQL_SUCCESS_WITH_INFO = 1 + SQL_INVALID_HANDLE = -2 + SQL_NO_DATA = 100 + SQL_NO_TOTAL = -4 + SQL_NTS = -3 + SQL_MAX_MESSAGE_LENGTH = 1024 + SQL_NULL_HANDLE = 0 + SQL_NULL_HENV = 0 + SQL_NULL_HDBC = 0 + SQL_NULL_HSTMT = 0 + SQL_PARAM_INPUT = 1 + SQL_PARAM_OUTPUT = 4 + SQL_PARAM_INPUT_OUTPUT = 2 + SQL_NULL_DATA = -1 + SQL_DATA_AT_EXEC = -2 + SQL_CHAR = 1 + SQL_NUMERIC = 2 + SQL_DECIMAL = 3 + SQL_INTEGER = 4 + SQL_SMALLINT = 5 + SQL_FLOAT = 6 + SQL_REAL = 7 + SQL_DOUBLE = 8 + SQL_DATETIME = 9 + SQL_DATE = 9 + SQL_TIME = 10 + SQL_VARCHAR = 12 + SQL_TYPE_DATE = 91 + SQL_TYPE_TIME = 92 + SQL_TYPE_TIMESTAMP = 93 + SQL_TIMESTAMP = 11 + SQL_LONGVARCHAR = -1 + SQL_BINARY = -2 + SQL_VARBINARY = -3 + SQL_LONGVARBINARY = -4 + SQL_BIGINT = -5 + SQL_TINYINT = -6 + SQL_BIT = -7 + SQL_WCHAR = -8 + SQL_WVARCHAR = -9 + SQL_WLONGVARCHAR = -10 + SQL_BLOB = -98 + SQL_CLOB = -99 + SQL_SIGNED_OFFSET = -20 + SQL_UNSIGNED_OFFSET = -22 + SQL_DBCLOB = -350 + SQL_XML = -370 + SQL_COMMIT = 0 + SQL_ROLLBACK = 1 + SQL_AUTOCOMMIT = 102 + SQL_ATTR_AUTOCOMMIT = 102 + SQL_AUTOCOMMIT_OFF = 0 + SQL_AUTOCOMMIT_ON = 1 + SQL_AUTOCOMMIT_DEFAULT = 1 + SQL_DESC_PRECISION = 1005 + SQL_DESC_SCALE = 1006 + SQL_DESC_LENGTH = 1003 + SQL_DESC_CONCISE_TYPE = 2 + SQL_DESC_TYPE_NAME = 14 + SQL_COLUMN_TYPE = 2 + SQL_COLUMN_TYPE_NAME = 14 + SQL_DESC_NULLABLE = 1008 + SQL_NULLABLE = 1 + SQL_NO_NULLS = 0 + SQL_DECFLOAT = -360 + SQL_ATTR_PARAMSET_SIZE = 22 + SQL_IS_UINTEGER = -5 + SQL_IS_INTEGER = -6 + SQL_ATTR_CONNECTION_POOLING = 201 + SQL_ATTR_CP_MATCH = 202 + SQL_CP_OFF = 0 + SQL_CP_ONE_PER_DRIVER = 1 + SQL_CP_ONE_PER_HENV = 2 + SQL_CP_DEFAULT = 0 + SQL_CP_STRICT_MATCH = 0 + SQL_CP_RELAXED_MATCH = 1 + SQL_C_CHAR = 1 + SQL_C_LONG = 4 + SQL_C_SHORT = 5 + SQL_C_FLOAT = 7 + SQL_C_DOUBLE = 8 + SQL_C_NUMERIC = 2 + SQL_C_DATE = 9 + SQL_C_TIME = 10 + SQL_C_TYPE_TIMESTAMP = 93 + SQL_C_TIMESTAMP = 11 + SQL_C_BINARY = -2 + SQL_C_BIT = -7 + SQL_C_WCHAR = -8 + SQL_C_DEFAULT = 99 + SQL_C_SBIGINT = -25 + SQL_C_UBIGINT = -27 + SQL_C_DBCHAR = -350 + SQL_C_TYPE_DATE = 91 + SQL_C_TYPE_TIME = 92 // TODO(hyder): Not defined in sqlext.h. Using windows value, but it is not supported. SQL_SS_XML = -152 MAX_FIELD_SIZE = 1024 - SQL_BOOLEAN = 16 + SQL_BOOLEAN = 16 ) type ( - SQLCHAR byte - SQLSCHAR byte - SQLINTEGER int32 - SDWORD int32 - SQLSMALLINT int16 - SQLDOUBLE float64 - SQLREAL float32 - SQLBIGINT int64 - ODBCINT64 int64 - SQLRETURN int16 - UDWORD uint32 - SQLUINTEGER uint32 - SQLUSMALLINT uint16 + SQLCHAR byte + SQLSCHAR byte + SQLINTEGER int32 + SDWORD int32 + SQLSMALLINT int16 + SQLDOUBLE float64 + SQLREAL float32 + SQLBIGINT int64 + ODBCINT64 int64 + SQLRETURN int16 + UDWORD uint32 + SQLUINTEGER uint32 + SQLUSMALLINT uint16 SQLSETPOSIROW uint16 - UWORD uint16 - SQLPOINTER unsafe.Pointer - SQLLEN SQLINTEGER - SQLULEN SQLUINTEGER - SQLDBCHAR uint16 - SQLWCHAR uint16 - SQLHANDLE SQLINTEGER - SQLHENV SQLINTEGER - SQLHDBC SQLINTEGER - SQLHSTMT SQLINTEGER - SQLHWND uintptr + UWORD uint16 + SQLPOINTER unsafe.Pointer + SQLLEN SQLINTEGER + SQLULEN SQLUINTEGER + SQLDBCHAR uint16 + SQLWCHAR uint16 + SQLHANDLE SQLINTEGER + SQLHENV SQLINTEGER + SQLHDBC SQLINTEGER + SQLHSTMT SQLINTEGER + SQLHWND uintptr ) func SQLSetEnvUIntPtrAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) { diff --git a/api/zapi_zos.go b/api/zapi_zos.go index debf264..9b9eaaf 100644 --- a/api/zapi_zos.go +++ b/api/zapi_zos.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build zos +//go:build zos package api @@ -25,132 +25,132 @@ func init() { } } -func SQLAllocHandle(handleType SQLSMALLINT, inputHandle SQLHANDLE, outputHandle *SQLHANDLE) (SQLRETURN) { +func SQLAllocHandle(handleType SQLSMALLINT, inputHandle SQLHANDLE, outputHandle *SQLHANDLE) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLAllocHandle"), uintptr(handleType), uintptr(inputHandle), uintptr(unsafe.Pointer(outputHandle))) 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 { r := utils.CfuncEbcdic(getFunc(&dll, "SQLBindCol"), uintptr(statementHandle), uintptr(columnNumber), uintptr(targetType), uintptr(unsafe.Pointer(&targetValuePtr[0])), uintptr(bufferLength), uintptr(unsafe.Pointer(vallen))) 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 { 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))) return SQLRETURN(r) } -func SQLCloseCursor(statementHandle SQLHSTMT) (SQLRETURN) { +func SQLCloseCursor(statementHandle SQLHSTMT) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLCloseCursor"), uintptr(statementHandle)) return SQLRETURN(r) } -func SQLDescribeCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, columnName *SQLWCHAR, bufferLength SQLSMALLINT, nameLengthPtr *SQLSMALLINT, dataTypePtr *SQLSMALLINT, columnSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) (SQLRETURN) { +func SQLDescribeCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, columnName *SQLWCHAR, bufferLength SQLSMALLINT, nameLengthPtr *SQLSMALLINT, dataTypePtr *SQLSMALLINT, columnSizePtr *SQLULEN, decimalDigitsPtr *SQLSMALLINT, nullablePtr *SQLSMALLINT) SQLRETURN { 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))) 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 { 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))) return SQLRETURN(r) } -func SQLDisconnect(connectionHandle SQLHDBC) (SQLRETURN) { +func SQLDisconnect(connectionHandle SQLHDBC) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLDisconnect"), uintptr(connectionHandle)) 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 { + 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)) return SQLRETURN(r) } -func SQLEndTran(handleType SQLSMALLINT, handle SQLHANDLE, completionType SQLSMALLINT) (SQLRETURN) { +func SQLEndTran(handleType SQLSMALLINT, handle SQLHANDLE, completionType SQLSMALLINT) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLEndTran"), uintptr(handleType), uintptr(handle), uintptr(completionType)) return SQLRETURN(r) } -func SQLExecute(statementHandle SQLHSTMT) (SQLRETURN) { +func SQLExecute(statementHandle SQLHSTMT) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLExecute"), uintptr(statementHandle)) return SQLRETURN(r) } -func SQLFetch(statementHandle SQLHSTMT) (SQLRETURN) { +func SQLFetch(statementHandle SQLHSTMT) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLFetch"), uintptr(statementHandle)) return SQLRETURN(r) } -func SQLFreeHandle(handleType SQLSMALLINT, handle SQLHANDLE) (SQLRETURN) { +func SQLFreeHandle(handleType SQLSMALLINT, handle SQLHANDLE) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLFreeHandle"), uintptr(handleType), uintptr(handle)) 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 { r := utils.CfuncEbcdic(getFunc(&dll, "SQLGetData"), uintptr(statementHandle), uintptr(colOrParamNum), uintptr(targetType), uintptr(targetValuePtr), uintptr(bufferLength), uintptr(unsafe.Pointer(vallen))) 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 { 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))) return SQLRETURN(r) } -func SQLNumParams(statementHandle SQLHSTMT, parameterCountPtr *SQLSMALLINT) (SQLRETURN) { +func SQLNumParams(statementHandle SQLHSTMT, parameterCountPtr *SQLSMALLINT) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLNumParams"), uintptr(statementHandle), uintptr(unsafe.Pointer(parameterCountPtr))) return SQLRETURN(r) } -func SQLNumResultCols(statementHandle SQLHSTMT, columnCountPtr *SQLSMALLINT) (SQLRETURN) { +func SQLNumResultCols(statementHandle SQLHSTMT, columnCountPtr *SQLSMALLINT) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLNumResultCols"), uintptr(statementHandle), uintptr(unsafe.Pointer(columnCountPtr))) return SQLRETURN(r) } -func SQLPrepare(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (SQLRETURN) { +func SQLPrepare(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLPrepareW"), uintptr(statementHandle), uintptr(unsafe.Pointer(statementText)), uintptr(textLength)) return SQLRETURN(r) } -func SQLRowCount(statementHandle SQLHSTMT, rowCountPtr *SQLLEN) (SQLRETURN) { +func SQLRowCount(statementHandle SQLHSTMT, rowCountPtr *SQLLEN) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLRowCount"), uintptr(statementHandle), uintptr(unsafe.Pointer(rowCountPtr))) 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 { r := utils.CfuncEbcdic(getFunc(&dll, "SQLSetEnvAttr"), uintptr(environmentHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength)) 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 { r := utils.CfuncEbcdic(getFunc(&dll, "SQLSetConnectAttrW"), uintptr(connectionHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength)) 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 { r := utils.CfuncEbcdic(getFunc(&dll, "SQLColAttribute"), uintptr(statementHandle), uintptr(ColumnNumber), uintptr(FieldIdentifier), uintptr(CharacterAttributePtr), uintptr(BufferLength), uintptr(unsafe.Pointer(StringLengthPtr)), uintptr(NumericAttributePtr)) return SQLRETURN(r) } -func SQLMoreResults(statementHandle SQLHSTMT) (SQLRETURN) { +func SQLMoreResults(statementHandle SQLHSTMT) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLMoreResults"), uintptr(statementHandle)) 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 { r := utils.CfuncEbcdic(getFunc(&dll, "SQLSetStmtAttr"), uintptr(statementHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength)) 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 { 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)) return SQLRETURN(r) } -func SQLDropDb(connectionHandle SQLHDBC, dbnamePtr *SQLWCHAR, dbnameLen SQLINTEGER) (SQLRETURN) { +func SQLDropDb(connectionHandle SQLHDBC, dbnamePtr *SQLWCHAR, dbnameLen SQLINTEGER) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLDropDbW"), uintptr(connectionHandle), uintptr(unsafe.Pointer(dbnamePtr)), uintptr(dbnameLen)) return SQLRETURN(r) } -func SQLExecDirect(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (SQLRETURN) { +func SQLExecDirect(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) SQLRETURN { r := utils.CfuncEbcdic(getFunc(&dll, "SQLExecDirectW"), uintptr(statementHandle), uintptr(unsafe.Pointer(statementText)), uintptr(textLength)) return SQLRETURN(r) } diff --git a/conn.go b/conn.go index bf0ef52..5a65bf1 100644 --- a/conn.go +++ b/conn.go @@ -1,4 +1,4 @@ -// Copyright 2012 The Go Authors. All rights reserved. +// Copyright 2024 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. @@ -27,14 +27,14 @@ func (d *Driver) Open(dsn string) (driver.Conn, error) { drv.Stats.updateHandleCount(api.SQL_HANDLE_DBC, 1) b := api.StringToUTF16(dsn) - if runtime.GOOS == "zos"{ + if runtime.GOOS == "zos" { ret = api.SQLDriverConnect(h, 0, - (*api.SQLWCHAR)(unsafe.Pointer(&b[0])), api.SQLSMALLINT(2*len(b)), // odbc api on zos doesn't handle null terminated strings, the exact size is passed - nil, 0, nil, api.SQL_DRIVER_NOPROMPT) + (*api.SQLWCHAR)(unsafe.Pointer(&b[0])), api.SQLSMALLINT(2*len(b)), // odbc api on zos doesn't handle null terminated strings, the exact size is passed + nil, 0, nil, api.SQL_DRIVER_NOPROMPT) } else { ret = api.SQLDriverConnect(h, 0, - (*api.SQLWCHAR)(unsafe.Pointer(&b[0])), api.SQLSMALLINT(len(b)), - nil, 0, nil, api.SQL_DRIVER_NOPROMPT) + (*api.SQLWCHAR)(unsafe.Pointer(&b[0])), api.SQLSMALLINT(len(b)), + nil, 0, nil, api.SQL_DRIVER_NOPROMPT) } if IsError(ret) { defer releaseHandle(h) @@ -53,7 +53,7 @@ func (c *Conn) Close() error { 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) { if len(args) > 0 { // Not implemented for queries with parameters diff --git a/error.go b/error.go index 35cb7ad..39d9aea 100644 --- a/error.go +++ b/error.go @@ -1,4 +1,4 @@ -// Copyright 2012 The Go Authors. All rights reserved. +// Copyright 2024 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. @@ -49,17 +49,17 @@ func NewError(apiName string, handle interface{}) error { state := make([]uint16, 6) msg := make([]uint16, api.SQL_MAX_MESSAGE_LENGTH) for i := 1; ; i++ { - if runtime.GOOS == "zos"{ + if runtime.GOOS == "zos" { ret = api.SQLGetDiagRec(ht, h, api.SQLSMALLINT(i), (*api.SQLWCHAR)(unsafe.Pointer(&state[0])), &ne, (*api.SQLWCHAR)(unsafe.Pointer(&msg[0])), api.SQLSMALLINT(2*len(msg)), nil) // odbc api on zos doesn't handle null terminated strings, the exact size is passed - } else { + } else { ret = api.SQLGetDiagRec(ht, h, api.SQLSMALLINT(i), (*api.SQLWCHAR)(unsafe.Pointer(&state[0])), &ne, (*api.SQLWCHAR)(unsafe.Pointer(&msg[0])), api.SQLSMALLINT(len(msg)), nil) - } + } if ret == api.SQL_NO_DATA { break }