psycopg.git / summary / log / commit / refs
commit 47821540b2cbfc9150ebbccd8cf959cc41de2c2d
Author: Daniele Varrazzo <daniele.varrazzo@gmail.com>
Date: Fri Feb 12 02:35:04 2021 +0000
Add tests to verify broken queries or other statements in server-side cursors
Enforce passing a single statement by making sure to use the advanced
query protocol.
psycopg3/psycopg3/server_cursor.py | 2 +-
tests/test_server_cursor.py | 9 +++++++++
tests/test_server_cursor_async.py | 9 +++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/psycopg3/psycopg3/server_cursor.py b/psycopg3/psycopg3/server_cursor.py
index 058a0392..cadd2ca7 100644
--- a/psycopg3/psycopg3/server_cursor.py
+++ b/psycopg3/psycopg3/server_cursor.py
@@ -61,7 +61,7 @@ class ServerCursorHelper(Generic[ConnectionType]):
yield from cur._start_query(query)
pgq = cur._convert_query(query, params)
- cur._execute_send(pgq)
+ cur._execute_send(pgq, no_pqexec=True)
results = yield from execute(conn.pgconn)
cur._execute_results(results)
diff --git a/tests/test_server_cursor.py b/tests/test_server_cursor.py
index 551579e9..29cb2921 100644
--- a/tests/test_server_cursor.py
+++ b/tests/test_server_cursor.py
@@ -108,6 +108,15 @@ def test_execute_reuse(conn):
assert cur.description[1].name == "baz"
+@pytest.mark.parametrize(
+ "stmt", ["", "wat", "create table ssc ()", "select 1; select 2"]
+)
+def test_execute_error(conn, stmt):
+ cur = conn.cursor("foo")
+ with pytest.raises(e.ProgrammingError):
+ cur.execute(stmt)
+
+
def test_executemany(conn):
cur = conn.cursor("foo")
with pytest.raises(e.NotSupportedError):
diff --git a/tests/test_server_cursor_async.py b/tests/test_server_cursor_async.py
index fa2d9425..d7d4805a 100644
--- a/tests/test_server_cursor_async.py
+++ b/tests/test_server_cursor_async.py
@@ -110,6 +110,15 @@ async def test_execute_reuse(aconn):
assert cur.description[1].name == "baz"
+@pytest.mark.parametrize(
+ "stmt", ["", "wat", "create table ssc ()", "select 1; select 2"]
+)
+async def test_execute_error(aconn, stmt):
+ cur = aconn.cursor("foo")
+ with pytest.raises(e.ProgrammingError):
+ await cur.execute(stmt)
+
+
async def test_executemany(aconn):
cur = aconn.cursor("foo")
with pytest.raises(e.NotSupportedError):
[parent: fafeb13521b0]