Skip to content

Commit fe5031e

Browse files
committed
update to go tip
1 parent 514210d commit fe5031e

File tree

6 files changed

+36
-49
lines changed

6 files changed

+36
-49
lines changed

Makefile

Lines changed: 0 additions & 23 deletions
This file was deleted.

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package odbc
5+
package odbc

make.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
export CGO_LDFLAGS=-lodbc
4+
go install

make.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set CGO_LDFLAGS=-lodbc32
2+
go install

odbc.go

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
2239
import "C"
2340
import (
24-
"unsafe"
2541
"fmt"
2642
"reflect"
43+
"unsafe"
2744
)
2845

2946
const (
@@ -265,7 +282,7 @@ func (conn *Connection) Close() *ODBCError {
265282
}
266283

267284
func (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-
382389
func (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

423430
func (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
}

util.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package odbc
22

33
import (
4-
"utf16"
4+
"unicode/utf16"
55
)
66

7-
// Follow code get from Go's syscall/syscall_windows.go.
8-
97
// StringToUTF16 returns the UTF-16 encoding of the UTF-8 string s,
108
// with a terminating NUL added.
11-
func StringToUTF16(s string) []uint16 { return utf16.Encode([]int(s + "\x00")) }
9+
func StringToUTF16(s string) []uint16 { return utf16.Encode([]rune(s + "\x00")) }
1210

1311
// UTF16ToString returns the UTF-8 encoding of the UTF-16 sequence s,
1412
// with a terminating NUL removed.
@@ -25,4 +23,3 @@ func UTF16ToString(s []uint16) string {
2523
// StringToUTF16Ptr returns pointer to the UTF-16 encoding of
2624
// the UTF-8 string s, with a terminating NUL added.
2725
func StringToUTF16Ptr(s string) *uint16 { return &StringToUTF16(s)[0] }
28-

0 commit comments

Comments
 (0)