mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-24 04:07:47 +00:00
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.
41 lines
1.3 KiB
Swift
41 lines
1.3 KiB
Swift
import XCTest
|
|
#if USING_SQLCIPHER
|
|
import GRDBCipher
|
|
#elseif USING_CUSTOMSQLITE
|
|
import GRDBCustomSQLite
|
|
#else
|
|
import GRDB
|
|
#endif
|
|
|
|
class DatabasePoolFunctionTests: GRDBTestCase {
|
|
|
|
func testFunctionIsSharedBetweenWriterAndReaders() {
|
|
assertNoError {
|
|
let dbPool = try makeDatabasePool()
|
|
|
|
let function1 = DatabaseFunction("function1", argumentCount: 1, pure: true) { (databaseValues: [DatabaseValue]) in
|
|
return databaseValues[0]
|
|
}
|
|
|
|
dbPool.addFunction(function1)
|
|
|
|
try dbPool.write { db in
|
|
try db.execute("CREATE TABLE items (text TEXT)")
|
|
try db.execute("INSERT INTO items (text) VALUES (function1('a'))")
|
|
}
|
|
dbPool.read { db in
|
|
XCTAssertEqual(String.fetchOne(db, "SELECT function1(text) FROM items")!, "a")
|
|
}
|
|
|
|
let function2 = DatabaseFunction("function2", argumentCount: 1, pure: true) { (databaseValues: [DatabaseValue]) in
|
|
return "foo"
|
|
}
|
|
dbPool.addFunction(function2)
|
|
|
|
dbPool.read { db in
|
|
XCTAssertTrue(String.fetchOne(db, "SELECT function2(text) FROM items") == "foo")
|
|
}
|
|
}
|
|
}
|
|
}
|