From 66602978710966c222ae41236ee13bb39327a7e0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 21 Jul 2017 17:10:03 +0200 Subject: [PATCH] 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" --- qutebrowser/completion/models/histcategory.py | 9 +++++---- tests/unit/completion/test_histcategory.py | 7 ++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/qutebrowser/completion/models/histcategory.py b/qutebrowser/completion/models/histcategory.py index fa8443a60..c87ba026c 100644 --- a/qutebrowser/completion/models/histcategory.py +++ b/qutebrowser/completion/models/histcategory.py @@ -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.""" diff --git a/tests/unit/completion/test_histcategory.py b/tests/unit/completion/test_histcategory.py index 0b5fcb915..bfd9d4aa5 100644 --- a/tests/unit/completion/test_histcategory.py +++ b/tests/unit/completion/test_histcategory.py @@ -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."""