mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Issue #61: failing test for TransactionObserver with several identically named savepoints
This commit is contained in:
1 parent
34dad07393
commit
a26bef8813
1 file changed
+42
@@ -102,6 +102,48 @@ class TransactionObserverSavepointsTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testSavepointWithIdenticalName() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let observer = TransactionObserver()
|
||||
dbQueue.addTransactionObserver(observer)
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE items1 (id INTEGER PRIMARY KEY)")
|
||||
try db.execute("CREATE TABLE items2 (id INTEGER PRIMARY KEY)")
|
||||
try db.execute("CREATE TABLE items3 (id INTEGER PRIMARY KEY)")
|
||||
try db.execute("CREATE TABLE items4 (id INTEGER PRIMARY KEY)")
|
||||
try db.execute("BEGIN TRANSACTION")
|
||||
try db.execute("INSERT INTO items1 (id) VALUES (NULL)")
|
||||
XCTAssertEqual(observer.events.count, 1)
|
||||
try db.execute("SAVEPOINT sp1")
|
||||
try db.execute("INSERT INTO items2 (id) VALUES (NULL)")
|
||||
XCTAssertEqual(observer.events.count, 1)
|
||||
try db.execute("SAVEPOINT sp1")
|
||||
try db.execute("INSERT INTO items3 (id) VALUES (NULL)")
|
||||
XCTAssertEqual(observer.events.count, 1)
|
||||
try db.execute("RELEASE SAVEPOINT sp1")
|
||||
XCTAssertEqual(observer.events.count, 1)
|
||||
try db.execute("RELEASE SAVEPOINT sp1")
|
||||
XCTAssertEqual(observer.events.count, 3)
|
||||
try db.execute("INSERT INTO items4 (id) VALUES (NULL)")
|
||||
XCTAssertEqual(observer.events.count, 4)
|
||||
try db.execute("COMMIT")
|
||||
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items1"), 1)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items2"), 1)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items3"), 1)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items4"), 1)
|
||||
}
|
||||
|
||||
XCTAssertEqual(observer.lastCommittedEvents.count, 3)
|
||||
XCTAssertTrue(match(event: observer.lastCommittedEvents[0], kind: .Insert, tableName: "items1", rowId: 1))
|
||||
XCTAssertTrue(match(event: observer.lastCommittedEvents[1], kind: .Insert, tableName: "items2", rowId: 1))
|
||||
XCTAssertTrue(match(event: observer.lastCommittedEvents[2], kind: .Insert, tableName: "items3", rowId: 1))
|
||||
XCTAssertTrue(match(event: observer.lastCommittedEvents[3], kind: .Insert, tableName: "items4", rowId: 1))
|
||||
}
|
||||
}
|
||||
|
||||
func testRollbackNestedSavepoint() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
Reference in new issue
Block a user