See :ref:`query-parameters` for all the details about executing
queries.
+ Results from each query, if any, can be walked through by calling
+ `nextset()`.
+
.. automethod:: copy
:param statement: The copy operation to execute
- Add :ref:`Two-Phase Commit <two-phase-commit>` support (:ticket:`#72`).
- Add `pq.PGconn.trace()` and related trace functions (:ticket:`#167`).
+- Return results from all queries run through `~Cursor.executemany()`; each
+ result set can be accessed by calling `~Cursor.nextset()` (:ticket:`#164`).
Current release
def nextset(self) -> Optional[bool]:
"""
- Move to the next result set if `execute()` returned more than one.
+ Move to the result set of the next query executed through `executemany()`
+ or to the next result set if `execute()` returned more than one.
Return `!True` if a new result is available, which will be the one
methods `!fetch*()` will operate on.
results = yield from self._maybe_prepare_gen(pgq, prepare=True)
self._check_results(results)
+ self._results.extend(results)
for res in results:
nrows += res.command_tuples or 0
assert cur.rowcount == 2
-def test_executemany_returning_rowcount(conn, execmany):
+def test_executemany_returning(conn, execmany):
cur = conn.cursor()
cur.executemany(
"insert into execmany(num, data) values (%s, %s) returning num",
[(10, "hello"), (20, "world")],
)
assert cur.rowcount == 2
+ assert cur.fetchone() == (10,)
+ assert cur.nextset()
+ assert cur.fetchone() == (20,)
+ assert cur.nextset() is None
def test_executemany_rowcount_no_hit(conn, execmany):
assert cur.rowcount == 2
-async def test_executemany_returning_rowcount(aconn, execmany):
+async def test_executemany_returning(aconn, execmany):
cur = aconn.cursor()
await cur.executemany(
"insert into execmany(num, data) values (%s, %s) returning num",
[(10, "hello"), (20, "world")],
)
assert cur.rowcount == 2
+ assert (await cur.fetchone()) == (10,)
+ assert cur.nextset()
+ assert (await cur.fetchone()) == (20,)
+ assert cur.nextset() is None
async def test_executemany_rowcount_no_hit(aconn, execmany):