From 0047b4006e5e9309d4ebc96049a4ca7233455865 Mon Sep 17 00:00:00 2001 From: abetkin Date: Tue, 10 Sep 2019 19:02:05 +0300 Subject: [PATCH 1/3] Fix typo (tests are missing!) --- databases/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/databases/core.py b/databases/core.py index b8da05e6..8e4bff9b 100644 --- a/databases/core.py +++ b/databases/core.py @@ -242,7 +242,7 @@ def _build_query( return query.bindparams(**values) if values is not None else query elif values: - return query.values(**values) + return query.params(**values) return query From 92adf226df9d4d85de24eaf36fd23c6c871fef3a Mon Sep 17 00:00:00 2001 From: abetkin Date: Thu, 19 Sep 2019 18:11:13 +0300 Subject: [PATCH 2/3] _build_query: fix for non-selectable queries --- databases/core.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/databases/core.py b/databases/core.py index 8e4bff9b..84fb3878 100644 --- a/databases/core.py +++ b/databases/core.py @@ -242,7 +242,9 @@ def _build_query( return query.bindparams(**values) if values is not None else query elif values: - return query.params(**values) + if query.is_selectable: + return query.params(**values) + return query.values(**values) return query From ee857d4d5e1e7a27237708977d429f62ff39897a Mon Sep 17 00:00:00 2001 From: pwtail Date: Mon, 30 Sep 2019 20:40:19 -0400 Subject: [PATCH 3/3] a test for selectable queries with params --- tests/test_databases.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_databases.py b/tests/test_databases.py index d20ec8d5..9644bcd7 100644 --- a/tests/test_databases.py +++ b/tests/test_databases.py @@ -106,6 +106,16 @@ def run_sync(*args, **kwargs): return run_sync +@pytest.mark.parametrize("database_url", DATABASE_URLS) +@async_adapter +async def test_selectable_queries_with_params(database_url): + async with Database(database_url) as database: + async with database.transaction(force_rollback=True): + param = sqlalchemy.bindparam('price') + query = sqlalchemy.select([prices]).where(prices.c.price < param) + rows = await database.fetch_all(query=query, values={'price': 10}) + list(rows) + @pytest.mark.parametrize("database_url", DATABASE_URLS) @async_adapter