Implement canFetchMore for SQL completion.
This just forwards canFetchMore and fetchMore to the underlying tables. It seems to be returning True and fetching in some cases (with a large history), so I guess it is useful?
This commit is contained in:
parent
ffd044b52b
commit
02fb1a037c
@ -91,6 +91,19 @@ class SqlCompletionModel(QAbstractItemModel):
|
||||
self.pattern = ''
|
||||
self.delete_cur_item = delete_cur_item
|
||||
|
||||
def _cat_from_idx(self, index):
|
||||
"""Return the category pointed to by the given index.
|
||||
|
||||
Args:
|
||||
idx: A QModelIndex
|
||||
Returns:
|
||||
A _SqlCompletionCategory if the index points at one, else None
|
||||
"""
|
||||
# items hold an index to the parent category in their internalPointer
|
||||
# categories have an empty internalPointer
|
||||
if index.isValid() and not index.internalPointer():
|
||||
return self._categories[index.row()]
|
||||
|
||||
def new_category(self, name, select='*', where=None, sort_by=None,
|
||||
sort_order=None, limit=None):
|
||||
"""Create a new completion category and add it to this model.
|
||||
@ -184,17 +197,31 @@ class SqlCompletionModel(QAbstractItemModel):
|
||||
if not parent.isValid():
|
||||
# top-level
|
||||
return len(self._categories)
|
||||
elif parent.internalPointer() or parent.column() != 0:
|
||||
cat = self._cat_from_idx(parent)
|
||||
if not cat or parent.column() != 0:
|
||||
# item or nonzero category column (only first col has children)
|
||||
return 0
|
||||
else:
|
||||
# category
|
||||
return self._categories[parent.row()].rowCount()
|
||||
return cat.rowCount()
|
||||
|
||||
def columnCount(self, parent=QModelIndex()):
|
||||
# pylint: disable=unused-argument
|
||||
return 3
|
||||
|
||||
def canFetchMore(self, parent):
|
||||
"""Override to forward the call to the tables."""
|
||||
cat = self._cat_from_idx(parent)
|
||||
if cat:
|
||||
return cat.canFetchMore()
|
||||
return False
|
||||
|
||||
def fetchMore(self, parent):
|
||||
"""Override to forward the call to the tables."""
|
||||
cat = self._cat_from_idx(parent)
|
||||
if cat:
|
||||
cat.fetchMore()
|
||||
|
||||
def count(self):
|
||||
"""Return the count of non-category items."""
|
||||
return sum(t.rowCount() for t in self._categories)
|
||||
|
@ -47,13 +47,13 @@ def run_query(querystr, values=None):
|
||||
Args:
|
||||
values: A list of positional parameter bindings.
|
||||
"""
|
||||
log.completion.debug('Running SQL query: "{}"'.format(querystr))
|
||||
log.sql.debug('Running SQL query: "{}"'.format(querystr))
|
||||
database = QSqlDatabase.database()
|
||||
query = QSqlQuery(database)
|
||||
query.prepare(querystr)
|
||||
for val in values or []:
|
||||
query.addBindValue(val)
|
||||
log.completion.debug('Query bindings: {}'.format(query.boundValues()))
|
||||
log.sql.debug('Query bindings: {}'.format(query.boundValues()))
|
||||
if not query.exec_():
|
||||
raise SqlException('Failed to exec query "{}": "{}"'.format(
|
||||
querystr, query.lastError().text()))
|
||||
|
@ -141,6 +141,7 @@ sessions = logging.getLogger('sessions')
|
||||
webelem = logging.getLogger('webelem')
|
||||
prompt = logging.getLogger('prompt')
|
||||
network = logging.getLogger('network')
|
||||
sql = logging.getLogger('sql')
|
||||
|
||||
|
||||
ram_handler = None
|
||||
|
Loading…
Reference in New Issue
Block a user