Skip to content

Commit

Permalink
Code alignment (#244)
Browse files Browse the repository at this point in the history
* Updated code alignment

---------

Co-authored-by: Vikas Mathur <[email protected]>
  • Loading branch information
vmathur12 and Vikas Mathur authored Jul 26, 2024
1 parent 30028d8 commit c9ab3e6
Show file tree
Hide file tree
Showing 23 changed files with 502 additions and 425 deletions.
16 changes: 8 additions & 8 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type (
// UTF16ToString returns the UTF-8 encoding of the UTF-16 sequence s,
// with a terminating NUL removed.
func UTF16ToString(s []uint16) string {
trc.Trace1("api/api.go UTF16ToString() - ENTRY")
trc.Trace1("api/api.go UTF16ToString() - ENTRY")
for i, v := range s {
if v == 0 {
s = s[0:i]
Expand All @@ -74,9 +74,9 @@ func UTF16ToString(s []uint16) string {
// with a terminating NUL added.
//func StringToUTF16(s string) []uint16 { return utf16.Encode([]rune(s + "\u0000")) }
func StringToUTF16(s string) []uint16 {
trc.Trace1("api/api.go StringToUTF16()")
trc.Trace1("api/api.go StringToUTF16()")
trc.Trace1(fmt.Sprintf("api/api.go StringToUTF16() - s = %s", s))

if runtime.GOOS == "zos"{
return utf16.Encode([]rune(s))
}else {
Expand All @@ -91,26 +91,26 @@ func StringToUTF16Ptr(s string) *uint16 { return &StringToUTF16(s)[0] }

// ExtractUTF16Str uses unsafe package to copy UTF16 string to a byte slice.
func ExtractUTF16Str(s []uint16) []byte {
trc.Trace1("api/api.go ExtractUTF16Str() - ENTRY")
trc.Trace1("api/api.go ExtractUTF16Str() - ENTRY")

var out []byte
for i := range s {
b := Extract(unsafe.Pointer(&s[i]), unsafe.Sizeof(s[i]))
out = append(out, b...)
}

trc.Trace1("api/api.go ExtractUTF16Str() - EXIT")
return out
}

func Extract(ptr unsafe.Pointer, size uintptr) []byte {
trc.Trace1("api/api.go Extract() - ENTRY")

out := make([]byte, size)
for i := range out {
out[i] = *((*byte)(unsafe.Pointer(uintptr(ptr) + uintptr(i))))
}

trc.Trace1("api/api.go Extract() - EXIT")
return out
}
16 changes: 8 additions & 8 deletions api/api_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package api

import (
trc "github.com/ibmdb/go_ibm_db/log2"
trc "github.com/ibmdb/go_ibm_db/log2"
"fmt"
)

Expand Down Expand Up @@ -177,23 +177,23 @@ type (
)

func SQLSetEnvUIntPtrAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) {
trc.Trace1("api/api_unix.go SQLSetEnvUIntPtrAttr() - ENTRY)
trc.Trace1("api/api_unix.go SQLSetEnvUIntPtrAttr() - ENTRY")
trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=0x%x, stringLength=%d", attribute, valuePtr, stringLength))

r := C.sqlSetEnvUIntPtrAttr(C.SQLHENV(environmentHandle), C.SQLINTEGER(attribute), C.uintptr_t(valuePtr), C.SQLINTEGER(stringLength))

trc.Trace1(fmt.Sprintf("r = %d", r))
trc.Trace1("api/api_unix.go SQLSetEnvUIntPtrAttr() - EXIT)
trc.Trace1("api/api_unix.go SQLSetEnvUIntPtrAttr() - EXIT")
return SQLRETURN(r)
}

func SQLSetConnectUIntPtrAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) {
trc.Trace1("api/api_unix.go SQLSetConnectUIntPtrAttr() - ENTRY)
trc.Trace1("api/api_unix.go SQLSetConnectUIntPtrAttr() - ENTRY")
trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=%x, stringLength=%d", attribute, valuePtr, stringLength))

r := C.sqlSetConnectUIntPtrAttr(C.SQLHDBC(connectionHandle), C.SQLINTEGER(attribute), C.uintptr_t(valuePtr), C.SQLINTEGER(stringLength))

trc.Trace1(fmt.Sprintf("r = %d", r))
trc.Trace1("api/api_unix.go SQLSetConnectUIntPtrAttr() - EXIT)
trc.Trace1("api/api_unix.go SQLSetConnectUIntPtrAttr() - EXIT")
return SQLRETURN(r)
}
72 changes: 57 additions & 15 deletions api/api_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package api

import (
"syscall"
trc "github.com/ibmdb/go_ibm_db/log2"
trc "github.com/ibmdb/go_ibm_db/log2"
"fmt"
)

Expand Down Expand Up @@ -112,10 +112,51 @@ const (
SQL_AUTOCOMMIT_ON = 1
SQL_AUTOCOMMIT_DEFAULT = SQL_AUTOCOMMIT_ON
SQL_ATTR_PARAMSET_SIZE = 22
// Statement attributes
SQL_ROW_NUMBER = 14

// Statement attributes for ODBC 3.0
SQL_ATTR_CURSOR_TYPE = 6
//SQL_ATTR_PARAMSET_SIZE = 22
SQL_ATTR_ROW_NUMBER = SQL_ROW_NUMBER
SQL_ATTR_ROW_ARRAY_SIZE = 27
SQL_ATTR_ROW_STATUS_PTR = 25
SQL_ATTR_ROWS_FETCHED_PTR = 26

// SQL_CURSOR_TYPE options
SQL_CURSOR_FORWARD_ONLY = 0
SQL_CURSOR_KEYSET_DRIVEN = 1
SQL_CURSOR_DYNAMIC = 2
SQL_CURSOR_STATIC = 3
SQL_CURSOR_TYPE_DEFAULT = SQL_CURSOR_FORWARD_ONLY

// Operations in SQLSetPos
SQL_POSITION = 0
SQL_REFRESH = 1
SQL_UPDATE = 2
SQL_DELETE = 3

// Operations in SQLBulkOperations
SQL_ADD = 4
SQL_SETPOS_MAX_OPTION_VALUE = SQL_ADD
SQL_UPDATE_BY_BOOKMARK = 5 // Check if to be removed
SQL_DELETE_BY_BOOKMARK = 6
SQL_FETCH_BY_BOOKMARK = 7

// Lock options in SQLSetPos
SQL_LOCK_NO_CHANGE = 0

SQL_IS_UINTEGER = -5
SQL_IS_INTEGER = -6

// Fetch Orientation in SQLFetchScroll
SQL_FETCH_NEXT = 1
SQL_FETCH_FIRST = 2
SQL_FETCH_LAST = 3
SQL_FETCH_PRIOR = 4
SQL_FETCH_ABSOLUTE = 5
SQL_FETCH_RELATIVE = 6

//Connection pooling
SQL_ATTR_CONNECTION_POOLING = 201
SQL_ATTR_CP_MATCH = 202
Expand Down Expand Up @@ -145,14 +186,15 @@ type (
SQLHSTMT SQLHANDLE
SQLHWND uintptr

SQLWCHAR uint16
SQLSCHAR int8
SQLSMALLINT int16
SQLUSMALLINT uint16
SQLINTEGER int32
SQLUINTEGER uint32
SQLPOINTER uintptr
SQLRETURN SQLSMALLINT
SQLWCHAR uint16
SQLSCHAR int8
SQLSMALLINT int16
SQLUSMALLINT uint16
SQLINTEGER int32
SQLUINTEGER uint32
SQLPOINTER uintptr
SQLRETURN SQLSMALLINT
SQLSETPOSIROW SQLUSMALLINT

SQLGUID struct {
Data1 uint32
Expand All @@ -163,24 +205,24 @@ type (
)

func SQLSetEnvUIntPtrAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) {
trc.Trace1("api/api_windows.go SQLSetEnvUIntPtrAttr() - ENTRY")
trc.Trace1("api/api_windows.go SQLSetEnvUIntPtrAttr() - ENTRY")
trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=0x%x, stringLength=%d", attribute, valuePtr, stringLength))

r0, _, _ := syscall.Syscall6(procSQLSetEnvAttr.Addr(), 4, uintptr(environmentHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength), 0, 0)
ret = SQLRETURN(r0)

trc.Trace1(fmt.Sprintf("ret = %d", ret))
trc.Trace1(fmt.Sprintf("ret = %d", ret))
trc.Trace1("api/api_windows.go SQLSetEnvUIntPtrAttr() - EXIT")
return
}

func SQLSetConnectUIntPtrAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) {
trc.Trace1("api/api_windows.go SQLSetConnectUIntPtrAttr() - ENTRY")
trc.Trace1("api/api_windows.go SQLSetConnectUIntPtrAttr() - ENTRY")
trc.Trace1(fmt.Sprintf("attribute=%d, valuePtr=%x, stringLength=%d", attribute, valuePtr, stringLength))

r0, _, _ := syscall.Syscall6(procSQLSetConnectAttrW.Addr(), 4, uintptr(connectionHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength), 0, 0)
ret = SQLRETURN(r0)

trc.Trace1(fmt.Sprintf("ret = %d", ret))
trc.Trace1("api/api_windows.go SQLSetConnectUIntPtrAttr() - EXIT")
return
Expand Down
13 changes: 6 additions & 7 deletions api/api_zos.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"log"
"runtime"
"unsafe"

"github.com/ibmruntimes/go-recordio/v2/utils"
trc "github.com/ibmdb/go_ibm_db/log2"
"fmt"
Expand Down Expand Up @@ -166,21 +165,21 @@ type (
)

func SQLSetEnvUIntPtrAttr(environmentHandle SQLHENV, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) {
trc.Trace1("api/api_zos.go SQLSetEnvUIntPtrAttr() - ENTRY")
trc.Trace1("api/api_zos.go SQLSetEnvUIntPtrAttr() - ENTRY")

r := utils.CfuncEbcdic(getFunc(&dll, "SQLSetEnvAttr"), uintptr(environmentHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength))

trc.Trace1(fmt.Sprintf("r = %d", r))
trc.Trace1("api/api_zos.go SQLSetEnvUIntPtrAttr() - EXIT")
return SQLRETURN(r)
}

func SQLSetConnectUIntPtrAttr(connectionHandle SQLHDBC, attribute SQLINTEGER, valuePtr uintptr, stringLength SQLINTEGER) (ret SQLRETURN) {
trc.Trace1("api/api_zos.go SQLSetConnectUIntPtrAttr() - ENTRY")
trc.Trace1("api/api_zos.go SQLSetConnectUIntPtrAttr() - ENTRY")

r := utils.CfuncEbcdic(getFunc(&dll, "SQLSetConnectAttr"), uintptr(connectionHandle), uintptr(attribute), uintptr(valuePtr), uintptr(stringLength))

trc.Trace1(fmt.Sprintf("r = %d", r))
trc.Trace1("api/api_zos.go SQLSetConnectUIntPtrAttr() - EXIT")
return SQLRETURN(r)
}
}
Loading

0 comments on commit c9ab3e6

Please sign in to comment.