Files
GRDB.swift/Tests/Public/Core/Database/ReadOnlyDatabaseTests.swift
T
swiftlyfalling 30bc7e4f6c Replace most uses of #if SQLITE_HAS_CODEC with the appropriate USING_BUILTIN_SQLITE or USING_SQLCIPHER defines.
This enables easier compilation of a custom version of SQLite that
itself uses the SQLITE_HAS_CODEC define. (ex. If building SQLite with
the SQLite Encryption Extension.)
The SQLITE_HAS_CODEC define is now only used to guard use of the SQLite
encryption APIs.
GRDBCipher builds define USING_BUILTIN_SQLITE and USING_SQLCIPHER.
2016-05-30 18:19:45 -04:00

39 lines
1.3 KiB
Swift

import XCTest
#if USING_SQLCIPHER
import GRDBCipher
#elseif USING_CUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
class ReadOnlyDatabaseTests : GRDBTestCase {
func testReadOnlyDatabaseCanNotBeModified() {
assertNoError {
// Create database
do {
try makeDatabaseQueue()
}
// Open it again, readonly
dbConfiguration.readonly = true
let dbQueue = try makeDatabaseQueue()
let statement = try dbQueue.inDatabase { db in
try db.updateStatement("CREATE TABLE items (id INTEGER PRIMARY KEY)")
}
do {
try dbQueue.inDatabase { db in
try statement.execute()
}
XCTFail()
} catch let error as DatabaseError {
XCTAssertEqual(error.code, 8) // SQLITE_READONLY
XCTAssertEqual(error.message!, "attempt to write a readonly database")
XCTAssertEqual(error.sql!, "CREATE TABLE items (id INTEGER PRIMARY KEY)")
XCTAssertEqual(error.description, "SQLite error 8 with statement `CREATE TABLE items (id INTEGER PRIMARY KEY)`: attempt to write a readonly database")
}
}
}
}