From 251b960376a80986d85c1fa4d66e1b323656d6f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciek=20Bry=C5=84ski?= Date: Mon, 30 Sep 2024 15:24:55 +0200 Subject: [PATCH] Add no cursor test --- aiosql/adapters/duckdb.py | 6 +++--- tests/test_duckdb.py | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/aiosql/adapters/duckdb.py b/aiosql/adapters/duckdb.py index 39e8fea4..8551effc 100644 --- a/aiosql/adapters/duckdb.py +++ b/aiosql/adapters/duckdb.py @@ -42,7 +42,7 @@ def insert_returning(self, conn, query_name, sql, parameters): # pragma: no cov # https://github.com/duckdb/duckdb/issues/6008 res = cur.fetchall() finally: - if not self._use_cursor: + if self._use_cursor: cur.close() if isinstance(res, list): res = res[0] @@ -73,7 +73,7 @@ def select(self, conn, query_name: str, sql: str, parameters, record_class=None) # strict=False: requires 3.10 yield record_class(**dict(zip(column_names, row))) finally: - if not self._use_cursor: + if self._use_cursor: cur.close() def select_one(self, conn, query_name, sql, parameters, record_class=None): @@ -89,6 +89,6 @@ def select_one(self, conn, query_name, sql, parameters, record_class=None): column_names = [c[0] for c in cur.description or []] result = dict(zip(column_names, result)) finally: - if not self._use_cursor: + if self._use_cursor: cur.close() return result diff --git a/tests/test_duckdb.py b/tests/test_duckdb.py index 4fe39d38..9e1ffaee 100644 --- a/tests/test_duckdb.py +++ b/tests/test_duckdb.py @@ -43,3 +43,8 @@ def conn(duckdb_conn): run_execute_script as test_execute_script, run_modulo as test_modulo, ) + +def test_no_cursor(conn): + adapter = aiosql.adapters.duckdb.DuckDBAdapter(use_cursor=False) + cursor = adapter._cursor(conn) + assert cursor == conn