commit
a6c2214440
|
@ -27,11 +27,11 @@ import "C"
|
||||||
import (
|
import (
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
|
||||||
"unsafe"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
@ -44,7 +44,7 @@ func (mc *taosConn) readColumns(count int) ([]taosSqlField, error) {
|
||||||
var result unsafe.Pointer
|
var result unsafe.Pointer
|
||||||
result = C.taos_use_result(mc.taos)
|
result = C.taos_use_result(mc.taos)
|
||||||
if result == nil {
|
if result == nil {
|
||||||
return nil , errors.New("invalid result")
|
return nil, errors.New("invalid result")
|
||||||
}
|
}
|
||||||
|
|
||||||
pFields := (*C.struct_taosField)(C.taos_fetch_fields(result))
|
pFields := (*C.struct_taosField)(C.taos_fetch_fields(result))
|
||||||
|
@ -52,7 +52,7 @@ func (mc *taosConn) readColumns(count int) ([]taosSqlField, error) {
|
||||||
// TODO: Optimized rewriting !!!!
|
// TODO: Optimized rewriting !!!!
|
||||||
fields := (*[1 << 30]C.struct_taosField)(unsafe.Pointer(pFields))
|
fields := (*[1 << 30]C.struct_taosField)(unsafe.Pointer(pFields))
|
||||||
|
|
||||||
for i := 0; i<count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
//columns[i].tableName = ms.taos.
|
//columns[i].tableName = ms.taos.
|
||||||
//fmt.Println(reflect.TypeOf(fields[i].name))
|
//fmt.Println(reflect.TypeOf(fields[i].name))
|
||||||
var charray []byte
|
var charray []byte
|
||||||
|
@ -60,7 +60,7 @@ func (mc *taosConn) readColumns(count int) ([]taosSqlField, error) {
|
||||||
//fmt.Println("fields[i].name[j]: ", fields[i].name[j])
|
//fmt.Println("fields[i].name[j]: ", fields[i].name[j])
|
||||||
if fields[i].name[j] != 0 {
|
if fields[i].name[j] != 0 {
|
||||||
charray = append(charray, byte(fields[i].name[j]))
|
charray = append(charray, byte(fields[i].name[j]))
|
||||||
}else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,7 @@ func (rows *taosSqlRows) readRow(dest []driver.Value) error {
|
||||||
row := C.taos_fetch_row(result)
|
row := C.taos_fetch_row(result)
|
||||||
if row == nil {
|
if row == nil {
|
||||||
rows.rs.done = true
|
rows.rs.done = true
|
||||||
|
C.taos_free_result(result)
|
||||||
rows.mc = nil
|
rows.mc = nil
|
||||||
return io.EOF
|
return io.EOF
|
||||||
}
|
}
|
||||||
|
@ -98,7 +99,7 @@ func (rows *taosSqlRows) readRow(dest []driver.Value) error {
|
||||||
// because sizeof(void*) == sizeof(int*) == 8
|
// because sizeof(void*) == sizeof(int*) == 8
|
||||||
// notes: sizeof(int) == 8 in go, but sizeof(int) == 4 in C.
|
// notes: sizeof(int) == 8 in go, but sizeof(int) == 4 in C.
|
||||||
for i := range dest {
|
for i := range dest {
|
||||||
currentRow := (unsafe.Pointer)(uintptr(*((*int)(unsafe.Pointer(uintptr(unsafe.Pointer(row)) + uintptr(i) * unsafe.Sizeof(int(0)))))))
|
currentRow := (unsafe.Pointer)(uintptr(*((*int)(unsafe.Pointer(uintptr(unsafe.Pointer(row)) + uintptr(i)*unsafe.Sizeof(int(0)))))))
|
||||||
|
|
||||||
if currentRow == nil {
|
if currentRow == nil {
|
||||||
dest[i] = nil
|
dest[i] = nil
|
||||||
|
@ -107,7 +108,7 @@ func (rows *taosSqlRows) readRow(dest []driver.Value) error {
|
||||||
|
|
||||||
switch rows.rs.columns[i].fieldType {
|
switch rows.rs.columns[i].fieldType {
|
||||||
case C.TSDB_DATA_TYPE_BOOL:
|
case C.TSDB_DATA_TYPE_BOOL:
|
||||||
if (*((*byte)(currentRow))) != 0{
|
if (*((*byte)(currentRow))) != 0 {
|
||||||
dest[i] = true
|
dest[i] = true
|
||||||
} else {
|
} else {
|
||||||
dest[i] = false
|
dest[i] = false
|
||||||
|
@ -142,7 +143,7 @@ func (rows *taosSqlRows) readRow(dest []driver.Value) error {
|
||||||
charLen := rows.rs.columns[i].length
|
charLen := rows.rs.columns[i].length
|
||||||
var index uint32
|
var index uint32
|
||||||
binaryVal := make([]byte, charLen)
|
binaryVal := make([]byte, charLen)
|
||||||
for index=0; index < charLen; index++ {
|
for index = 0; index < charLen; index++ {
|
||||||
binaryVal[index] = *((*byte)(unsafe.Pointer(uintptr(currentRow) + uintptr(index))))
|
binaryVal[index] = *((*byte)(unsafe.Pointer(uintptr(currentRow) + uintptr(index))))
|
||||||
}
|
}
|
||||||
dest[i] = string(binaryVal[:])
|
dest[i] = string(binaryVal[:])
|
||||||
|
@ -152,7 +153,7 @@ func (rows *taosSqlRows) readRow(dest []driver.Value) error {
|
||||||
if mc.cfg.parseTime == true {
|
if mc.cfg.parseTime == true {
|
||||||
timestamp := (int64)(*((*int64)(currentRow)))
|
timestamp := (int64)(*((*int64)(currentRow)))
|
||||||
dest[i] = timestampConvertToString(timestamp, int(C.taos_result_precision(result)))
|
dest[i] = timestampConvertToString(timestamp, int(C.taos_result_precision(result)))
|
||||||
}else {
|
} else {
|
||||||
dest[i] = (int64)(*((*int64)(currentRow)))
|
dest[i] = (int64)(*((*int64)(currentRow)))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue