]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Test server-side cursor hold
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 11 Feb 2021 19:42:22 +0000 (20:42 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 11 Feb 2021 19:42:22 +0000 (20:42 +0100)
tests/test_server_cursor.py
tests/test_server_cursor_async.py

index 09ae7bac4d1c3b213a00e15c2616ac08a22dcb04..551579e95ffedebc58a0dd62ab5d814a4f98190a 100644 (file)
@@ -238,6 +238,24 @@ def test_non_scrollable(conn):
         curs.scroll(-1)
 
 
+@pytest.mark.parametrize("kwargs", [{}, {"hold": False}])
+def test_no_hold(conn, kwargs):
+    with pytest.raises(e.InvalidCursorName):
+        with conn.cursor("foo") as curs:
+            curs.execute("select generate_series(0, 2)", **kwargs)
+            assert curs.fetchone() == (0,)
+            conn.commit()
+            curs.fetchone()
+
+
+def test_hold(conn):
+    with conn.cursor("foo") as curs:
+        curs.execute("select generate_series(0, 5)", hold=True)
+        assert curs.fetchone() == (0,)
+        conn.commit()
+        assert curs.fetchone() == (1,)
+
+
 def test_steal_cursor(conn):
     cur1 = conn.cursor()
     cur1.execute("declare test cursor for select generate_series(1, 6)")
index 8326578d6805688af748cae606be0de833d3fae5..fa2d9425cdcc4f67f35c9630550a7e480d3165d6 100644 (file)
@@ -245,6 +245,24 @@ async def test_non_scrollable(aconn):
         await curs.scroll(-1)
 
 
+@pytest.mark.parametrize("kwargs", [{}, {"hold": False}])
+async def test_no_hold(aconn, kwargs):
+    with pytest.raises(e.InvalidCursorName):
+        async with aconn.cursor("foo") as curs:
+            await curs.execute("select generate_series(0, 2)", **kwargs)
+            assert await curs.fetchone() == (0,)
+            await aconn.commit()
+            await curs.fetchone()
+
+
+async def test_hold(aconn):
+    async with aconn.cursor("foo") as curs:
+        await curs.execute("select generate_series(0, 5)", hold=True)
+        assert await curs.fetchone() == (0,)
+        await aconn.commit()
+        assert await curs.fetchone() == (1,)
+
+
 async def test_steal_cursor(aconn):
     cur1 = aconn.cursor()
     await cur1.execute(