mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Finish trigger tests
This commit is contained in:
parent
1dd710991f
commit
2ecdbfb194
@ -4,8 +4,8 @@ CREATE TEMP TRIGGER fts_db_book_deleted_trg AFTER DELETE ON main.books BEGIN
|
|||||||
END;
|
END;
|
||||||
|
|
||||||
CREATE TEMP TRIGGER fts_db_format_deleted_trg AFTER DELETE ON main.data BEGIN
|
CREATE TEMP TRIGGER fts_db_format_deleted_trg AFTER DELETE ON main.data BEGIN
|
||||||
DELETE FROM books_text WHERE book=OLD.id AND format=OLD.format;
|
DELETE FROM books_text WHERE book=OLD.book AND format=OLD.format;
|
||||||
DELETE FROM dirtied_formats WHERE book=OLD.id AND format=OLD.format;
|
DELETE FROM dirtied_formats WHERE book=OLD.book AND format=OLD.format;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
CREATE TEMP TRIGGER fts_db_format_added_trg AFTER INSERT ON main.data BEGIN
|
CREATE TEMP TRIGGER fts_db_format_added_trg AFTER INSERT ON main.data BEGIN
|
||||||
|
@ -39,3 +39,7 @@ class FTS:
|
|||||||
def all_currently_dirty(self):
|
def all_currently_dirty(self):
|
||||||
conn = self.get_connection()
|
conn = self.get_connection()
|
||||||
return conn.get('''SELECT book, format from fts_db.dirtied_formats''', all=True)
|
return conn.get('''SELECT book, format from fts_db.dirtied_formats''', all=True)
|
||||||
|
|
||||||
|
def clear_all_dirty(self):
|
||||||
|
conn = self.get_connection()
|
||||||
|
conn.execute('DELETE FROM fts_db.dirtied_formats')
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import builtins
|
import builtins
|
||||||
import sys
|
import sys
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
from calibre.db.tests.base import BaseTest
|
from calibre.db.tests.base import BaseTest
|
||||||
|
|
||||||
@ -29,10 +30,19 @@ class FTSAPITest(BaseTest):
|
|||||||
def test_fts_triggers(self):
|
def test_fts_triggers(self):
|
||||||
cache = self.init_cache()
|
cache = self.init_cache()
|
||||||
fts = cache.backend.enable_fts()
|
fts = cache.backend.enable_fts()
|
||||||
cd = fts.all_currently_dirty()
|
self.ae(fts.all_currently_dirty(), [(1, 'FMT1'), (1, 'FMT2'), (2, 'FMT1')])
|
||||||
self.ae(len(cd), 3)
|
|
||||||
fts.dirty_existing()
|
fts.dirty_existing()
|
||||||
self.ae(len(cd), 3)
|
self.ae(fts.all_currently_dirty(), [(1, 'FMT1'), (1, 'FMT2'), (2, 'FMT1')])
|
||||||
|
cache.remove_formats({2: ['FMT1']})
|
||||||
|
self.ae(fts.all_currently_dirty(), [(1, 'FMT1'), (1, 'FMT2')])
|
||||||
|
cache.remove_books((1,))
|
||||||
|
self.ae(fts.all_currently_dirty(), [])
|
||||||
|
cache.add_format(2, 'ADDED', BytesIO(b'data'))
|
||||||
|
self.ae(fts.all_currently_dirty(), [(2, 'ADDED')])
|
||||||
|
fts.clear_all_dirty()
|
||||||
|
self.ae(fts.all_currently_dirty(), [])
|
||||||
|
cache.add_format(2, 'ADDED', BytesIO(b'data2'))
|
||||||
|
self.ae(fts.all_currently_dirty(), [(2, 'ADDED')])
|
||||||
|
|
||||||
|
|
||||||
def find_tests():
|
def find_tests():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user