Merge branch 'bug-633'

This commit is contained in:
Daniele Varrazzo 2017-11-29 15:42:29 +00:00
commit f4aa40da09
3 changed files with 19 additions and 2 deletions

4
NEWS
View File

@ -13,10 +13,12 @@ What's new in psycopg 2.7.4
^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed Solaris 10 support (:ticket:`#532`).
- Fixed `!MinTimeLoggingCursor` on Python 3 (:ticket:`#609`).
- Fixed `~psycopg2.extras.MinTimeLoggingCursor` on Python 3 (:ticket:`#609`).
- Fixed parsing of array of points as floats (:ticket:`#613`).
- Fixed `~psycopg2.__libpq_version__` building with libpq >= 10.1
(:ticket:`632`).
- Fixed `~cursor.rowcount` after `~cursor.executemany()` with :sql:`RETURNING` statements
(:ticket:`633`).
- Wheel packages compiled against PostgreSQL 10.1 libpq and OpenSSL 1.0.2m.

View File

@ -1952,8 +1952,9 @@ pq_fetch(cursorObject *curs, int no_result)
}
else {
Dprintf("pq_fetch: got tuples, discarding them");
/* TODO: is there any case in which PQntuples == PQcmdTuples? */
_read_rowcount(curs);
CLEARPGRES(curs->pgres);
curs->rowcount = -1;
ex = 0;
}
break;

View File

@ -583,6 +583,20 @@ class CursorTests(ConnectingTestCase):
self.assertEqual(victim_conn.closed, 2)
@skip_before_postgres(8, 2)
def test_rowcount_on_executemany_returning(self):
cur = self.conn.cursor()
cur.execute("create table execmany(id serial primary key, data int)")
cur.executemany(
"insert into execmany (data) values (%s)",
[(i,) for i in range(4)])
self.assertEqual(cur.rowcount, 4)
cur.executemany(
"insert into execmany (data) values (%s) returning data",
[(i,) for i in range(5)])
self.assertEqual(cur.rowcount, 5)
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)