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:
parent
de0b50eaf7
commit
6660297871
@ -60,7 +60,7 @@ class HistoryCategory(QSqlQueryModel):
|
||||
def _atime_expr(self):
|
||||
"""If max_items is set, return an expression to limit the query."""
|
||||
max_items = config.get('completion', 'web-history-max-items')
|
||||
if max_items < 0:
|
||||
if max_items <= 0:
|
||||
return ''
|
||||
|
||||
min_atime = sql.Query(' '.join([
|
||||
@ -83,9 +83,10 @@ class HistoryCategory(QSqlQueryModel):
|
||||
# treat spaces as wildcards to match any of the typed words
|
||||
pattern = re.sub(r' +', '%', pattern)
|
||||
pattern = '%{}%'.format(pattern)
|
||||
with debug.log_time('sql', 'Running completion query'):
|
||||
self._query.run(pat=pattern)
|
||||
self.setQuery(self._query)
|
||||
if config.get('completion', 'web-history-max-items') != 0:
|
||||
with debug.log_time('sql', 'Running completion query'):
|
||||
self._query.run(pat=pattern)
|
||||
self.setQuery(self._query)
|
||||
|
||||
def delete_cur_item(self, index):
|
||||
"""Delete the row at the given index."""
|
||||
|
@ -117,7 +117,12 @@ def test_set_pattern(pattern, before, after, model_validator, hist):
|
||||
], [
|
||||
('b', 'b', '2017-06-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):
|
||||
"""Validate the filtering and sorting results of set_pattern."""
|
||||
|
Loading…
Reference in New Issue
Block a user