From 7148743eefcc1eb6699b6b64834d158f14f12235 Mon Sep 17 00:00:00 2001 From: localvar Date: Sat, 21 Dec 2019 09:14:01 +0800 Subject: [PATCH] fix tbase-1381 --- src/connector/go/src/taosSql/result.go | 39 +++++++++++++------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/connector/go/src/taosSql/result.go b/src/connector/go/src/taosSql/result.go index e6b0adcac7..2367560c31 100755 --- a/src/connector/go/src/taosSql/result.go +++ b/src/connector/go/src/taosSql/result.go @@ -25,13 +25,13 @@ package taosSql import "C" import ( - "database/sql/driver" + "database/sql/driver" "errors" - "strconv" - "unsafe" "fmt" "io" + "strconv" "time" + "unsafe" ) /****************************************************************************** @@ -41,10 +41,10 @@ import ( func (mc *taosConn) readColumns(count int) ([]taosSqlField, error) { columns := make([]taosSqlField, count) - var result unsafe.Pointer + var result unsafe.Pointer result = C.taos_use_result(mc.taos) if result == nil { - return nil , errors.New("invalid result") + return nil, errors.New("invalid 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 !!!! fields := (*[1 << 30]C.struct_taosField)(unsafe.Pointer(pFields)) - for i := 0; i int of C + dest[i] = (int)(*((*int32)(currentRow))) // notes int32 of go <----> int of C break case C.TSDB_DATA_TYPE_BIGINT: @@ -142,7 +143,7 @@ func (rows *taosSqlRows) readRow(dest []driver.Value) error { charLen := rows.rs.columns[i].length var index uint32 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)))) } dest[i] = string(binaryVal[:]) @@ -152,7 +153,7 @@ func (rows *taosSqlRows) readRow(dest []driver.Value) error { if mc.cfg.parseTime == true { timestamp := (int64)(*((*int64)(currentRow))) dest[i] = timestampConvertToString(timestamp, int(C.taos_result_precision(result))) - }else { + } else { dest[i] = (int64)(*((*int64)(currentRow))) } break @@ -182,12 +183,12 @@ func timestampConvertToString(timestamp int64, precision int) string { var decimal, sVal, nsVal int64 if precision == 0 { decimal = timestamp % 1000 - sVal = timestamp / 1000 - nsVal = decimal * 1000 + sVal = timestamp / 1000 + nsVal = decimal * 1000 } else { decimal = timestamp % 1000000 - sVal = timestamp / 1000000 - nsVal = decimal * 1000000 + sVal = timestamp / 1000000 + nsVal = decimal * 1000000 } date_time := time.Unix(sVal, nsVal) -- GitLab