Also detect missing bound values for sql.Query.run_batch

This commit is contained in:
Florian Bruhin 2018-09-01 11:44:46 +02:00
parent fa1fe63a93
commit 3f2a468750
2 changed files with 7 additions and 0 deletions

View File

@ -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()

View File

@ -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()