"client-side cursors don't support binary results"
)
- if no_pqexec:
- raise e.NotSupportedError(
- "PQexec operations not supported by client-side cursors"
- )
-
self._query = query
- # if we don't have to, let's use exec_ as it can run more than
- # one query in one go
- if self._conn._pipeline:
- self._conn._pipeline.command_queue.append(
- partial(self._pgconn.send_query, query.query)
- )
+ if no_pqexec:
+ if self._conn._pipeline:
+ self._conn._pipeline.command_queue.append(
+ partial(self._pgconn.send_query_params, None)
+ )
+ else:
+ self._pgconn.send_query_params(query.query, None)
else:
- self._pgconn.send_query(query.query)
+ # if we don't have to, let's use exec_ as it can run more than
+ # one query in one go
+ if self._conn._pipeline:
+ self._conn._pipeline.command_queue.append(
+ partial(self._pgconn.send_query, query.query)
+ )
+ else:
+ self._pgconn.send_query(query.query)
def _convert_query(
self, query: Query, params: Optional[Params] = None
) -> Tuple[Prepare, bytes]:
return (Prepare.NO, b"")
- def _is_pipeline_supported(self) -> bool:
- return False
-
class ClientCursor(ClientCursorMixin["Connection[Row]", Row], Cursor[Row]):
pass
Execute the same command with a sequence of input data.
"""
try:
- if self._is_pipeline_supported():
+ if Pipeline.is_supported():
# If there is already a pipeline, ride it, in order to avoid
# sending unnecessary Sync.
with self._conn.lock:
except e.Error as ex:
raise ex.with_traceback(None)
- def _is_pipeline_supported(self) -> bool:
- return Pipeline.is_supported()
-
def stream(
self,
query: Query,
def test_stream(conn):
cur = conn.cursor()
- with pytest.raises(psycopg.NotSupportedError):
- for rec in cur.stream(
- "select i, '2021-01-01'::date + i from generate_series(1, %s) as i",
- [2],
- ):
- pass
+ recs = []
+ for rec in cur.stream(
+ "select i, '2021-01-01'::date + i from generate_series(1, %s) as i",
+ [2],
+ ):
+ recs.append(rec)
+
+ assert recs == [(1, dt.date(2021, 1, 2)), (2, dt.date(2021, 1, 3))]
class TestColumn:
async def test_stream(aconn):
cur = aconn.cursor()
- with pytest.raises(psycopg.NotSupportedError):
- async for rec in cur.stream(
- "select i, '2021-01-01'::date + i from generate_series(1, %s) as i",
- [2],
- ):
- pass
+ recs = []
+ async for rec in cur.stream(
+ "select i, '2021-01-01'::date + i from generate_series(1, %s) as i",
+ [2],
+ ):
+ recs.append(rec)
+
+ assert recs == [(1, dt.date(2021, 1, 2)), (2, dt.date(2021, 1, 3))]
async def test_str(aconn):