Coverage for qutebrowser/completion/models/histcategory.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2017-2018 Ryan Roden-Corrent (rcorre) <ryan@rcorre.net> # # This file is part of qutebrowser. # # qutebrowser is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # qutebrowser is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""A completion category that queries the SQL History store."""
"""Create a new History completion category."""
# advertise that this model filters by URL and title
"""If max_items is set, return an expression to limit the query.""" # HistoryCategory should not be added to the completion in that case.
'SELECT min(last_atime) FROM', '(SELECT last_atime FROM CompletionHistory', 'ORDER BY last_atime DESC LIMIT :limit)', ])).run(limit=max_items).value()
# if there are no history items, min_atime may be '' (issue #2849)
"""Set the pattern used to filter results.
Args: pattern: string pattern to filter by. """ # escape to treat a user input % or _ as a literal, not a wildcard
# build a where clause to match all of the words in any order # given the search term "a b", the WHERE clause would be: # ((url || title) LIKE '%a%') AND ((url || title) LIKE '%b%') "(url || title) LIKE :{} escape '\\'".format(i) for i in range(len(words)))
# replace ' in timestamp-format to avoid breaking the query .format(timestamp_format.replace("'", "`")))
# if the number of words changed, we need to generate a new query # otherwise, we can reuse the prepared query for performance "SELECT url, title, {}".format(timefmt), "FROM CompletionHistory", # the incoming pattern will have literal % and _ escaped # we need to tell sql to treat '\' as an escape character 'WHERE ({})'.format(where_clause), self._atime_expr(), "ORDER BY last_atime DESC", ]), forward_only=False)
str(i): w for i, w in enumerate(words)})
"""Override QAbstractItemModel::removeRows to re-run sql query.""" # re-run query to reload updated table |