Fix new completion with web-history-max-items set to 0

We get no last_atime limit at all otherwise:

qutebrowser.misc.sql.SqlException: Failed to prepare query "SELECT url, title,
strftime('%Y-%m-%d', last_atime, 'unixepoch', 'localtime') FROM
CompletionHistory WHERE (url LIKE :pat escape '\' or title LIKE :pat escape '\')
AND last_atime >= ORDER BY last_atime DESC": "near "ORDER": syntax error Unable
to execute statement"
This commit is contained in:
Florian Bruhin 2017-07-21 17:10:03 +02:00
parent de0b50eaf7
commit 6660297871
2 changed files with 11 additions and 5 deletions

View File

@ -60,7 +60,7 @@ class HistoryCategory(QSqlQueryModel):
def _atime_expr(self): def _atime_expr(self):
"""If max_items is set, return an expression to limit the query.""" """If max_items is set, return an expression to limit the query."""
max_items = config.get('completion', 'web-history-max-items') max_items = config.get('completion', 'web-history-max-items')
if max_items < 0: if max_items <= 0:
return '' return ''
min_atime = sql.Query(' '.join([ min_atime = sql.Query(' '.join([
@ -83,6 +83,7 @@ class HistoryCategory(QSqlQueryModel):
# treat spaces as wildcards to match any of the typed words # treat spaces as wildcards to match any of the typed words
pattern = re.sub(r' +', '%', pattern) pattern = re.sub(r' +', '%', pattern)
pattern = '%{}%'.format(pattern) pattern = '%{}%'.format(pattern)
if config.get('completion', 'web-history-max-items') != 0:
with debug.log_time('sql', 'Running completion query'): with debug.log_time('sql', 'Running completion query'):
self._query.run(pat=pattern) self._query.run(pat=pattern)
self.setQuery(self._query) self.setQuery(self._query)

View File

@ -117,7 +117,12 @@ def test_set_pattern(pattern, before, after, model_validator, hist):
], [ ], [
('b', 'b', '2017-06-16'), ('b', 'b', '2017-06-16'),
('c', 'c', '2017-05-16'), ('c', 'c', '2017-05-16'),
]) ]),
(0, [
('a', 'a', '2017-04-16'),
('b', 'b', '2017-06-16'),
('c', 'c', '2017-05-16'),
], []),
]) ])
def test_sorting(max_items, before, after, model_validator, hist, config_stub): def test_sorting(max_items, before, after, model_validator, hist, config_stub):
"""Validate the filtering and sorting results of set_pattern.""" """Validate the filtering and sorting results of set_pattern."""