[TBASE-1047] Go connector prints all the SQL. This will harm the performance and consume unnecessary hard disk space. Modified to print only the SQLs which returns error.
This commit is contained in:
parent
fcc308fb40
commit
db26cf1e8e
|
@ -29,46 +29,47 @@ import (
|
|||
"unsafe"
|
||||
)
|
||||
|
||||
func (mc *taosConn) taosConnect(ip, user, pass, db string, port int) (taos unsafe.Pointer, err error){
|
||||
func (mc *taosConn) taosConnect(ip, user, pass, db string, port int) (taos unsafe.Pointer, err error) {
|
||||
cuser := C.CString(user)
|
||||
cpass := C.CString(pass)
|
||||
cip := C.CString(ip)
|
||||
cdb := C.CString(db)
|
||||
cip := C.CString(ip)
|
||||
cdb := C.CString(db)
|
||||
defer C.free(unsafe.Pointer(cip))
|
||||
defer C.free(unsafe.Pointer(cuser))
|
||||
defer C.free(unsafe.Pointer(cpass))
|
||||
defer C.free(unsafe.Pointer(cdb))
|
||||
|
||||
taosObj := C.taos_connect(cip, cuser, cpass, cdb, (C.int)(port))
|
||||
if taosObj == nil {
|
||||
return nil, errors.New("taos_connect() fail!")
|
||||
}
|
||||
if taosObj == nil {
|
||||
return nil, errors.New("taos_connect() fail!")
|
||||
}
|
||||
|
||||
return (unsafe.Pointer)(taosObj), nil
|
||||
}
|
||||
return (unsafe.Pointer)(taosObj), nil
|
||||
}
|
||||
|
||||
func (mc *taosConn) taosQuery(sqlstr string) (int, error) {
|
||||
taosLog.Printf("taosQuery() input sql:%s\n", sqlstr)
|
||||
//taosLog.Printf("taosQuery() input sql:%s\n", sqlstr)
|
||||
|
||||
csqlstr := C.CString(sqlstr)
|
||||
csqlstr := C.CString(sqlstr)
|
||||
defer C.free(unsafe.Pointer(csqlstr))
|
||||
code := int(C.taos_query(mc.taos, csqlstr))
|
||||
code := int(C.taos_query(mc.taos, csqlstr))
|
||||
|
||||
if 0 != code {
|
||||
mc.taos_error()
|
||||
errStr := C.GoString(C.taos_errstr(mc.taos))
|
||||
taosLog.Println("taos_query() failed:", errStr)
|
||||
return 0, errors.New(errStr)
|
||||
}
|
||||
if 0 != code {
|
||||
mc.taos_error()
|
||||
errStr := C.GoString(C.taos_errstr(mc.taos))
|
||||
taosLog.Println("taos_query() failed:", errStr)
|
||||
taosLog.Printf("taosQuery() input sql:%s\n", sqlstr)
|
||||
return 0, errors.New(errStr)
|
||||
}
|
||||
|
||||
// read result and save into mc struct
|
||||
num_fields := int(C.taos_field_count(mc.taos))
|
||||
if 0 == num_fields { // there are no select and show kinds of commands
|
||||
mc.affectedRows = int(C.taos_affected_rows(mc.taos))
|
||||
mc.insertId = 0
|
||||
}
|
||||
// read result and save into mc struct
|
||||
num_fields := int(C.taos_field_count(mc.taos))
|
||||
if 0 == num_fields { // there are no select and show kinds of commands
|
||||
mc.affectedRows = int(C.taos_affected_rows(mc.taos))
|
||||
mc.insertId = 0
|
||||
}
|
||||
|
||||
return num_fields, nil
|
||||
return num_fields, nil
|
||||
}
|
||||
|
||||
func (mc *taosConn) taos_close() {
|
||||
|
@ -76,8 +77,8 @@ func (mc *taosConn) taos_close() {
|
|||
}
|
||||
|
||||
func (mc *taosConn) taos_error() {
|
||||
// free local resouce: allocated memory/metric-meta refcnt
|
||||
//var pRes unsafe.Pointer
|
||||
pRes := C.taos_use_result(mc.taos)
|
||||
C.taos_free_result(pRes)
|
||||
// free local resouce: allocated memory/metric-meta refcnt
|
||||
//var pRes unsafe.Pointer
|
||||
pRes := C.taos_use_result(mc.taos)
|
||||
C.taos_free_result(pRes)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue