From f9a9a7bc54ef318118b7ad3d7ad396110b2db0e6 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Thu, 4 Jun 2020 08:05:45 +0000 Subject: [PATCH] [TD-519] fix execute sql return --- src/connector/python/linux/python2/taos/cinterface.py | 1 + src/connector/python/linux/python2/taos/cursor.py | 3 ++- src/connector/python/linux/python3/taos/cinterface.py | 1 + src/connector/python/linux/python3/taos/cursor.py | 4 ++-- src/connector/python/windows/python2/taos/cinterface.py | 1 + src/connector/python/windows/python2/taos/cursor.py | 3 ++- src/connector/python/windows/python3/taos/cinterface.py | 1 + src/connector/python/windows/python3/taos/cursor.py | 3 ++- 8 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/connector/python/linux/python2/taos/cinterface.py b/src/connector/python/linux/python2/taos/cinterface.py index 758244b6d8..1b17bf72b0 100644 --- a/src/connector/python/linux/python2/taos/cinterface.py +++ b/src/connector/python/linux/python2/taos/cinterface.py @@ -149,6 +149,7 @@ class CTaosInterface(object): libtaos.taos_consume.restype = ctypes.c_void_p libtaos.taos_fetch_lengths.restype = ctypes.c_void_p libtaos.taos_free_result.restype = None + libtaos.taos_errno.restype = ctypes.c_int def __init__(self, config=None): ''' diff --git a/src/connector/python/linux/python2/taos/cursor.py b/src/connector/python/linux/python2/taos/cursor.py index 6bf8236ac9..75aa7f69d8 100644 --- a/src/connector/python/linux/python2/taos/cursor.py +++ b/src/connector/python/linux/python2/taos/cursor.py @@ -126,7 +126,8 @@ class TDengineCursor(object): with open(self._logfile, "a") as logfile: logfile.write("%s;\n" % operation) - if self._result is not None: + errno = CTaosInterface.libtaos.taos_errno(self._result) + if errno == 0: if CTaosInterface.fieldsCount(self._result) == 0: self._affected_rows += CTaosInterface.affectedRows( self._result ) diff --git a/src/connector/python/linux/python3/taos/cinterface.py b/src/connector/python/linux/python3/taos/cinterface.py index b953aa1192..87540bf326 100644 --- a/src/connector/python/linux/python3/taos/cinterface.py +++ b/src/connector/python/linux/python3/taos/cinterface.py @@ -149,6 +149,7 @@ class CTaosInterface(object): libtaos.taos_consume.restype = ctypes.c_void_p libtaos.taos_fetch_lengths.restype = ctypes.c_void_p libtaos.taos_free_result.restype = None + libtaos.taos_errno.restype = ctypes.c_int def __init__(self, config=None): ''' diff --git a/src/connector/python/linux/python3/taos/cursor.py b/src/connector/python/linux/python3/taos/cursor.py index 724cfe2163..3baca89462 100644 --- a/src/connector/python/linux/python3/taos/cursor.py +++ b/src/connector/python/linux/python3/taos/cursor.py @@ -124,12 +124,12 @@ class TDengineCursor(object): # print(" >> Exec Query ({}): {}".format(localSeqNum, str(stmt))) self._result = CTaosInterface.query(self._connection._conn, stmt) # print(" << Query ({}) Exec Done".format(localSeqNum)) - if (self._logfile): with open(self._logfile, "a") as logfile: logfile.write("%s;\n" % operation) - if self._result is not None: + errno = CTaosInterface.libtaos.taos_errno(self._result) + if errno == 0: if CTaosInterface.fieldsCount(self._result) == 0: self._affected_rows += CTaosInterface.affectedRows( self._result ) diff --git a/src/connector/python/windows/python2/taos/cinterface.py b/src/connector/python/windows/python2/taos/cinterface.py index e58ebbc8da..9fb7d4ec09 100644 --- a/src/connector/python/windows/python2/taos/cinterface.py +++ b/src/connector/python/windows/python2/taos/cinterface.py @@ -149,6 +149,7 @@ class CTaosInterface(object): libtaos.taos_consume.restype = ctypes.c_void_p libtaos.taos_fetch_lengths.restype = ctypes.c_void_p libtaos.taos_free_result.restype = None + libtaos.taos_errno.restype = ctypes.c_int def __init__(self, config=None): ''' diff --git a/src/connector/python/windows/python2/taos/cursor.py b/src/connector/python/windows/python2/taos/cursor.py index 0d7c882baf..6af82e72de 100644 --- a/src/connector/python/windows/python2/taos/cursor.py +++ b/src/connector/python/windows/python2/taos/cursor.py @@ -110,7 +110,8 @@ class TDengineCursor(object): pass self._result = CTaosInterface.query(self._connection._conn, stmt) - if self._result is not None: + errno = CTaosInterface.libtaos.taos_errno(self._result) + if errno == 0: if CTaosInterface.fieldsCount(self._result) == 0: self._affected_rows += CTaosInterface.affectedRows(self._result) return CTaosInterface.affectedRows(self._result ) diff --git a/src/connector/python/windows/python3/taos/cinterface.py b/src/connector/python/windows/python3/taos/cinterface.py index 2217ad5c58..0dbb2ce3a1 100644 --- a/src/connector/python/windows/python3/taos/cinterface.py +++ b/src/connector/python/windows/python3/taos/cinterface.py @@ -149,6 +149,7 @@ class CTaosInterface(object): libtaos.taos_consume.restype = ctypes.c_void_p libtaos.taos_fetch_lengths.restype = ctypes.c_void_p libtaos.taos_free_result.restype = None + libtaos.taos_errno.restype = ctypes.c_int def __init__(self, config=None): ''' diff --git a/src/connector/python/windows/python3/taos/cursor.py b/src/connector/python/windows/python3/taos/cursor.py index ebc549ec98..0ee8af4ed0 100644 --- a/src/connector/python/windows/python3/taos/cursor.py +++ b/src/connector/python/windows/python3/taos/cursor.py @@ -110,7 +110,8 @@ class TDengineCursor(object): pass self._result = CTaosInterface.query(self._connection._conn, stmt) - if self._result is not None: + errno = CTaosInterface.libtaos.taos_errno(self._result) + if errno == 0: if CTaosInterface.fieldsCount(self._result) == 0: self._affected_rows += CTaosInterface.affectedRows(self._result ) return CTaosInterface.affectedRows(self._result ) -- GitLab