@@ -18,12 +18,29 @@ package odbc
1818#include <sqlext.h>
1919#include <sqltypes.h>
2020
21+ SQLRETURN _SQLColAttribute (
22+ SQLHSTMT StatementHandle,
23+ SQLUSMALLINT ColumnNumber,
24+ SQLUSMALLINT FieldIdentifier,
25+ SQLPOINTER CharacterAttributePtr,
26+ SQLSMALLINT BufferLength,
27+ SQLSMALLINT * StringLengthPtr,
28+ void * NumericAttributePtr) {
29+ return SQLColAttribute(StatementHandle,
30+ ColumnNumber,
31+ FieldIdentifier,
32+ CharacterAttributePtr,
33+ BufferLength,
34+ StringLengthPtr,
35+ NumericAttributePtr);
36+ }
37+
2138*/
2239import "C"
2340import (
24- "unsafe"
2541 "fmt"
2642 "reflect"
43+ "unsafe"
2744)
2845
2946const (
@@ -265,7 +282,7 @@ func (conn *Connection) Close() *ODBCError {
265282}
266283
267284func (stmt * Statement ) RowsAffected () (int , * ODBCError ) {
268- var nor C.SQLINTEGER
285+ var nor C.SQLLEN
269286 ret := C .SQLRowCount (C .SQLHSTMT (stmt .handle ), & nor )
270287 if ! Success (ret ) {
271288 err := FormatError (C .SQL_HANDLE_STMT , stmt .handle , int (ret ))
@@ -369,16 +386,6 @@ func (r *Row) GetFloat(a interface{}) (ret float64) {
369386 return
370387}
371388
372- func (r * Row ) GetComplex64 (a interface {}) (ret complex64 ) {
373- v := r .Get (a )
374- value := reflect .ValueOf (v )
375- switch f := value ; f .Kind () {
376- case reflect .Complex64 , reflect .Complex128 :
377- ret = complex64 (f .Complex ())
378- }
379- return
380- }
381-
382389func (r * Row ) GetString (a interface {}) (ret string ) {
383390 v := r .Get (a )
384391 value := reflect .ValueOf (v )
@@ -422,13 +429,13 @@ func (stmt *Statement) FetchOne() (*Row, *ODBCError) {
422429
423430func (stmt * Statement ) GetField (field_index int ) (v interface {}, ftype int , flen int , err * ODBCError ) {
424431 var field_type C.int
425- var field_len C.int
432+ var field_len C.SQLLEN
426433 var ll C.SQLSMALLINT
427- 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 ) ))
434+ 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 , unsafe .Pointer (& field_type ))
428435 if ! Success (ret ) {
429436 debugPrint ("GetFiled type Error" )
430437 }
431- 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 ) ))
438+ 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 , unsafe .Pointer (& field_len ))
432439 if ! Success (ret ) {
433440 debugPrint ("GetFiled len Error" )
434441 }
@@ -452,12 +459,12 @@ func (stmt *Statement) GetField(field_index int) (v interface{}, ftype int, flen
452459 }
453460 case C .SQL_WCHAR , C .SQL_WVARCHAR , C .SQL_WLONGVARCHAR :
454461 value := make ([]uint16 , int (field_len )+ 8 )
455- 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 )
462+ ret = C .SQLGetData (C .SQLHSTMT (stmt .handle ), C .SQLUSMALLINT (field_index + 1 ), C .SQL_C_WCHAR , C .SQLPOINTER (unsafe .Pointer (& value [0 ])), field_len + 4 , & fl )
456463 s := UTF16ToString (value )
457464 v = s
458465 default :
459466 value := make ([]byte , int (fl )+ 2 )
460- 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 )
467+ ret = C .SQLGetData (C .SQLHSTMT (stmt .handle ), C .SQLUSMALLINT (field_index + 1 ), C .SQL_C_CHAR , C .SQLPOINTER (unsafe .Pointer (& value [0 ])), field_len + 4 , & fl )
461468 s := string (value [0 :])
462469 v = s
463470 debugPrint ("default type" , value , fl , s )
@@ -559,9 +566,9 @@ func (stmt *Statement) BindParam(index int, param interface{}) *ODBCError {
559566 ValueType = C .SQL_C_CHAR
560567 s := []byte (v .String ())
561568 ParameterValuePtr = C .SQLPOINTER (unsafe .Pointer (& s [0 ]))
562- ColumnSize = slen
563- BufferLength = C .SQLINTEGER (slen + 1 )
564- StrLen_or_IndPt = C .SQLINTEGER (slen )
569+ ColumnSize = C . SQLULEN ( slen )
570+ BufferLength = C .SQLLEN (slen + 1 )
571+ StrLen_or_IndPt = C .SQLLEN (slen )
565572 default :
566573 debugPrint ("Not support type" , v )
567574 }
0 commit comments