Tests for Database.dropFTS4SynchronizationTriggers & Database.dropFTS5SynchronizationTriggers

This commit is contained in:
Gwendal Roué committed 2017-12-01 13:14:24 +01:00
1 parent e8835af363
commit b4887b661c
2 files changed
+118

No files matched your search

@@ -229,4 +229,63 @@ class FTS4TableBuilderTests: GRDBTestCase {
XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
}
}
func testFTS4SynchronizationCleanup() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "documents") { t in
t.column("id", .integer).primaryKey()
t.column("content", .text)
}
try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
try db.create(virtualTable: "ft_documents", using: FTS4()) { t in
t.synchronize(withTable: "documents")
t.column("content")
}
try db.drop(table: "ft_documents")
try db.dropFTS4SynchronizationTriggers(forTable: "ft_documents")
// It is possible to modify the content table
try db.execute("UPDATE documents SET content = ?", arguments: ["bar"])
try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
try db.execute("DELETE FROM documents WHERE content = ?", arguments: ["foo"])
// It is possible to recreate the FT table
try db.create(virtualTable: "ft_documents", using: FTS4()) { t in
t.synchronize(withTable: "documents")
t.column("content")
}
}
}
func testFTS4SynchronizationCleanupWithLegacySupport() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "documents") { t in
t.column("id", .integer).primaryKey()
t.column("content", .text)
}
try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
try db.create(virtualTable: "ft_documents", using: FTS4()) { t in
t.synchronize(withTable: "documents")
t.column("content")
}
try db.drop(table: "ft_documents")
try db.dropFTS4SynchronizationTriggers(forTable: "documents") // legacy GRDB <= 2.3.1
try db.dropFTS4SynchronizationTriggers(forTable: "ft_documents")
// It is possible to modify the content table
try db.execute("UPDATE documents SET content = ?", arguments: ["bar"])
try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
try db.execute("DELETE FROM documents WHERE content = ?", arguments: ["foo"])
// It is possible to recreate the FT table
try db.create(virtualTable: "ft_documents", using: FTS4()) { t in
t.synchronize(withTable: "documents")
t.column("content")
}
}
}
}
@@ -219,5 +219,64 @@ class FTS5TableBuilderTests: GRDBTestCase {
XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
}
}
func testFTS5SynchronizationCleanup() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "documents") { t in
t.column("id", .integer).primaryKey()
t.column("content", .text)
}
try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
try db.create(virtualTable: "ft_documents", using: FTS5()) { t in
t.synchronize(withTable: "documents")
t.column("content")
}
try db.drop(table: "ft_documents")
try db.dropFTS5SynchronizationTriggers(forTable: "ft_documents")
// It is possible to modify the content table
try db.execute("UPDATE documents SET content = ?", arguments: ["bar"])
try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
try db.execute("DELETE FROM documents WHERE content = ?", arguments: ["foo"])
// It is possible to recreate the FT table
try db.create(virtualTable: "ft_documents", using: FTS5()) { t in
t.synchronize(withTable: "documents")
t.column("content")
}
}
}
func testFTS5SynchronizationCleanupWithLegacySupport() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "documents") { t in
t.column("id", .integer).primaryKey()
t.column("content", .text)
}
try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
try db.create(virtualTable: "ft_documents", using: FTS5()) { t in
t.synchronize(withTable: "documents")
t.column("content")
}
try db.drop(table: "ft_documents")
try db.dropFTS5SynchronizationTriggers(forTable: "documents") // legacy GRDB <= 2.3.1
try db.dropFTS5SynchronizationTriggers(forTable: "ft_documents")
// It is possible to modify the content table
try db.execute("UPDATE documents SET content = ?", arguments: ["bar"])
try db.execute("INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
try db.execute("DELETE FROM documents WHERE content = ?", arguments: ["foo"])
// It is possible to recreate the FT table
try db.create(virtualTable: "ft_documents", using: FTS5()) { t in
t.synchronize(withTable: "documents")
t.column("content")
}
}
}
}
#endif