Error recovery is reported to be problematic (see #78).
Close #82.
yield from self._start_query()
query = self._convert_query(statement)
- # Make sure to avoid PQexec to avoid receiving a mix of COPY and
- # other operations.
- self._execute_send(query, no_pqexec=True)
- (result,) = yield from execute(self._conn.pgconn)
+ self._execute_send(query, binary=False)
+ results = yield from execute(self._conn.pgconn)
+ if len(results) != 1:
+ raise e.ProgrammingError(
+ "COPY cannot be mixed with other operations"
+ )
+
+ result = results[0]
self._check_copy_result(result)
self.pgresult = result
self._tx.set_pgresult(result)
return data
# Retrieve the final result of copy
- (result,) = yield from fetch_many(pgconn)
+ results = yield from fetch_many(pgconn)
+ if len(results) > 1:
+ # TODO: too brutal? Copy worked.
+ raise e.ProgrammingError("you cannot mix COPY with other operations")
+ result = results[0]
if result.status != ExecStatus.COMMAND_OK:
encoding = py_codecs.get(
pgconn.parameter_status(b"client_encoding") or "", "utf-8"
with cur.copy("reset timezone"):
pass
+ with pytest.raises(e.ProgrammingError):
+ with cur.copy("copy (select 1) to stdout; select 1") as copy:
+ list(copy)
+
+ with pytest.raises(e.ProgrammingError):
+ with cur.copy("select 1; copy (select 1) to stdout"):
+ pass
+
def test_copy_in_str(conn):
cur = conn.cursor()
async with cur.copy("reset timezone"):
pass
+ with pytest.raises(e.ProgrammingError):
+ async with cur.copy("copy (select 1) to stdout; select 1") as copy:
+ [_ async for _ in copy]
+
+ with pytest.raises(e.ProgrammingError):
+ async with cur.copy("select 1; copy (select 1) to stdout"):
+ pass
+
async def test_copy_in_str(aconn):
cur = aconn.cursor()