from typing import Any, Generic, Iterable, Iterator, List
from typing import Optional, NoReturn, Sequence, Tuple, Type, TypeVar
from typing import overload, TYPE_CHECKING
+from warnings import warn
from contextlib import contextmanager
from . import pq
Return `!True` if a new result is available, which will be the one
methods `!fetch*()` will operate on.
"""
+ # Raise a warning if people is calling nextset() in pipeline mode
+ # after a sequence of execute() in pipeline mode. Pipeline accumulating
+ # execute() results in the cursor is an unintended difference w.r.t.
+ # non-pipeline mode.
+ if self._execmany_returning is None and self._conn._pipeline:
+ warn(
+ "using nextset() in pipeline mode for several execute() is"
+ " deprecated and will be dropped in 3.2; please use different"
+ " cursors to receive more than one result",
+ DeprecationWarning,
+ )
+
if self._iresult < len(self._results) - 1:
self._select_current_result(self._iresult + 1)
return True
assert s == sum(values)
(after,) = conn.execute("select value from accessed").fetchone()
assert after > before
+
+
+def test_execute_nextset_warning(conn):
+ cur = conn.cursor()
+ cur.execute("select 1")
+ cur.execute("select 2")
+
+ assert cur.fetchall() == [(2,)]
+ assert not cur.nextset()
+ assert cur.fetchall() == []
+
+ with conn.pipeline():
+ cur.execute("select 1")
+ cur.execute("select 2")
+
+ # WARNING: this behavior is unintentional and will be changed in 3.2
+ assert cur.fetchall() == [(1,)]
+ with pytest.warns(DeprecationWarning, match="nextset"):
+ assert cur.nextset()
+ assert cur.fetchall() == [(2,)]
assert s == sum(values)
(after,) = await (await aconn.execute("select value from accessed")).fetchone()
assert after > before
+
+
+async def test_execute_nextset_warning(aconn):
+ cur = aconn.cursor()
+ await cur.execute("select 1")
+ await cur.execute("select 2")
+
+ assert (await cur.fetchall()) == [(2,)]
+ assert not cur.nextset()
+ assert (await cur.fetchall()) == []
+
+ async with aconn.pipeline():
+ await cur.execute("select 1")
+ await cur.execute("select 2")
+
+ # WARNING: this behavior is unintentional and will be changed in 3.2
+ assert (await cur.fetchall()) == [(1,)]
+ with pytest.warns(DeprecationWarning, match="nextset"):
+ assert cur.nextset()
+ assert (await cur.fetchall()) == [(2,)]