]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: fix Cursor.rowcount after non-SELECT tuple-returining queries
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 28 Jul 2022 09:34:57 +0000 (11:34 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 28 Jul 2022 09:42:54 +0000 (11:42 +0200)
PQcmdTuples doesn't return a value after SHOW and other type of queries.

Close #343

docs/news.rst
psycopg/psycopg/cursor.py

index 7952c74a66cc6e016672263bf43705709dfc3c1b..234c5c8707513d7c55b61ca6a376189c7f4b7c0d 100644 (file)
@@ -37,6 +37,12 @@ Psycopg 3.1 (unreleased)
 - Drop support for Python 3.6.
 
 
+Psycopg 3.0.16 (unreleased)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Fix missing `~Cursor.rowcount` after SHOW (:ticket:`#343`).
+
+
 Current release
 ---------------
 
index 5653f07c9863a972ba5ffcaa95cbd7986e42175d..b9875a315d4d2ccce3a9416d7a7b26ff0bdc1d18 100644 (file)
@@ -530,10 +530,13 @@ class BaseCursor(Generic[ConnectionType, Row]):
 
         self._pos = 0
 
+        if res.status == TUPLES_OK:
+            self._rowcount = self.pgresult.ntuples
+
         # COPY_OUT has never info about nrows. We need such result for the
         # columns in order to return a `description`, but not overwrite the
         # cursor rowcount (which was set by the Copy object).
-        if res.status != COPY_OUT:
+        elif res.status != COPY_OUT:
             nrows = self.pgresult.command_tuples
             self._rowcount = nrows if nrows is not None else -1