Files
GRDB.swift/Tests/Private/StatementInformationTests.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

47 lines
1.7 KiB
Swift

import XCTest
#if USING_SQLCIPHER
@testable import GRDBCipher
#elseif USING_CUSTOMSQLITE
@testable import GRDBCustomSQLite
#else
@testable import GRDB
#endif
class StatementInformationTests : GRDBTestCase {
func testSelectStatementSourceTables() {
assertNoError {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.execute("CREATE TABLE foo (id INTEGER)")
try db.execute("CREATE TABLE bar (id INTEGER, fooId INTEGER)")
let statement = try db.selectStatement("SELECT * FROM FOO JOIN BAR ON fooId = foo.id")
XCTAssertTrue(statement.sourceTables.count == 2)
XCTAssertTrue(statement.sourceTables.contains("foo"))
XCTAssertTrue(statement.sourceTables.contains("bar"))
}
}
}
func testUpdateStatementInvalidatesDatabaseSchemaCache() {
assertNoError {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
do {
let statement = try db.updateStatement("CREATE TABLE foo (id INTEGER)")
XCTAssertFalse(statement.invalidatesDatabaseSchemaCache)
try statement.execute()
}
do {
let statement = try db.updateStatement("ALTER TABLE foo ADD COLUMN name TEXT")
XCTAssertTrue(statement.invalidatesDatabaseSchemaCache)
}
do {
let statement = try db.updateStatement("DROP TABLE foo")
XCTAssertTrue(statement.invalidatesDatabaseSchemaCache)
}
}
}
}
}