Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please pull to get my fixes for compile-time errors #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions odbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (conn *Connection) Close() *ODBCError {
}

func (stmt *Statement) RowsAffected() (int, *ODBCError) {
var nor C.SQLINTEGER
var nor C.SQLLEN
ret := C.SQLRowCount(C.SQLHSTMT(stmt.handle), &nor)
if !Success(ret) {
err := FormatError(C.SQL_HANDLE_STMT, stmt.handle, int(ret))
Expand Down Expand Up @@ -421,14 +421,14 @@ func (stmt *Statement) FetchOne() (*Row, *ODBCError) {
}

func (stmt *Statement) GetField(field_index int) (v interface{}, ftype int, flen int, err *ODBCError) {
var field_type C.int
var field_len C.int
var field_type C.SQLLEN
var field_len C.SQLLEN
var ll C.SQLSMALLINT
ret := C.SQLColAttribute(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_DESC_CONCISE_TYPE, C.SQLPOINTER(unsafe.Pointer(uintptr(0))), C.SQLSMALLINT(0), &ll, C.SQLPOINTER(unsafe.Pointer(&field_type)))
ret := C.SQLColAttribute(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_DESC_CONCISE_TYPE, C.SQLPOINTER(unsafe.Pointer(uintptr(0))), C.SQLSMALLINT(0), &ll, &field_type)
if !Success(ret) {
debugPrint("GetFiled type Error")
}
ret = C.SQLColAttribute(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_DESC_LENGTH, C.SQLPOINTER(unsafe.Pointer(uintptr(0))), C.SQLSMALLINT(0), &ll, C.SQLPOINTER(unsafe.Pointer(&field_len)))
ret = C.SQLColAttribute(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_DESC_LENGTH, C.SQLPOINTER(unsafe.Pointer(uintptr(0))), C.SQLSMALLINT(0), &ll, &field_len)
if !Success(ret) {
debugPrint("GetFiled len Error")
}
Expand All @@ -452,12 +452,12 @@ func (stmt *Statement) GetField(field_index int) (v interface{}, ftype int, flen
}
case C.SQL_WCHAR, C.SQL_WVARCHAR, C.SQL_WLONGVARCHAR:
value := make([]uint16, int(field_len)+8)
ret = C.SQLGetData(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_C_WCHAR, C.SQLPOINTER(unsafe.Pointer(&value[0])), C.SQLINTEGER(int(field_len)+4), &fl)
ret = C.SQLGetData(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_C_WCHAR, C.SQLPOINTER(unsafe.Pointer(&value[0])), C.SQLLEN(int(field_len)+4), &fl)
s := UTF16ToString(value)
v = s
default:
value := make([]byte, int(fl)+2)
ret = C.SQLGetData(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_C_CHAR, C.SQLPOINTER(unsafe.Pointer(&value[0])), C.SQLINTEGER(int(field_len)+4), &fl)
ret = C.SQLGetData(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_C_CHAR, C.SQLPOINTER(unsafe.Pointer(&value[0])), C.SQLLEN(int(field_len)+4), &fl)
s := string(value[0:])
v = s
debugPrint("default type", value, fl, s)
Expand Down Expand Up @@ -554,14 +554,14 @@ func (stmt *Statement) BindParam(index int, param interface{}) *ODBCError {
StrLen_or_IndPt = 0
case reflect.Complex64, reflect.Complex128:
case reflect.String:
var slen C.SQLUINTEGER = C.SQLUINTEGER(len(v.String()))
var slen C.SQLULEN = C.SQLULEN(len(v.String()))
ParameterType = C.SQL_VARCHAR
ValueType = C.SQL_C_CHAR
s := []byte(v.String())
ParameterValuePtr = C.SQLPOINTER(unsafe.Pointer(&s[0]))
ColumnSize = slen
BufferLength = C.SQLINTEGER(slen + 1)
StrLen_or_IndPt = C.SQLINTEGER(slen)
BufferLength = C.SQLLEN(slen + 1)
StrLen_or_IndPt = C.SQLLEN(slen)
default:
debugPrint("Not support type", v)
}
Expand Down