From 3f2a468750c24257e9bd99adcd24f12f92fbadf7 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 1 Sep 2018 11:44:46 +0200 Subject: [PATCH] Also detect missing bound values for sql.Query.run_batch --- qutebrowser/misc/sql.py | 2 ++ tests/unit/misc/test_sql.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/qutebrowser/misc/sql.py b/qutebrowser/misc/sql.py index c7028380d..91edf0cb6 100644 --- a/qutebrowser/misc/sql.py +++ b/qutebrowser/misc/sql.py @@ -193,6 +193,8 @@ class Query: for key, val in values.items(): self.query.bindValue(':{}'.format(key), val) + if any(val is None for val in self.bound_values().values()): + raise SqlError("Missing bound values!") db = QSqlDatabase.database() db.transaction() diff --git a/tests/unit/misc/test_sql.py b/tests/unit/misc/test_sql.py index 3479259ee..67ca5e5c1 100644 --- a/tests/unit/misc/test_sql.py +++ b/tests/unit/misc/test_sql.py @@ -285,6 +285,11 @@ class TestSqlQuery: q.run_batch(values={'answer': [42]}) assert q.value() == 42 + def test_run_batch_missing_binding(self): + q = sql.Query('SELECT :answer') + with pytest.raises(sql.SqlError, match='Missing bound values!'): + q.run_batch(values={}) + def test_value_missing(self): q = sql.Query('SELECT 0 WHERE 0') q.run()