From 4bcb26a752ad077501b13ab305508c809960ad86 Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 14 Aug 2019 19:37:33 +0800 Subject: [PATCH] fix the problem that affectRows in python is incorrect --- src/connector/python/linux/python2/taos/cursor.py | 11 ++++++++++- src/connector/python/linux/python3/taos/cursor.py | 11 ++++++++++- src/connector/python/windows/python2/taos/cursor.py | 13 +++++++++++-- src/connector/python/windows/python3/taos/cursor.py | 11 ++++++++++- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/connector/python/linux/python2/taos/cursor.py b/src/connector/python/linux/python2/taos/cursor.py index 933efbde22..f18920c553 100644 --- a/src/connector/python/linux/python2/taos/cursor.py +++ b/src/connector/python/linux/python2/taos/cursor.py @@ -31,6 +31,7 @@ class TDengineCursor(object): self._block = None self._block_rows = -1 self._block_iter = 0 + self._affected_rows = 0 if connection is not None: self._connection = connection @@ -66,6 +67,12 @@ class TDengineCursor(object): """ return self._rowcount + @property + def affected_rows(self): + """Return the affected_rows of the object + """ + return self._affected_rows + def callproc(self, procname, *args): """Call a stored database procedure with the given name. @@ -105,6 +112,7 @@ class TDengineCursor(object): res = CTaosInterface.query(self._connection._conn, stmt) if res == 0: if CTaosInterface.fieldsCount(self._connection._conn) == 0: + self._affected_rows += CTaosInterface.affectedRows(self._connection._conn) return CTaosInterface.affectedRows(self._connection._conn) else: self._result, self._fields = CTaosInterface.useResult(self._connection._conn) @@ -167,6 +175,7 @@ class TDengineCursor(object): self._block = None self._block_rows = -1 self._block_iter = 0 + self._affected_rows = 0 def _handle_result(self): """Handle the return result from query. @@ -175,4 +184,4 @@ class TDengineCursor(object): for ele in self._fields: self._description.append((ele['name'], ele['type'], None, None, None, None, False)) - return self._result \ No newline at end of file + return self._result diff --git a/src/connector/python/linux/python3/taos/cursor.py b/src/connector/python/linux/python3/taos/cursor.py index 656a348472..7a0ae767bc 100644 --- a/src/connector/python/linux/python3/taos/cursor.py +++ b/src/connector/python/linux/python3/taos/cursor.py @@ -31,6 +31,7 @@ class TDengineCursor(object): self._block = None self._block_rows = -1 self._block_iter = 0 + self._affected_rows = 0 if connection is not None: self._connection = connection @@ -66,6 +67,12 @@ class TDengineCursor(object): """ return self._rowcount + @property + def affected_rows(self): + """Return the rowcount of insertion + """ + return self._affected_rows + def callproc(self, procname, *args): """Call a stored database procedure with the given name. @@ -105,6 +112,7 @@ class TDengineCursor(object): res = CTaosInterface.query(self._connection._conn, stmt) if res == 0: if CTaosInterface.fieldsCount(self._connection._conn) == 0: + self._affected_rows += CTaosInterface.affectedRows(self._connection._conn) return CTaosInterface.affectedRows(self._connection._conn) else: self._result, self._fields = CTaosInterface.useResult(self._connection._conn) @@ -167,6 +175,7 @@ class TDengineCursor(object): self._block = None self._block_rows = -1 self._block_iter = 0 + self._affected_rows = 0 def _handle_result(self): """Handle the return result from query. @@ -175,4 +184,4 @@ class TDengineCursor(object): for ele in self._fields: self._description.append((ele['name'], ele['type'], None, None, None, None, False)) - return self._result \ No newline at end of file + return self._result diff --git a/src/connector/python/windows/python2/taos/cursor.py b/src/connector/python/windows/python2/taos/cursor.py index 933efbde22..976ec06707 100644 --- a/src/connector/python/windows/python2/taos/cursor.py +++ b/src/connector/python/windows/python2/taos/cursor.py @@ -31,6 +31,7 @@ class TDengineCursor(object): self._block = None self._block_rows = -1 self._block_iter = 0 + self._affected_rows = 0 if connection is not None: self._connection = connection @@ -66,6 +67,12 @@ class TDengineCursor(object): """ return self._rowcount + @property + def affected_rows(self): + """Return the affected_rows of the object + """ + return self._affected_rows + def callproc(self, procname, *args): """Call a stored database procedure with the given name. @@ -105,6 +112,7 @@ class TDengineCursor(object): res = CTaosInterface.query(self._connection._conn, stmt) if res == 0: if CTaosInterface.fieldsCount(self._connection._conn) == 0: + self._affected_rows += CTaosInterface.affectedRows(self._connection._conn) return CTaosInterface.affectedRows(self._connection._conn) else: self._result, self._fields = CTaosInterface.useResult(self._connection._conn) @@ -167,7 +175,8 @@ class TDengineCursor(object): self._block = None self._block_rows = -1 self._block_iter = 0 - + self._affected_rows = 0 + def _handle_result(self): """Handle the return result from query. """ @@ -175,4 +184,4 @@ class TDengineCursor(object): for ele in self._fields: self._description.append((ele['name'], ele['type'], None, None, None, None, False)) - return self._result \ No newline at end of file + return self._result diff --git a/src/connector/python/windows/python3/taos/cursor.py b/src/connector/python/windows/python3/taos/cursor.py index ac70c37958..c7f3400642 100644 --- a/src/connector/python/windows/python3/taos/cursor.py +++ b/src/connector/python/windows/python3/taos/cursor.py @@ -31,6 +31,7 @@ class TDengineCursor(object): self._block = None self._block_rows = -1 self._block_iter = 0 + self._affected_rows = 0 if connection is not None: self._connection = connection @@ -66,6 +67,12 @@ class TDengineCursor(object): """ return self._rowcount + @property + def affected_rows(self): + """Return the affected_rows of the object + """ + return self._affected_rows + def callproc(self, procname, *args): """Call a stored database procedure with the given name. @@ -105,6 +112,7 @@ class TDengineCursor(object): res = CTaosInterface.query(self._connection._conn, stmt) if res == 0: if CTaosInterface.fieldsCount(self._connection._conn) == 0: + self._affected_rows += CTaosInterface.affectedRows(self._connection._conn) return CTaosInterface.affectedRows(self._connection._conn) else: self._result, self._fields = CTaosInterface.useResult(self._connection._conn) @@ -167,6 +175,7 @@ class TDengineCursor(object): self._block = None self._block_rows = -1 self._block_iter = 0 + self._affected_rows = 0 def _handle_result(self): """Handle the return result from query. @@ -175,4 +184,4 @@ class TDengineCursor(object): for ele in self._fields: self._description.append((ele['name'], ele['type'], None, None, None, None, False)) - return self._result \ No newline at end of file + return self._result -- GitLab