Make sure queries don't have any missing bindings
This commit is contained in:
parent
1d6282fd6c
commit
6b719fb218
@ -171,9 +171,13 @@ class Query(QSqlQuery):
|
||||
def run(self, **values):
|
||||
"""Execute the prepared query."""
|
||||
log.sql.debug('Running SQL query: "{}"'.format(self.lastQuery()))
|
||||
|
||||
for key, val in values.items():
|
||||
self.bindValue(':{}'.format(key), val)
|
||||
log.sql.debug('query bindings: {}'.format(self.boundValues()))
|
||||
if any(val is None for val in self.boundValues().values()):
|
||||
raise SqlError("Missing bound values!")
|
||||
|
||||
if not self.exec_():
|
||||
raise SqliteError.from_query('exec', self.lastQuery(),
|
||||
self.lastError())
|
||||
|
@ -263,6 +263,11 @@ class TestSqlQuery:
|
||||
q.run(answer=42)
|
||||
assert q.value() == 42
|
||||
|
||||
def test_run_missing_binding(self):
|
||||
q = sql.Query('SELECT :answer')
|
||||
with pytest.raises(sql.SqlError, match='Missing bound values!'):
|
||||
q.run()
|
||||
|
||||
def test_value_missing(self):
|
||||
q = sql.Query('SELECT 0 WHERE 0')
|
||||
q.run()
|
||||
|
Loading…
Reference in New Issue
Block a user