Merge remote-tracking branch 'origin/pr/3048'

This commit is contained in:
Florian Bruhin 2017-10-04 06:47:48 +02:00
commit 42550cd2e6
3 changed files with 17 additions and 6 deletions

View File

@ -40,7 +40,10 @@ class CompletionHistory(sql.SqlTable):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__("CompletionHistory", ['url', 'title', 'last_atime'], super().__init__("CompletionHistory", ['url', 'title', 'last_atime'],
constraints={'url': 'PRIMARY KEY'}, parent=parent) constraints={'url': 'PRIMARY KEY',
'title': 'NOT NULL',
'last_atime': 'NOT NULL'},
parent=parent)
self.create_index('CompletionHistoryAtimeIndex', 'last_atime') self.create_index('CompletionHistoryAtimeIndex', 'last_atime')
@ -50,6 +53,10 @@ class WebHistory(sql.SqlTable):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__("History", ['url', 'title', 'atime', 'redirect'], super().__init__("History", ['url', 'title', 'atime', 'redirect'],
constraints={'url': 'NOT NULL',
'title': 'NOT NULL',
'atime': 'NOT NULL',
'redirect': 'NOT NULL'},
parent=parent) parent=parent)
self.completion = CompletionHistory(parent=self) self.completion = CompletionHistory(parent=self)
if sql.Query('pragma user_version').run().value() < _USER_VERSION: if sql.Query('pragma user_version').run().value() < _USER_VERSION:

View File

@ -150,7 +150,7 @@ class SqlTable(QObject):
def __init__(self, name, fields, constraints=None, parent=None): def __init__(self, name, fields, constraints=None, parent=None):
"""Create a new table in the sql database. """Create a new table in the sql database.
Raises SqlError if the table already exists. Does nothing if the table already exists.
Args: Args:
name: Name of the table. name: Name of the table.

View File

@ -140,20 +140,24 @@ def test_sorting(max_items, before, after, model_validator, hist, config_stub):
def test_remove_rows(hist, model_validator): def test_remove_rows(hist, model_validator):
hist.insert({'url': 'foo', 'title': 'Foo'}) hist.insert({'url': 'foo', 'title': 'Foo', 'last_atime': 0})
hist.insert({'url': 'bar', 'title': 'Bar'}) hist.insert({'url': 'bar', 'title': 'Bar', 'last_atime': 0})
cat = histcategory.HistoryCategory() cat = histcategory.HistoryCategory()
model_validator.set_model(cat) model_validator.set_model(cat)
cat.set_pattern('') cat.set_pattern('')
hist.delete('url', 'foo') hist.delete('url', 'foo')
cat.removeRows(0, 1) cat.removeRows(0, 1)
model_validator.validate([('bar', 'Bar', '')]) model_validator.validate([('bar', 'Bar', '1970-01-01')])
def test_remove_rows_fetch(hist): def test_remove_rows_fetch(hist):
"""removeRows should fetch enough data to make the current index valid.""" """removeRows should fetch enough data to make the current index valid."""
# we cannot use model_validator as it will fetch everything up front # we cannot use model_validator as it will fetch everything up front
hist.insert_batch({'url': [str(i) for i in range(300)]}) hist.insert_batch({
'url': [str(i) for i in range(300)],
'title': [str(i) for i in range(300)],
'last_atime': [0] * 300,
})
cat = histcategory.HistoryCategory() cat = histcategory.HistoryCategory()
cat.set_pattern('') cat.set_pattern('')