mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
54 lines
1.8 KiB
Swift
54 lines
1.8 KiB
Swift
import XCTest
|
|
#if GRDBCIPHER
|
|
import GRDBCipher
|
|
#elseif GRDBCUSTOMSQLITE
|
|
import GRDBCustomSQLite
|
|
#else
|
|
import GRDB
|
|
#endif
|
|
|
|
class DatabaseWriterTests : GRDBTestCase {
|
|
|
|
func testDatabaseQueueUnsafeReentrantWrite() throws {
|
|
let dbQueue = try makeDatabaseQueue()
|
|
try dbQueue.unsafeReentrantWrite { db1 in
|
|
try db1.create(table: "table1") { t in
|
|
t.column("id", .integer).primaryKey()
|
|
}
|
|
try dbQueue.unsafeReentrantWrite { db2 in
|
|
try db2.execute("INSERT INTO table1 (id) VALUES (NULL)")
|
|
|
|
try dbQueue.unsafeReentrantWrite { db3 in
|
|
try XCTAssertEqual(Int.fetchOne(db3, "SELECT * FROM table1"), 1)
|
|
XCTAssertTrue(db1 === db2)
|
|
XCTAssertTrue(db2 === db3)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func testDatabasePoolUnsafeReentrantWrite() throws {
|
|
let dbPool = try makeDatabasePool()
|
|
try dbPool.unsafeReentrantWrite { db1 in
|
|
try db1.create(table: "table1") { t in
|
|
t.column("id", .integer).primaryKey()
|
|
}
|
|
try dbPool.unsafeReentrantWrite { db2 in
|
|
try db2.execute("INSERT INTO table1 (id) VALUES (NULL)")
|
|
|
|
try dbPool.unsafeReentrantWrite { db3 in
|
|
try XCTAssertEqual(Int.fetchOne(db3, "SELECT * FROM table1"), 1)
|
|
XCTAssertTrue(db1 === db2)
|
|
XCTAssertTrue(db2 === db3)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func testAnyDatabaseWriter() {
|
|
// This test passes if this code compiles.
|
|
let writer: DatabaseWriter = DatabaseQueue()
|
|
let _: DatabaseWriter = AnyDatabaseWriter(writer)
|
|
}
|
|
}
|