mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Merge pull request #831 from groue/dev/more-preparation
Improve Configuration.prepareDatabase
This commit is contained in:
47 files changed
+502
-692
No files matched your search
@@ -66,7 +66,11 @@ Once you have a custom tokenizer type that adopts [FTS5CustomTokenizer](#fts5cus
|
||||
```swift
|
||||
class MyTokenizer : FTS5CustomTokenizer { ... }
|
||||
|
||||
dbQueue.add(tokenizer: MyTokenizer.self) // or dbPool.add
|
||||
var config = Configuration()
|
||||
config.prepareDatabase { db in
|
||||
db.add(tokenizer: MyTokenizer.self)
|
||||
}
|
||||
let dbQueue = try DatabaseQueue(path: dbPath, configuration: config)
|
||||
```
|
||||
|
||||
**Create [full-text tables](../../../#create-fts5-virtual-tables) that use the custom tokenizer:**
|
||||
|
||||
@@ -5,6 +5,7 @@ Migrating From GRDB 4 to GRDB 5
|
||||
|
||||
- [Preparing the Migration to GRDB 5](#preparing-the-migration-to-grdb-5)
|
||||
- [New requirements](#new-requirements)
|
||||
- [Database Configuration](#database-configuration)
|
||||
- [ValueObservation](#valueobservation)
|
||||
- [Combine Integration](#combine-integration)
|
||||
- [Other Changes](#other-changes)
|
||||
@@ -31,6 +32,35 @@ GRDB requirements have been bumped:
|
||||
- watchOS 2.0+ (unchanged)
|
||||
|
||||
|
||||
## Database Configuration
|
||||
|
||||
The way to configure a database relies much more on the `Configuration.prepareDatabase(_:)` method:
|
||||
|
||||
```swift
|
||||
// BEFORE: GRDB 4
|
||||
var config = Configuration()
|
||||
config.trace = { ... } // Tracing SQL statements
|
||||
config.prepareDatabase = { db in // prepareDatabase was a property
|
||||
... // Custom setup
|
||||
}
|
||||
let dbQueue = try DatabaseQueue(path: dbPath, configuration: config)
|
||||
dbQueue.add(function: ...) // Custom SQL function
|
||||
dbQueue.add(collation: ...) // Custom collation
|
||||
dbQueue.add(tokenizer: ...) // Custom FTS5 tokenizer
|
||||
|
||||
// NEW: GRDB 5
|
||||
var config = Configuration()
|
||||
config.prepareDatabase { db in // prepareDatabase is now a method
|
||||
db.trace { ... }
|
||||
db.add(function: ...)
|
||||
db.add(collation: ...)
|
||||
db.add(tokenizer: ...)
|
||||
...
|
||||
}
|
||||
let dbQueue = try DatabaseQueue(dbPath, configuration: config)
|
||||
```
|
||||
|
||||
|
||||
## ValueObservation
|
||||
|
||||
[ValueObservation] is the database observation tool that tracks changes in database values. It has quite changed in GRDB 5.
|
||||
@@ -337,7 +367,7 @@ let publisher = observation
|
||||
|
||||
// NEW: GRDB 5
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
db.trace { print($0) }
|
||||
}
|
||||
let dbQueue = try DatabaseQueue(path: dbPath, configuration: config)
|
||||
|
||||
@@ -11,7 +11,7 @@ import GRDB
|
||||
//: Open a database connection
|
||||
|
||||
var configuration = Configuration()
|
||||
configuration.prepareDatabase = { db in
|
||||
configuration.prepareDatabase { db in
|
||||
db.trace { print("SQL> \($0)") }
|
||||
}
|
||||
let dbQueue = DatabaseQueue(configuration: configuration)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import GRDB
|
||||
|
||||
var configuration = Configuration()
|
||||
configuration.prepareDatabase = { db in
|
||||
configuration.prepareDatabase { db in
|
||||
db.trace { print("SQL> \($0)") }
|
||||
}
|
||||
let dbQueue = DatabaseQueue(configuration: configuration)
|
||||
|
||||
@@ -19,7 +19,7 @@ import CoreLocation
|
||||
|
||||
// Open an in-memory database that logs all SQL statements
|
||||
var configuration = Configuration()
|
||||
configuration.prepareDatabase = { db in
|
||||
configuration.prepareDatabase { db in
|
||||
db.trace { print("SQL> \($0)") }
|
||||
}
|
||||
let dbQueue = DatabaseQueue(configuration: configuration)
|
||||
|
||||
@@ -50,7 +50,7 @@ Since several processes may open the database at the same time, protect the crea
|
||||
|
||||
private func openDatabase(at databaseURL: URL) throws -> DatabasePool {
|
||||
var configuration = Configuration()
|
||||
configuration.prepareDatabase = { db in
|
||||
configuration.prepareDatabase { db in
|
||||
// Activate the persistent WAL mode so that
|
||||
// readonly processes can access the database.
|
||||
//
|
||||
@@ -179,7 +179,7 @@ See https://developer.apple.com/library/archive/technotes/tn2151/_index.html for
|
||||
|
||||
```swift
|
||||
var configuration = Configuration()
|
||||
configuration.prepareDatabase = { (db: Database) in
|
||||
configuration.prepareDatabase { (db: Database) in
|
||||
try db.usePassphrase("secret")
|
||||
try db.execute(sql: "PRAGMA cipher_plaintext_header_size = 32")
|
||||
}
|
||||
|
||||
@@ -103,16 +103,23 @@ public struct Configuration {
|
||||
|
||||
// MARK: - Managing SQLite Connections
|
||||
|
||||
/// A function that is run when an SQLite connection is opened, before the
|
||||
/// connection is made available for database access methods.
|
||||
private var setups: [(Database) throws -> Void] = []
|
||||
|
||||
/// The function argument is run when an SQLite connection is opened,
|
||||
/// before the connection is made available for database access methods.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// var config = Configuration()
|
||||
/// config.prepareDatabase = { db in
|
||||
/// config.prepareDatabase { db in
|
||||
/// try db.execute(sql: "PRAGMA kdf_iter = 10000")
|
||||
/// }
|
||||
public var prepareDatabase: ((Database) throws -> Void)?
|
||||
///
|
||||
/// This method can be called several times. The setup functions are run in
|
||||
/// the same order.
|
||||
public mutating func prepareDatabase(_ setup: @escaping (Database) throws -> Void) {
|
||||
setups.append(setup)
|
||||
}
|
||||
|
||||
// MARK: - Transactions
|
||||
|
||||
@@ -207,6 +214,12 @@ public struct Configuration {
|
||||
return threadingMode.SQLiteOpenFlags | readWriteFlags
|
||||
}
|
||||
|
||||
func setUp(_ db: Database) throws {
|
||||
for f in setups {
|
||||
try f(db)
|
||||
}
|
||||
}
|
||||
|
||||
func identifier(defaultLabel: String, purpose: String? = nil) -> String {
|
||||
(self.label ?? defaultLabel) + (purpose.map { "." + $0 } ?? "")
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
// MARK: - Database Setup
|
||||
|
||||
/// This method must be called after database initialization
|
||||
func setup() throws {
|
||||
func setUp() throws {
|
||||
setupBusyMode()
|
||||
setupDoubleQuotedStringLiterals()
|
||||
try setupForeignKeys()
|
||||
@@ -226,7 +226,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
#endif
|
||||
|
||||
// Last step before we can start accessing the database.
|
||||
try configuration.prepareDatabase?(self)
|
||||
try configuration.setUp(self)
|
||||
|
||||
try validateFormat()
|
||||
configuration.SQLiteConnectionDidOpen?()
|
||||
@@ -559,7 +559,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
|
||||
///
|
||||
/// // Trace all SQL statements executed by the database
|
||||
/// var configuration = Configuration()
|
||||
/// configuration.prepareDatabase = { db in
|
||||
/// configuration.prepareDatabase { db in
|
||||
/// db.trace(options: .statement) { event in
|
||||
/// print("SQL: \(event)")
|
||||
/// }
|
||||
@@ -1226,10 +1226,11 @@ extension Database {
|
||||
|
||||
/// Sets the passphrase used to crypt and decrypt an SQLCipher database.
|
||||
///
|
||||
/// Call this method from Configuration.prepareDatabase, as in the example below:
|
||||
/// Call this method from `Configuration.prepareDatabase`,
|
||||
/// as in the example below:
|
||||
///
|
||||
/// var config = Configuration()
|
||||
/// config.prepareDatabase = { db in
|
||||
/// config.prepareDatabase { db in
|
||||
/// try db.usePassphrase("secret")
|
||||
/// }
|
||||
public func usePassphrase(_ passphrase: String) throws {
|
||||
|
||||
@@ -75,8 +75,8 @@ public final class DatabaseFunction: Hashable {
|
||||
///
|
||||
/// let dbQueue = DatabaseQueue()
|
||||
/// let fn = DatabaseFunction("mysum", argumentCount: 1, aggregate: MySum.self)
|
||||
/// dbQueue.add(function: fn)
|
||||
/// try dbQueue.write { db in
|
||||
/// db.add(function: fn)
|
||||
/// try db.execute(sql: "CREATE TABLE test(i)")
|
||||
/// try db.execute(sql: "INSERT INTO test(i) VALUES (1)")
|
||||
/// try db.execute(sql: "INSERT INTO test(i) VALUES (2)")
|
||||
@@ -364,8 +364,8 @@ extension DatabaseFunction {
|
||||
///
|
||||
/// let dbQueue = DatabaseQueue()
|
||||
/// let fn = DatabaseFunction("mysum", argumentCount: 1, aggregate: MySum.self)
|
||||
/// dbQueue.add(function: fn)
|
||||
/// try dbQueue.write { db in
|
||||
/// db.add(function: fn)
|
||||
/// try db.execute(sql: "CREATE TABLE test(i)")
|
||||
/// try db.execute(sql: "INSERT INTO test(i) VALUES (1)")
|
||||
/// try db.execute(sql: "INSERT INTO test(i) VALUES (2)")
|
||||
|
||||
+38
-111
@@ -8,9 +8,6 @@ import UIKit
|
||||
public final class DatabasePool: DatabaseWriter {
|
||||
private let writer: SerializedDatabase
|
||||
private var readerPool: Pool<SerializedDatabase>!
|
||||
private var functions = Set<DatabaseFunction>()
|
||||
private var collations = Set<DatabaseCollation>()
|
||||
private var tokenizerRegistrations: [(Database) -> Void] = []
|
||||
|
||||
@LockedBox var databaseSnapshotCount = 0
|
||||
|
||||
@@ -50,51 +47,22 @@ public final class DatabasePool: DatabaseWriter {
|
||||
purpose: "writer")
|
||||
|
||||
// Readers
|
||||
var readerConfiguration = configuration
|
||||
readerConfiguration.readonly = true
|
||||
|
||||
// Readers use deferred transactions by default.
|
||||
// Other transaction kinds are forbidden by SQLite in read-only connections.
|
||||
readerConfiguration.defaultTransactionKind = .deferred
|
||||
var readerConfiguration = DatabasePool.readerConfiguration(configuration)
|
||||
|
||||
// Readers can't allow dangling transactions because there's no
|
||||
// guarantee that one can get the same reader later in order to close
|
||||
// an opened transaction.
|
||||
readerConfiguration.allowsUnsafeTransactions = false
|
||||
|
||||
// https://www.sqlite.org/wal.html#sometimes_queries_return_sqlite_busy_in_wal_mode
|
||||
// > But there are some obscure cases where a query against a WAL-mode
|
||||
// > database can return SQLITE_BUSY, so applications should be prepared
|
||||
// > for that happenstance.
|
||||
// >
|
||||
// > - If another database connection has the database mode open in
|
||||
// > exclusive locking mode [...]
|
||||
// > - When the last connection to a particular database is closing,
|
||||
// > that connection will acquire an exclusive lock for a short time
|
||||
// > while it cleans up the WAL and shared-memory files [...]
|
||||
// > - If the last connection to a database crashed, then the first new
|
||||
// > connection to open the database will start a recovery process. An
|
||||
// > exclusive lock is held during recovery. [...]
|
||||
//
|
||||
// The whole point of WAL readers is to avoid SQLITE_BUSY, so let's
|
||||
// setup a busy handler for pool readers, in order to workaround those
|
||||
// "obscure cases" that may happen when the database is shared between
|
||||
// multiple processes.
|
||||
if readerConfiguration.readonlyBusyMode == nil {
|
||||
readerConfiguration.readonlyBusyMode = .timeout(10)
|
||||
}
|
||||
|
||||
var readerCount = 0
|
||||
readerPool = Pool(maximumCount: configuration.maximumReaderCount, makeElement: { [unowned self] in
|
||||
readerCount += 1 // protected by pool (TODO: document this protection behavior)
|
||||
let reader = try SerializedDatabase(
|
||||
readerPool = Pool(maximumCount: configuration.maximumReaderCount, makeElement: {
|
||||
readerCount += 1 // protected by Pool (TODO: document this protection behavior)
|
||||
return try SerializedDatabase(
|
||||
path: path,
|
||||
configuration: readerConfiguration,
|
||||
schemaCache: DatabaseSchemaCache(),
|
||||
defaultLabel: "GRDB.DatabasePool",
|
||||
purpose: "reader.\(readerCount)")
|
||||
reader.sync { self.setupDatabase($0) }
|
||||
return reader
|
||||
})
|
||||
|
||||
// Activate WAL Mode unless readonly
|
||||
@@ -147,16 +115,40 @@ public final class DatabasePool: DatabaseWriter {
|
||||
readerPool = nil
|
||||
}
|
||||
|
||||
private func setupDatabase(_ db: Database) {
|
||||
for function in functions {
|
||||
db.add(function: function)
|
||||
}
|
||||
for collation in collations {
|
||||
db.add(collation: collation)
|
||||
}
|
||||
for registration in tokenizerRegistrations {
|
||||
registration(db)
|
||||
/// Returns a Configuration suitable for readonly connections on a
|
||||
/// WAL database.
|
||||
static func readerConfiguration(_ configuration: Configuration) -> Configuration {
|
||||
var configuration = configuration
|
||||
|
||||
configuration.readonly = true
|
||||
|
||||
// Readers use deferred transactions by default.
|
||||
// Other transaction kinds are forbidden by SQLite in read-only connections.
|
||||
configuration.defaultTransactionKind = .deferred
|
||||
|
||||
// https://www.sqlite.org/wal.html#sometimes_queries_return_sqlite_busy_in_wal_mode
|
||||
// > But there are some obscure cases where a query against a WAL-mode
|
||||
// > database can return SQLITE_BUSY, so applications should be prepared
|
||||
// > for that happenstance.
|
||||
// >
|
||||
// > - If another database connection has the database mode open in
|
||||
// > exclusive locking mode [...]
|
||||
// > - When the last connection to a particular database is closing,
|
||||
// > that connection will acquire an exclusive lock for a short time
|
||||
// > while it cleans up the WAL and shared-memory files [...]
|
||||
// > - If the last connection to a database crashed, then the first new
|
||||
// > connection to open the database will start a recovery process. An
|
||||
// > exclusive lock is held during recovery. [...]
|
||||
//
|
||||
// The whole point of WAL readers is to avoid SQLITE_BUSY, so let's
|
||||
// setup a busy handler for pool readers, in order to workaround those
|
||||
// "obscure cases" that may happen when the database is shared between
|
||||
// multiple processes.
|
||||
if configuration.readonlyBusyMode == nil {
|
||||
configuration.readonlyBusyMode = .timeout(10)
|
||||
}
|
||||
|
||||
return configuration
|
||||
}
|
||||
|
||||
/// Blocks the current thread until all database connections have
|
||||
@@ -794,53 +786,6 @@ extension DatabasePool: DatabaseReader {
|
||||
writer.weakAsync(updates)
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
|
||||
/// Add or redefine an SQL function.
|
||||
///
|
||||
/// let fn = DatabaseFunction("succ", argumentCount: 1) { dbValues in
|
||||
/// guard let int = Int.fromDatabaseValue(dbValues[0]) else {
|
||||
/// return nil
|
||||
/// }
|
||||
/// return int + 1
|
||||
/// }
|
||||
/// dbPool.add(function: fn)
|
||||
/// try dbPool.read { db in
|
||||
/// try Int.fetchOne(db, sql: "SELECT succ(1)") // 2
|
||||
/// }
|
||||
public func add(function: DatabaseFunction) {
|
||||
functions.update(with: function)
|
||||
forEachConnection { $0.add(function: function) }
|
||||
}
|
||||
|
||||
/// Remove an SQL function.
|
||||
public func remove(function: DatabaseFunction) {
|
||||
functions.remove(function)
|
||||
forEachConnection { $0.remove(function: function) }
|
||||
}
|
||||
|
||||
// MARK: - Collations
|
||||
|
||||
/// Add or redefine a collation.
|
||||
///
|
||||
/// let collation = DatabaseCollation("localized_standard") { (string1, string2) in
|
||||
/// return (string1 as NSString).localizedStandardCompare(string2)
|
||||
/// }
|
||||
/// dbPool.add(collation: collation)
|
||||
/// try dbPool.write { db in
|
||||
/// try db.execute(sql: "CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD")
|
||||
/// }
|
||||
public func add(collation: DatabaseCollation) {
|
||||
collations.update(with: collation)
|
||||
forEachConnection { $0.add(collation: collation) }
|
||||
}
|
||||
|
||||
/// Remove a collation.
|
||||
public func remove(collation: DatabaseCollation) {
|
||||
collations.remove(collation)
|
||||
forEachConnection { $0.remove(collation: collation) }
|
||||
}
|
||||
|
||||
// MARK: - Database Observation
|
||||
|
||||
/// :nodoc:
|
||||
@@ -1011,22 +956,6 @@ extension DatabasePool: DatabaseReader {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Custom FTS5 Tokenizers
|
||||
|
||||
#if SQLITE_ENABLE_FTS5
|
||||
/// Add a custom FTS5 tokenizer.
|
||||
///
|
||||
/// class MyTokenizer : FTS5CustomTokenizer { ... }
|
||||
/// dbPool.add(tokenizer: MyTokenizer.self)
|
||||
public func add<Tokenizer: FTS5CustomTokenizer>(tokenizer: Tokenizer.Type) {
|
||||
func registerTokenizer(db: Database) {
|
||||
db.add(tokenizer: Tokenizer.self)
|
||||
}
|
||||
tokenizerRegistrations.append(registerTokenizer)
|
||||
forEachConnection(registerTokenizer)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
extension DatabasePool {
|
||||
@@ -1101,12 +1030,10 @@ extension DatabasePool {
|
||||
}
|
||||
}
|
||||
|
||||
let snapshot = try DatabaseSnapshot(
|
||||
return try DatabaseSnapshot(
|
||||
path: path,
|
||||
configuration: writer.configuration,
|
||||
defaultLabel: "GRDB.DatabasePool",
|
||||
purpose: "snapshot.\($databaseSnapshotCount.increment())")
|
||||
snapshot.read { setupDatabase($0) }
|
||||
return snapshot
|
||||
}
|
||||
}
|
||||
@@ -427,49 +427,6 @@ extension DatabaseQueue {
|
||||
writer.weakAsync(updates)
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
|
||||
/// Add or redefine an SQL function.
|
||||
///
|
||||
/// let fn = DatabaseFunction("succ", argumentCount: 1) { dbValues in
|
||||
/// guard let int = Int.fromDatabaseValue(dbValues[0]) else {
|
||||
/// return nil
|
||||
/// }
|
||||
/// return int + 1
|
||||
/// }
|
||||
/// dbQueue.add(function: fn)
|
||||
/// try dbQueue.read { db in
|
||||
/// try Int.fetchOne(db, sql: "SELECT succ(1)") // 2
|
||||
/// }
|
||||
public func add(function: DatabaseFunction) {
|
||||
writer.sync { $0.add(function: function) }
|
||||
}
|
||||
|
||||
/// Remove an SQL function.
|
||||
public func remove(function: DatabaseFunction) {
|
||||
writer.sync { $0.remove(function: function) }
|
||||
}
|
||||
|
||||
// MARK: - Collations
|
||||
|
||||
/// Add or redefine a collation.
|
||||
///
|
||||
/// let collation = DatabaseCollation("localized_standard") { (string1, string2) in
|
||||
/// return (string1 as NSString).localizedStandardCompare(string2)
|
||||
/// }
|
||||
/// dbQueue.add(collation: collation)
|
||||
/// try dbQueue.write { db in
|
||||
/// try db.execute(sql: "CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD")
|
||||
/// }
|
||||
public func add(collation: DatabaseCollation) {
|
||||
writer.sync { $0.add(collation: collation) }
|
||||
}
|
||||
|
||||
/// Remove a collation.
|
||||
public func remove(collation: DatabaseCollation) {
|
||||
writer.sync { $0.remove(collation: collation) }
|
||||
}
|
||||
|
||||
// MARK: - Database Observation
|
||||
|
||||
/// :nodoc:
|
||||
|
||||
@@ -208,40 +208,6 @@ public protocol DatabaseReader: AnyObject {
|
||||
func unsafeReentrantRead<T>(_ block: (Database) throws -> T) throws -> T
|
||||
|
||||
|
||||
// MARK: - Functions
|
||||
|
||||
/// Add or redefine an SQL function.
|
||||
///
|
||||
/// let fn = DatabaseFunction("succ", argumentCount: 1) { dbValues in
|
||||
/// guard let int = Int.fromDatabaseValue(dbValues[0]) else {
|
||||
/// return nil
|
||||
/// }
|
||||
/// return int + 1
|
||||
/// }
|
||||
/// reader.add(function: fn)
|
||||
/// try reader.read { db in
|
||||
/// try Int.fetchOne(db, sql: "SELECT succ(1)")! // 2
|
||||
/// }
|
||||
func add(function: DatabaseFunction)
|
||||
|
||||
/// Remove an SQL function.
|
||||
func remove(function: DatabaseFunction)
|
||||
|
||||
|
||||
// MARK: - Collations
|
||||
|
||||
/// Add or redefine a collation.
|
||||
///
|
||||
/// let collation = DatabaseCollation("localized_standard") { (string1, string2) in
|
||||
/// return (string1 as NSString).localizedStandardCompare(string2)
|
||||
/// }
|
||||
/// reader.add(collation: collation)
|
||||
/// try reader.execute(sql: "SELECT * FROM file ORDER BY name COLLATE localized_standard")
|
||||
func add(collation: DatabaseCollation)
|
||||
|
||||
/// Remove a collation.
|
||||
func remove(collation: DatabaseCollation)
|
||||
|
||||
// MARK: - Value Observation
|
||||
|
||||
/// Starts a value observation.
|
||||
@@ -464,26 +430,6 @@ public final class AnyDatabaseReader: DatabaseReader {
|
||||
try base.unsafeReentrantRead(block)
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
|
||||
public func add(function: DatabaseFunction) {
|
||||
base.add(function: function)
|
||||
}
|
||||
|
||||
public func remove(function: DatabaseFunction) {
|
||||
base.remove(function: function)
|
||||
}
|
||||
|
||||
// MARK: - Collations
|
||||
|
||||
public func add(collation: DatabaseCollation) {
|
||||
base.add(collation: collation)
|
||||
}
|
||||
|
||||
public func remove(collation: DatabaseCollation) {
|
||||
base.remove(collation: collation)
|
||||
}
|
||||
|
||||
// MARK: - Value Observation
|
||||
|
||||
/// :nodoc:
|
||||
|
||||
@@ -18,32 +18,9 @@ public class DatabaseSnapshot: DatabaseReader {
|
||||
private(set) var version: UnsafeMutablePointer<sqlite3_snapshot>?
|
||||
|
||||
init(path: String, configuration: Configuration = Configuration(), defaultLabel: String, purpose: String) throws {
|
||||
var configuration = configuration
|
||||
configuration.readonly = true
|
||||
var configuration = DatabasePool.readerConfiguration(configuration)
|
||||
configuration.allowsUnsafeTransactions = true // Snaphost keeps a long-lived transaction
|
||||
|
||||
// https://www.sqlite.org/wal.html#sometimes_queries_return_sqlite_busy_in_wal_mode
|
||||
// > But there are some obscure cases where a query against a WAL-mode
|
||||
// > database can return SQLITE_BUSY, so applications should be prepared
|
||||
// > for that happenstance.
|
||||
// >
|
||||
// > - If another database connection has the database mode open in
|
||||
// > exclusive locking mode [...]
|
||||
// > - When the last connection to a particular database is closing,
|
||||
// > that connection will acquire an exclusive lock for a short time
|
||||
// > while it cleans up the WAL and shared-memory files [...]
|
||||
// > - If the last connection to a database crashed, then the first new
|
||||
// > connection to open the database will start a recovery process. An
|
||||
// > exclusive lock is held during recovery. [...]
|
||||
//
|
||||
// The whole point of WAL readers is to avoid SQLITE_BUSY, so let's
|
||||
// setup a busy handler for pool readers, in order to workaround those
|
||||
// "obscure cases" that may happen when the database is shared between
|
||||
// multiple processes.
|
||||
if configuration.readonlyBusyMode == nil {
|
||||
configuration.readonlyBusyMode = .timeout(10)
|
||||
}
|
||||
|
||||
|
||||
serializedDatabase = try SerializedDatabase(
|
||||
path: path,
|
||||
configuration: configuration,
|
||||
@@ -135,26 +112,6 @@ extension DatabaseSnapshot {
|
||||
try serializedDatabase.reentrantSync(block)
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
|
||||
public func add(function: DatabaseFunction) {
|
||||
serializedDatabase.sync { $0.add(function: function) }
|
||||
}
|
||||
|
||||
public func remove(function: DatabaseFunction) {
|
||||
serializedDatabase.sync { $0.remove(function: function) }
|
||||
}
|
||||
|
||||
// MARK: - Collations
|
||||
|
||||
public func add(collation: DatabaseCollation) {
|
||||
serializedDatabase.sync { $0.add(collation: collation) }
|
||||
}
|
||||
|
||||
public func remove(collation: DatabaseCollation) {
|
||||
serializedDatabase.sync { $0.remove(collation: collation) }
|
||||
}
|
||||
|
||||
// MARK: - Database Observation
|
||||
|
||||
/// :nodoc:
|
||||
|
||||
@@ -640,26 +640,6 @@ public final class AnyDatabaseWriter: DatabaseWriter {
|
||||
try base.unsafeReentrantWrite(updates)
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
|
||||
public func add(function: DatabaseFunction) {
|
||||
base.add(function: function)
|
||||
}
|
||||
|
||||
public func remove(function: DatabaseFunction) {
|
||||
base.remove(function: function)
|
||||
}
|
||||
|
||||
// MARK: - Collations
|
||||
|
||||
public func add(collation: DatabaseCollation) {
|
||||
base.add(collation: collation)
|
||||
}
|
||||
|
||||
public func remove(collation: DatabaseCollation) {
|
||||
base.remove(collation: collation)
|
||||
}
|
||||
|
||||
// MARK: - Database Observation
|
||||
|
||||
/// :nodoc:
|
||||
|
||||
@@ -53,7 +53,7 @@ final class SerializedDatabase {
|
||||
SchedulingWatchdog.allowDatabase(db, onQueue: queue)
|
||||
try queue.sync {
|
||||
do {
|
||||
try db.setup()
|
||||
try db.setUp()
|
||||
} catch {
|
||||
db.close()
|
||||
throw error
|
||||
|
||||
@@ -165,19 +165,4 @@ extension Database {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseQueue {
|
||||
|
||||
// MARK: - Custom FTS5 Tokenizers
|
||||
|
||||
/// Add a custom FTS5 tokenizer.
|
||||
///
|
||||
/// class MyTokenizer : FTS5CustomTokenizer { ... }
|
||||
/// dbQueue.add(tokenizer: MyTokenizer.self)
|
||||
public func add<Tokenizer: FTS5CustomTokenizer>(tokenizer: Tokenizer.Type) {
|
||||
inDatabase { db in
|
||||
db.add(tokenizer: Tokenizer.self)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -48,6 +48,12 @@ extension AssociationAggregate {
|
||||
}
|
||||
|
||||
extension Configuration {
|
||||
@available(*, unavailable, message: "Replace the assignment with a method call: prepareDatabase { db in ... }")
|
||||
public var prepareDatabase: ((Database) throws -> Void)? {
|
||||
get { preconditionFailure() }
|
||||
set { preconditionFailure() }
|
||||
}
|
||||
|
||||
@available(*, unavailable, message: "Use Database.trace(options:_:) in Configuration.prepareDatabase instead.")
|
||||
public var trace: TraceFunction? {
|
||||
get { preconditionFailure() }
|
||||
@@ -102,6 +108,25 @@ extension DatabaseQueue {
|
||||
#endif
|
||||
}
|
||||
|
||||
extension DatabaseReader {
|
||||
@available(*, unavailable, message: "Use Database.add(collation:) in Configuration.prepareDatabase instead.")
|
||||
public func add(collation: DatabaseCollation) { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable)
|
||||
public func remove(collation: DatabaseCollation) { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, message: "Use Database.add(function:) in Configuration.prepareDatabase instead.")
|
||||
public func add(function: DatabaseFunction) { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable)
|
||||
public func remove(function: DatabaseFunction) { preconditionFailure() }
|
||||
|
||||
#if SQLITE_ENABLE_FTS5
|
||||
@available(*, unavailable, message: "Use Database.add(tokenizer:) in Configuration.prepareDatabase instead.")
|
||||
public func add<Tokenizer: FTS5CustomTokenizer>(tokenizer: Tokenizer.Type) { preconditionFailure() }
|
||||
#endif
|
||||
}
|
||||
|
||||
extension FetchRequest {
|
||||
@available(*, unavailable, message: "Use makePreparedRequest(_:forSingleResult:) instead.")
|
||||
func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?)
|
||||
|
||||
@@ -1781,6 +1781,10 @@ SELECT maxLength(name) FROM player; -- custom aggregate
|
||||
|
||||
### Custom SQL Functions
|
||||
|
||||
A *function* argument takes an array of [DatabaseValue](#databasevalue), and returns any valid [value](#values) (Bool, Int, String, Date, Swift enums, etc.) The number of database values is guaranteed to be *argumentCount*.
|
||||
|
||||
SQLite has the opportunity to perform additional optimizations when functions are "pure", which means that their result only depends on their arguments. So make sure to set the *pure* argument to true when possible.
|
||||
|
||||
```swift
|
||||
let reverse = DatabaseFunction("reverse", argumentCount: 1, pure: true) { (values: [DatabaseValue]) in
|
||||
// Extract string value, if any...
|
||||
@@ -1790,7 +1794,16 @@ let reverse = DatabaseFunction("reverse", argumentCount: 1, pure: true) { (value
|
||||
// ... and return reversed string:
|
||||
return String(string.reversed())
|
||||
}
|
||||
dbQueue.add(function: reverse) // Or dbPool.add(function: ...)
|
||||
```
|
||||
|
||||
You make a function available to a database connection through its configuration:
|
||||
|
||||
```swift
|
||||
var config = Configuration()
|
||||
config.prepareDatabase { db in
|
||||
db.add(function: reverse)
|
||||
}
|
||||
let dbQueue = try DatabaseQueue(path: dbPath, configuration: config)
|
||||
|
||||
try dbQueue.read { db in
|
||||
// "oof"
|
||||
@@ -1798,10 +1811,6 @@ try dbQueue.read { db in
|
||||
}
|
||||
```
|
||||
|
||||
The *function* argument takes an array of [DatabaseValue](#databasevalue), and returns any valid [value](#values) (Bool, Int, String, Date, Swift enums, etc.) The number of database values is guaranteed to be *argumentCount*.
|
||||
|
||||
SQLite has the opportunity to perform additional optimizations when functions are "pure", which means that their result only depends on their arguments. So make sure to set the *pure* argument to true when possible.
|
||||
|
||||
|
||||
**Functions can take a variable number of arguments:**
|
||||
|
||||
@@ -1812,12 +1821,10 @@ let averageOf = DatabaseFunction("averageOf", pure: true) { (values: [DatabaseVa
|
||||
let doubles = values.compactMap { Double.fromDatabaseValue($0) }
|
||||
return doubles.reduce(0, +) / Double(doubles.count)
|
||||
}
|
||||
dbQueue.add(function: averageOf)
|
||||
db.add(function: averageOf)
|
||||
|
||||
try dbQueue.read { db in
|
||||
// 2.0
|
||||
try Double.fetchOne(db, sql: "SELECT averageOf(1, 2, 3)")!
|
||||
}
|
||||
// 2.0
|
||||
try Double.fetchOne(db, sql: "SELECT averageOf(1, 2, 3)")!
|
||||
```
|
||||
|
||||
|
||||
@@ -1833,12 +1840,10 @@ let sqrt = DatabaseFunction("sqrt", argumentCount: 1, pure: true) { (values: [Da
|
||||
}
|
||||
return sqrt(double)
|
||||
}
|
||||
dbQueue.add(function: sqrt)
|
||||
db.add(function: sqrt)
|
||||
|
||||
// SQLite error 1 with statement `SELECT sqrt(-1)`: invalid negative number
|
||||
try dbQueue.read { db in
|
||||
try Double.fetchOne(db, sql: "SELECT sqrt(-1)")!
|
||||
}
|
||||
try Double.fetchOne(db, sql: "SELECT sqrt(-1)")!
|
||||
```
|
||||
|
||||
|
||||
@@ -1898,8 +1903,16 @@ let maxLength = DatabaseFunction(
|
||||
argumentCount: 1,
|
||||
pure: true,
|
||||
aggregate: MaxLength.self)
|
||||
```
|
||||
|
||||
dbQueue.add(function: maxLength) // Or dbPool.add(function: ...)
|
||||
Like [custom SQL Functions](#custom-sql-functions), you make an aggregate function available to a database connection through its configuration:
|
||||
|
||||
```swift
|
||||
var config = Configuration()
|
||||
config.prepareDatabase { db in
|
||||
db.add(function: maxLength)
|
||||
}
|
||||
let dbQueue = try DatabaseQueue(path: dbPath, configuration: config)
|
||||
|
||||
try dbQueue.read { db in
|
||||
// Some Int
|
||||
@@ -6221,7 +6234,7 @@ pod 'SQLCipher', '~> 3.4'
|
||||
|
||||
```swift
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try DatabaseQueue(path: dbPath, configuration: config)
|
||||
@@ -6231,7 +6244,7 @@ It is also in `prepareDatabase` that you perform other [SQLCipher configuration
|
||||
|
||||
```swift
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
try db.execute(sql: "PRAGMA cipher_page_size = ...")
|
||||
try db.execute(sql: "PRAGMA kdf_iter = ...")
|
||||
@@ -6244,7 +6257,7 @@ When you want to open an existing SQLCipher 3 database with SQLCipher 4, you may
|
||||
```swift
|
||||
// Open an SQLCipher 3 database with SQLCipher 4
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
try db.execute(sql: "PRAGMA cipher_compatibility = 3")
|
||||
}
|
||||
@@ -6281,13 +6294,13 @@ try dbPool.barrierWriteWithoutTransaction { db in
|
||||
> // WRONG: this won't work across a passphrase change
|
||||
> let passphrase = try getPassphrase()
|
||||
> var config = Configuration()
|
||||
> config.prepareDatabase = { db in
|
||||
> config.prepareDatabase { db in
|
||||
> try db.usePassphrase(passphrase)
|
||||
> }
|
||||
>
|
||||
> // CORRECT: get the latest passphrase when it is needed
|
||||
> var config = Configuration()
|
||||
> config.prepareDatabase = { db in
|
||||
> config.prepareDatabase { db in
|
||||
> let passphrase = try getPassphrase()
|
||||
> try db.usePassphrase(passphrase)
|
||||
> }
|
||||
@@ -6314,7 +6327,7 @@ let existingDBQueue = try DatabaseQueue(path: "/path/to/existing.db")
|
||||
|
||||
// The new encrypted database, at some distinct location:
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let newDBQueue = try DatabaseQueue(path: "/path/to/new.db", configuration: config)
|
||||
@@ -6337,19 +6350,19 @@ try existingDBQueue.inDatabase { db in
|
||||
|
||||
#### Managing the lifetime of the passphrase string
|
||||
|
||||
It is recommended to avoid keeping the passphrase in memory longer than necessary. To do this, make sure you load the passphrase from inside the `prepareDatabase` function:
|
||||
It is recommended to avoid keeping the passphrase in memory longer than necessary. To do this, make sure you load the passphrase from the `prepareDatabase` method:
|
||||
|
||||
```swift
|
||||
// NOT RECOMMENDED: this keeps the passphrase in memory longer than necessary
|
||||
let passphrase = try getPassphrase()
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase(passphrase)
|
||||
}
|
||||
|
||||
// RECOMMENDED: only load the passphrase when it is needed
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
let passphrase = try getPassphrase()
|
||||
try db.usePassphrase(passphrase)
|
||||
}
|
||||
@@ -6368,7 +6381,7 @@ For example:
|
||||
|
||||
```swift
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
... // Carefully load passphrase bytes
|
||||
let code = sqlite3_key(db.sqliteConnection, /* passphrase bytes */)
|
||||
... // Carefully dispose passphrase bytes
|
||||
@@ -6389,7 +6402,7 @@ Such protection prevents GRDB from creating SQLite connections when the passphra
|
||||
|
||||
```swift
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
let passphrase = try loadPassphraseFromSystemKeychain()
|
||||
try db.usePassphrase(passphrase)
|
||||
}
|
||||
@@ -6851,8 +6864,15 @@ let players = try Player.order(nameColumn.collating(collation)).fetchAll(db)
|
||||
let collation = DatabaseCollation("customCollation") { (lhs, rhs) -> NSComparisonResult in
|
||||
// return the comparison of lhs and rhs strings.
|
||||
}
|
||||
dbQueue.add(collation: collation) // Or dbPool.add(collation: ...)
|
||||
```
|
||||
|
||||
// Make the collation available to a database connection
|
||||
var config = Configuration()
|
||||
config.prepareDatabase { db in
|
||||
db.add(collation: collation)
|
||||
}
|
||||
let dbQueue = try DatabaseQueue(path: dbPath, configuration: config)
|
||||
-```
|
||||
|
||||
|
||||
|
||||
## Memory Management
|
||||
@@ -7572,7 +7592,7 @@ Another option is to setup a tracing function that prints out the executed SQL r
|
||||
```swift
|
||||
// Prints all SQL statements
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
db.trace { print($0) }
|
||||
}
|
||||
let dbQueue = try DatabaseQueue(path: dbPath, configuration: config)
|
||||
@@ -7609,7 +7629,7 @@ Use the `trace(options:_:)` method, with the `.profile` option:
|
||||
|
||||
```swift
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
db.trace(options: .profile) { event in
|
||||
// Prints all SQL statements with their duration
|
||||
print(event)
|
||||
|
||||
@@ -8,15 +8,15 @@ class DatabaseAbortedTransactionTests : GRDBTestCase {
|
||||
let semaphore1 = DispatchSemaphore(value: 0)
|
||||
let semaphore2 = DispatchSemaphore(value: 0)
|
||||
|
||||
dbReader.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
let block1 = {
|
||||
do {
|
||||
_ = try dbReader.read {
|
||||
try Row.fetchAll($0, sql: "SELECT wait()")
|
||||
try dbReader.read { db in
|
||||
db.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
_ = try Row.fetchAll(db, sql: "SELECT wait()")
|
||||
}
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError {
|
||||
@@ -47,13 +47,13 @@ class DatabaseAbortedTransactionTests : GRDBTestCase {
|
||||
let semaphore1 = DispatchSemaphore(value: 0)
|
||||
let semaphore2 = DispatchSemaphore(value: 0)
|
||||
|
||||
dbReader.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
let block1 = {
|
||||
try! dbReader.read { db in
|
||||
db.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
let wasInTransaction = db.isInsideTransaction
|
||||
do {
|
||||
_ = try Row.fetchAll(db, sql: "SELECT wait()")
|
||||
@@ -95,14 +95,14 @@ class DatabaseAbortedTransactionTests : GRDBTestCase {
|
||||
let semaphore1 = DispatchSemaphore(value: 0)
|
||||
let semaphore2 = DispatchSemaphore(value: 0)
|
||||
|
||||
dbWriter.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
let block1 = {
|
||||
do {
|
||||
try dbWriter.write { db in
|
||||
db.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
try db.execute(sql: "INSERT INTO t SELECT wait()")
|
||||
}
|
||||
XCTFail("Expected error")
|
||||
@@ -142,15 +142,15 @@ class DatabaseAbortedTransactionTests : GRDBTestCase {
|
||||
let semaphore1 = DispatchSemaphore(value: 0)
|
||||
let semaphore2 = DispatchSemaphore(value: 0)
|
||||
|
||||
dbWriter.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
let block1 = {
|
||||
do {
|
||||
try dbWriter.write { db in
|
||||
do {
|
||||
db.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
try db.execute(sql: "INSERT INTO t SELECT wait()")
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError {
|
||||
@@ -220,13 +220,13 @@ class DatabaseAbortedTransactionTests : GRDBTestCase {
|
||||
let semaphore1 = DispatchSemaphore(value: 0)
|
||||
let semaphore2 = DispatchSemaphore(value: 0)
|
||||
|
||||
dbWriter.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
let block1 = {
|
||||
try! dbWriter.writeWithoutTransaction { db in
|
||||
db.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
try db.inTransaction {
|
||||
do {
|
||||
try db.execute(sql: "INSERT INTO t SELECT wait()")
|
||||
|
||||
@@ -21,9 +21,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { nil }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try DatabaseValue.fetchOne(db, sql: "SELECT f()")!.isNull)
|
||||
}
|
||||
}
|
||||
@@ -34,9 +34,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { Int64(1) }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f()")!, Int64(1))
|
||||
}
|
||||
}
|
||||
@@ -47,9 +47,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func step(_ values: [DatabaseValue]) { }
|
||||
func finalize() -> DatabaseValueConvertible? { 1e100 }
|
||||
}
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f()")!, 1e100)
|
||||
}
|
||||
}
|
||||
@@ -60,9 +60,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { "foo" }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f()")!, "foo")
|
||||
}
|
||||
}
|
||||
@@ -75,9 +75,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f()")!, "foo".data(using: .utf8))
|
||||
}
|
||||
}
|
||||
@@ -88,9 +88,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { CustomValueType() }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f()") != nil)
|
||||
}
|
||||
}
|
||||
@@ -106,9 +106,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { result }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try Bool.fetchOne(db, sql: "SELECT f(NULL)")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(1)")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(1.1)")!)
|
||||
@@ -127,9 +127,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { result }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try Int64.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f(1)")!, 1)
|
||||
XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f(1.1)")!, 1)
|
||||
@@ -145,9 +145,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { result }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try Double.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f(1)")!, 1.0)
|
||||
XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f(1.1)")!, 1.1)
|
||||
@@ -163,9 +163,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { result }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try String.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f('foo')")!, "foo")
|
||||
}
|
||||
@@ -180,9 +180,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { result }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try Data.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!, "foo".data(using: .utf8))
|
||||
XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f(?)", arguments: [Data()])!, Data())
|
||||
@@ -198,9 +198,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { result }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f('CustomValueType')") != nil)
|
||||
}
|
||||
@@ -214,9 +214,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { "foo" }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f()")!, "foo")
|
||||
do {
|
||||
try db.execute(sql: "SELECT f(1)")
|
||||
@@ -239,9 +239,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { result }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT upper(?)", arguments: ["Roué"])!, "ROUé")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f(?)", arguments: ["Roué"])!, "ROUÉ")
|
||||
XCTAssertTrue(try String.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
@@ -267,9 +267,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { result }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 2, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 2, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1, 2)")!, 3)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
@@ -292,9 +292,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { result }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f()")!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1)")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1, 1)")!, 2)
|
||||
@@ -311,9 +311,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { fatalError() }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
@@ -332,9 +332,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { fatalError() }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
@@ -353,9 +353,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { fatalError() }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
@@ -374,9 +374,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() -> DatabaseValueConvertible? { fatalError() }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
@@ -399,9 +399,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
@@ -420,9 +420,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
@@ -441,9 +441,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
@@ -462,9 +462,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
@@ -490,9 +490,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() throws -> DatabaseValueConvertible? { sum }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(a) FROM (SELECT 1 AS a UNION ALL SELECT 2 UNION ALL SELECT 3)")!, 6)
|
||||
}
|
||||
}
|
||||
@@ -508,9 +508,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
func finalize() throws -> DatabaseValueConvertible? { sum }
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
let row = try Row.fetchOne(db, sql: "SELECT f(a), f(b) FROM (SELECT 1 AS a, 2 AS b UNION ALL SELECT 2, 4 UNION ALL SELECT 3, 6)")!
|
||||
XCTAssertEqual(row[0], 6)
|
||||
XCTAssertEqual(row[1], 12)
|
||||
@@ -539,9 +539,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(allocationCount, 0)
|
||||
XCTAssertEqual(aliveCount, 0)
|
||||
try db.execute(sql: "SELECT f()")
|
||||
@@ -572,9 +572,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(allocationCount, 0)
|
||||
XCTAssertEqual(aliveCount, 0)
|
||||
_ = try? db.execute(sql: "SELECT f()")
|
||||
@@ -606,9 +606,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
dbQueue.inDatabase { db in
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(allocationCount, 0)
|
||||
XCTAssertEqual(aliveCount, 0)
|
||||
_ = try? db.execute(sql: "SELECT f()")
|
||||
|
||||
@@ -54,9 +54,9 @@ class DatabaseCollationTests: GRDBTestCase {
|
||||
return .orderedDescending
|
||||
}
|
||||
}
|
||||
dbQueue.add(collation: collation)
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(collation: collation)
|
||||
try db.execute(sql: "CREATE TABLE strings (id INTEGER PRIMARY KEY, name TEXT COLLATE LOCALIZED_STANDARD)")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (1, 'a')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (2, 'aa')")
|
||||
|
||||
@@ -8,7 +8,7 @@ class DatabaseConfigurationTests: GRDBTestCase {
|
||||
// prepareDatabase is called when connection opens
|
||||
var connectionCount = 0
|
||||
var configuration = Configuration()
|
||||
configuration.prepareDatabase = { db in
|
||||
configuration.prepareDatabase { db in
|
||||
connectionCount += 1
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class DatabaseConfigurationTests: GRDBTestCase {
|
||||
var error: TestError?
|
||||
|
||||
var configuration = Configuration()
|
||||
configuration.prepareDatabase = { db in
|
||||
configuration.prepareDatabase { db in
|
||||
if let error = error {
|
||||
throw error
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ class DatabaseCursorTests: GRDBTestCase {
|
||||
func testStepError() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
let cursor = try Int.fetchCursor(db, sql: "SELECT throw()")
|
||||
do {
|
||||
_ = try cursor.next()
|
||||
@@ -51,8 +51,8 @@ class DatabaseCursorTests: GRDBTestCase {
|
||||
func testStepDatabaseError() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = DatabaseError(resultCode: ResultCode(rawValue: 0xDEAD), message: "custom error")
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
let cursor = try Int.fetchCursor(db, sql: "SELECT throw()")
|
||||
do {
|
||||
_ = try cursor.next()
|
||||
|
||||
@@ -53,8 +53,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0) { dbValues in
|
||||
return nil
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try DatabaseValue.fetchOne(db, sql: "SELECT f()")!.isNull)
|
||||
}
|
||||
}
|
||||
@@ -64,8 +64,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0) { dbValues in
|
||||
return Int64(1)
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f()")!, Int64(1))
|
||||
}
|
||||
}
|
||||
@@ -75,8 +75,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0) { dbValues in
|
||||
return 1e100
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f()")!, 1e100)
|
||||
}
|
||||
}
|
||||
@@ -86,8 +86,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0) { dbValues in
|
||||
return "foo"
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f()")!, "foo")
|
||||
}
|
||||
}
|
||||
@@ -97,8 +97,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0) { dbValues in
|
||||
return "foo".data(using: .utf8)
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f()")!, "foo".data(using: .utf8))
|
||||
}
|
||||
}
|
||||
@@ -108,8 +108,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0) { dbValues in
|
||||
return CustomValueType()
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f()") != nil)
|
||||
}
|
||||
}
|
||||
@@ -121,8 +121,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1) { (dbValues: [DatabaseValue]) in
|
||||
return dbValues[0].isNull
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try Bool.fetchOne(db, sql: "SELECT f(NULL)")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(1)")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(1.1)")!)
|
||||
@@ -137,8 +137,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1) { (dbValues: [DatabaseValue]) in
|
||||
return Int64.fromDatabaseValue(dbValues[0])
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try Int64.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f(1)")!, 1)
|
||||
XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f(1.1)")!, 1)
|
||||
@@ -150,8 +150,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1) { (dbValues: [DatabaseValue]) in
|
||||
return Double.fromDatabaseValue(dbValues[0])
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try Double.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f(1)")!, 1.0)
|
||||
XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f(1.1)")!, 1.1)
|
||||
@@ -163,8 +163,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1) { (dbValues: [DatabaseValue]) in
|
||||
return String.fromDatabaseValue(dbValues[0])
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try String.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f('foo')")!, "foo")
|
||||
}
|
||||
@@ -175,8 +175,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1) { (dbValues: [DatabaseValue]) in
|
||||
return Data.fromDatabaseValue(dbValues[0])
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try Data.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!, "foo".data(using: .utf8))
|
||||
XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f(?)", arguments: [Data()])!, Data())
|
||||
@@ -188,8 +188,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1) { (dbValues: [DatabaseValue]) in
|
||||
return CustomValueType.fromDatabaseValue(dbValues[0])
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f('CustomValueType')") != nil)
|
||||
}
|
||||
@@ -202,8 +202,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0) { dbValues in
|
||||
return "foo"
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f()")!, "foo")
|
||||
do {
|
||||
try db.execute(sql: "SELECT f(1)")
|
||||
@@ -222,8 +222,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1) { (dbValues: [DatabaseValue]) in
|
||||
String.fromDatabaseValue(dbValues[0]).map { $0.uppercased() }
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT upper(?)", arguments: ["Roué"])!, "ROUé")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f(?)", arguments: ["Roué"])!, "ROUÉ")
|
||||
XCTAssertTrue(try String.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
@@ -245,8 +245,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let ints = dbValues.compactMap { Int.fromDatabaseValue($0) }
|
||||
return ints.reduce(0, +)
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1, 2)")!, 3)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
@@ -265,8 +265,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f") { dbValues in
|
||||
return dbValues.count
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f()")!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1)")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1, 1)")!, 2)
|
||||
@@ -280,8 +280,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f") { dbValues in
|
||||
throw DatabaseError(message: "custom error message")
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
@@ -297,8 +297,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f") { dbValues in
|
||||
throw DatabaseError(resultCode: ResultCode(rawValue: 123))
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
@@ -314,8 +314,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f") { dbValues in
|
||||
throw DatabaseError(resultCode: ResultCode(rawValue: 123), message: "custom error message")
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
@@ -331,8 +331,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f") { dbValues in
|
||||
throw NSError(domain: "CustomErrorDomain", code: 123, userInfo: [NSLocalizedDescriptionKey: "custom error message"])
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
do {
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
@@ -353,8 +353,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0) { dbValues in
|
||||
return x
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
x = 321
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f()")!, 321)
|
||||
}
|
||||
|
||||
@@ -486,7 +486,7 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
}
|
||||
|
||||
// Apply 1st migrator
|
||||
dbConfiguration.prepareDatabase = { db in
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
let function = DatabaseFunction("testFunction", argumentCount: 0, pure: true) { _ in "Arthur" }
|
||||
db.add(function: function)
|
||||
}
|
||||
|
||||
@@ -4,18 +4,19 @@ import GRDB
|
||||
class DatabasePoolCollationTests: GRDBTestCase {
|
||||
|
||||
func testCollationIsSharedBetweenWriterAndReaders() throws {
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
let collation1 = DatabaseCollation("collation1") { (string1, string2) in
|
||||
return (string1 == string2) ? .orderedSame : ((string1 < string2) ? .orderedAscending : .orderedDescending)
|
||||
}
|
||||
db.add(collation: collation1)
|
||||
|
||||
let collation2 = DatabaseCollation("collation2") { (string1, string2) in
|
||||
return (string1 == string2) ? .orderedSame : ((string1 < string2) ? .orderedDescending : .orderedAscending)
|
||||
}
|
||||
db.add(collation: collation2)
|
||||
}
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
let collation1 = DatabaseCollation("collation1") { (string1, string2) in
|
||||
return (string1 == string2) ? .orderedSame : ((string1 < string2) ? .orderedAscending : .orderedDescending)
|
||||
}
|
||||
dbPool.add(collation: collation1)
|
||||
|
||||
let collation2 = DatabaseCollation("collation2") { (string1, string2) in
|
||||
return (string1 == string2) ? .orderedSame : ((string1 < string2) ? .orderedDescending : .orderedAscending)
|
||||
}
|
||||
dbPool.add(collation: collation2)
|
||||
|
||||
try dbPool.write { db in
|
||||
// Both collations are available in writer
|
||||
try db.execute(sql: """
|
||||
@@ -34,27 +35,5 @@ class DatabasePoolCollationTests: GRDBTestCase {
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1"), ["a", "b", "c"])
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation2"), ["c", "b", "a"])
|
||||
}
|
||||
|
||||
dbPool.remove(collation: collation1)
|
||||
|
||||
do {
|
||||
// collation1 is no longer available in writer
|
||||
try dbPool.write { db in
|
||||
_ = try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1")
|
||||
}
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
XCTAssert(error.message!.contains("collation1"))
|
||||
}
|
||||
|
||||
do {
|
||||
// collation1 is no longer available in reader
|
||||
try dbPool.read { db in
|
||||
_ = try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1")
|
||||
}
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
XCTAssert(error.message!.contains("collation1"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,13 @@ import GRDB
|
||||
class DatabasePoolFunctionTests: GRDBTestCase {
|
||||
|
||||
func testFunctionIsSharedBetweenWriterAndReaders() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
let function1 = DatabaseFunction("function1", argumentCount: 1, pure: true) { (dbValues: [DatabaseValue]) in
|
||||
return dbValues[0]
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
db.add(function: DatabaseFunction("function1", argumentCount: 1, pure: true) { (dbValues: [DatabaseValue]) in
|
||||
return dbValues[0]
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
dbPool.add(function: function1)
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.execute(sql: "CREATE TABLE items (text TEXT)")
|
||||
@@ -19,14 +19,5 @@ class DatabasePoolFunctionTests: GRDBTestCase {
|
||||
try dbPool.read { db in
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT function1(text) FROM items")!, "a")
|
||||
}
|
||||
|
||||
let function2 = DatabaseFunction("function2", argumentCount: 1, pure: true) { (dbValues: [DatabaseValue]) in
|
||||
return "foo"
|
||||
}
|
||||
dbPool.add(function: function2)
|
||||
|
||||
try dbPool.read { db in
|
||||
XCTAssertTrue(try String.fetchOne(db, sql: "SELECT function2(text) FROM items") == "foo")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class DatabasePoolTests: GRDBTestCase {
|
||||
func testPersistentWALModeEnabled() throws {
|
||||
let path: String
|
||||
do {
|
||||
dbConfiguration.prepareDatabase = { db in
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
var flag: CInt = 1
|
||||
let code = withUnsafeMutablePointer(to: &flag) { flagP in
|
||||
sqlite3_file_control(db.sqliteConnection, nil, SQLITE_FCNTL_PERSIST_WAL, flagP)
|
||||
@@ -35,7 +35,7 @@ class DatabasePoolTests: GRDBTestCase {
|
||||
func testPersistentWALModeDisabled() throws {
|
||||
let path: String
|
||||
do {
|
||||
dbConfiguration.prepareDatabase = { db in
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
var flag: CInt = 0
|
||||
let code = withUnsafeMutablePointer(to: &flag) { flagP in
|
||||
sqlite3_file_control(db.sqliteConnection, nil, SQLITE_FCNTL_PERSIST_WAL, flagP)
|
||||
|
||||
@@ -34,11 +34,11 @@ class DatabaseQueueTests: GRDBTestCase {
|
||||
}
|
||||
return int + 1
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: fn)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT succ(1)"), 2) // 2
|
||||
db.remove(function: fn)
|
||||
}
|
||||
dbQueue.remove(function: fn)
|
||||
do {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(sql: "SELECT succ(1)")
|
||||
@@ -61,11 +61,11 @@ class DatabaseQueueTests: GRDBTestCase {
|
||||
let collation = DatabaseCollation("test_collation_foo") { (string1, string2) in
|
||||
return (string1 as NSString).localizedStandardCompare(string2)
|
||||
}
|
||||
dbQueue.add(collation: collation)
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(collation: collation)
|
||||
try db.execute(sql: "CREATE TABLE files (name TEXT COLLATE TEST_COLLATION_FOO)")
|
||||
db.remove(collation: collation)
|
||||
}
|
||||
dbQueue.remove(collation: collation)
|
||||
do {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(sql: "CREATE TABLE files_fail (name TEXT COLLATE TEST_COLLATION_FOO)")
|
||||
|
||||
@@ -163,10 +163,10 @@ class DatabaseReaderTests : GRDBTestCase {
|
||||
|
||||
func testAddFunction() throws {
|
||||
func test(_ dbReader: DatabaseReader) throws {
|
||||
let f = DatabaseFunction("f", argumentCount: 0, pure: true) { _ in 0 }
|
||||
dbReader.add(function: f)
|
||||
let value = try dbReader.read { db in
|
||||
try Int.fetchOne(db, sql: "SELECT f()")
|
||||
let value = try dbReader.read { db -> Int? in
|
||||
let f = DatabaseFunction("f", argumentCount: 0, pure: true) { _ in 0 }
|
||||
db.add(function: f)
|
||||
return try Int.fetchOne(db, sql: "SELECT f()")
|
||||
}
|
||||
XCTAssertEqual(value, 0)
|
||||
}
|
||||
@@ -180,10 +180,10 @@ class DatabaseReaderTests : GRDBTestCase {
|
||||
|
||||
func testAddCollation() throws {
|
||||
func test(_ dbReader: DatabaseReader) throws {
|
||||
let collation = DatabaseCollation("c") { _, _ in .orderedSame }
|
||||
dbReader.add(collation: collation)
|
||||
let value = try dbReader.read { db in
|
||||
try Int.fetchOne(db, sql: "SELECT 'foo' AS str ORDER BY str COLLATE c")
|
||||
let value = try dbReader.read { db -> Int? in
|
||||
let collation = DatabaseCollation("c") { _, _ in .orderedSame }
|
||||
db.add(collation: collation)
|
||||
return try Int.fetchOne(db, sql: "SELECT 'foo' AS str ORDER BY str COLLATE c")
|
||||
}
|
||||
XCTAssertEqual(value, 0)
|
||||
}
|
||||
|
||||
@@ -132,9 +132,11 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
// MARK: - Functions
|
||||
|
||||
func testSnapshotInheritPoolFunctions() throws {
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
let function = DatabaseFunction("foo", argumentCount: 0, pure: true) { _ in return "foo" }
|
||||
db.add(function: function)
|
||||
}
|
||||
let dbPool = try makeDatabasePool()
|
||||
let function = DatabaseFunction("foo", argumentCount: 0, pure: true) { _ in return "foo" }
|
||||
dbPool.add(function: function)
|
||||
|
||||
let snapshot = try dbPool.makeSnapshot()
|
||||
try snapshot.read { db in
|
||||
@@ -142,24 +144,16 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testSnapshotFunctions() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
let snapshot = try dbPool.makeSnapshot()
|
||||
let function = DatabaseFunction("foo", argumentCount: 0, pure: true) { _ in return "foo" }
|
||||
snapshot.add(function: function)
|
||||
try snapshot.read { db in
|
||||
try XCTAssertEqual(String.fetchOne(db, sql: "SELECT foo()")!, "foo")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Collations
|
||||
|
||||
func testSnapshotInheritPoolCollations() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
let collation = DatabaseCollation("reverse") { (string1, string2) in
|
||||
return (string1 == string2) ? .orderedSame : ((string1 < string2) ? .orderedDescending : .orderedAscending)
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
let collation = DatabaseCollation("reverse") { (string1, string2) in
|
||||
return (string1 == string2) ? .orderedSame : ((string1 < string2) ? .orderedDescending : .orderedAscending)
|
||||
}
|
||||
db.add(collation: collation)
|
||||
}
|
||||
dbPool.add(collation: collation)
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.execute(sql: "CREATE TABLE items (text TEXT)")
|
||||
@@ -174,25 +168,6 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testSnapshotCollations() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(sql: "CREATE TABLE items (text TEXT)")
|
||||
try db.execute(sql: "INSERT INTO items (text) VALUES ('a')")
|
||||
try db.execute(sql: "INSERT INTO items (text) VALUES ('b')")
|
||||
try db.execute(sql: "INSERT INTO items (text) VALUES ('c')")
|
||||
}
|
||||
|
||||
let snapshot = try dbPool.makeSnapshot()
|
||||
let collation = DatabaseCollation("reverse") { (string1, string2) in
|
||||
return (string1 == string2) ? .orderedSame : ((string1 < string2) ? .orderedDescending : .orderedAscending)
|
||||
}
|
||||
snapshot.add(collation: collation)
|
||||
try snapshot.read { db in
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE reverse"), ["c", "b", "a"])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Concurrency
|
||||
|
||||
func testReadBlockIsolationStartingWithRead() throws {
|
||||
|
||||
@@ -265,11 +265,13 @@ class DatabaseSuspensionTests : GRDBTestCase {
|
||||
func test(_ dbQueue: DatabaseQueue) throws {
|
||||
let semaphore1 = DispatchSemaphore(value: 0)
|
||||
let semaphore2 = DispatchSemaphore(value: 0)
|
||||
dbQueue.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
dbQueue.inDatabase { db in
|
||||
db.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
let block1 = {
|
||||
do {
|
||||
@@ -306,11 +308,13 @@ class DatabaseSuspensionTests : GRDBTestCase {
|
||||
let semaphore1 = DispatchSemaphore(value: 0)
|
||||
let semaphore2 = DispatchSemaphore(value: 0)
|
||||
|
||||
dbQueue.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
dbQueue.inDatabase { db in
|
||||
db.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
let block1 = {
|
||||
do {
|
||||
try dbQueue.inTransaction { db in
|
||||
@@ -348,11 +352,13 @@ class DatabaseSuspensionTests : GRDBTestCase {
|
||||
let semaphore1 = DispatchSemaphore(value: 0)
|
||||
let semaphore2 = DispatchSemaphore(value: 0)
|
||||
|
||||
dbQueue.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
dbQueue.inDatabase { db in
|
||||
db.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
let block1 = {
|
||||
do {
|
||||
try dbQueue.write { db in
|
||||
@@ -391,11 +397,13 @@ class DatabaseSuspensionTests : GRDBTestCase {
|
||||
let semaphore1 = DispatchSemaphore(value: 0)
|
||||
let semaphore2 = DispatchSemaphore(value: 0)
|
||||
|
||||
dbQueue.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
dbQueue.inDatabase { db in
|
||||
db.add(function: DatabaseFunction("wait", argumentCount: 0, pure: true) { _ in
|
||||
semaphore1.signal()
|
||||
semaphore2.wait()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
let block1 = {
|
||||
do {
|
||||
try dbQueue.write { db in
|
||||
@@ -475,7 +483,7 @@ class DatabaseSuspensionTests : GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
var configuration = Configuration()
|
||||
configuration.prepareDatabase = { db in
|
||||
configuration.prepareDatabase { db in
|
||||
try db.execute(sql: "PRAGMA journal_mode=truncate")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(configuration: configuration)
|
||||
|
||||
@@ -119,7 +119,7 @@ class DatabaseTraceTests : GRDBTestCase {
|
||||
func testTraceFromConfigurationWithDefaultOptions() throws {
|
||||
var events: [String] = []
|
||||
var configuration = Configuration()
|
||||
configuration.prepareDatabase = { db in
|
||||
configuration.prepareDatabase { db in
|
||||
db.trace { event in
|
||||
events.append("SQL: \(event)")
|
||||
}
|
||||
|
||||
@@ -61,9 +61,9 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testFetchCursorStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ cursor: DatabaseValueCursor<Fetched>, sql: String) throws {
|
||||
do {
|
||||
_ = try cursor.next()
|
||||
@@ -169,9 +169,9 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testFetchAllStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ array: @autoclosure () throws -> [Fetched], sql: String) throws {
|
||||
do {
|
||||
_ = try array()
|
||||
@@ -270,9 +270,9 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testFetchSetStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ set: @autoclosure () throws -> Set<Fetched>, sql: String) throws {
|
||||
do {
|
||||
_ = try set()
|
||||
@@ -417,9 +417,9 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testFetchOneStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ value: @autoclosure () throws -> Fetched?, sql: String) throws {
|
||||
do {
|
||||
_ = try value()
|
||||
@@ -524,9 +524,9 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testOptionalFetchCursorStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ cursor: NullableDatabaseValueCursor<Fetched>, sql: String) throws {
|
||||
do {
|
||||
_ = try cursor.next()
|
||||
@@ -634,9 +634,9 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testOptionalFetchAllStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ array: @autoclosure () throws -> [Fetched?], sql: String) throws {
|
||||
do {
|
||||
_ = try array()
|
||||
@@ -735,9 +735,9 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testOptionalFetchSetStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ set: @autoclosure () throws -> Set<Fetched?>, sql: String) throws {
|
||||
do {
|
||||
_ = try set()
|
||||
|
||||
@@ -7,7 +7,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testDatabaseQueueWithPassphraseToDatabaseQueueWithPassphrase() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite", configuration: config)
|
||||
@@ -19,7 +19,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite", configuration: config)
|
||||
@@ -32,7 +32,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testDatabaseQueueWithPassphraseToDatabaseQueueWithoutPassphrase() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite", configuration: config)
|
||||
@@ -56,7 +56,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testDatabaseQueueWithPassphraseToDatabaseQueueWithWrongPassphrase() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite", configuration: config)
|
||||
@@ -68,7 +68,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("wrong")
|
||||
}
|
||||
do {
|
||||
@@ -84,7 +84,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testDatabaseQueueWithPassphraseToDatabaseQueueWithNewPassphrase() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite", configuration: config)
|
||||
@@ -96,7 +96,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite", configuration: config)
|
||||
@@ -116,7 +116,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("newSecret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite", configuration: config)
|
||||
@@ -129,7 +129,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testDatabaseQueueWithPassphraseToDatabasePoolWithPassphrase() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite", configuration: config)
|
||||
@@ -141,7 +141,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite", configuration: config)
|
||||
@@ -154,7 +154,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testDatabaseQueueWithPassphraseToDatabasePoolWithoutPassphrase() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite", configuration: config)
|
||||
@@ -178,7 +178,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testDatabaseQueueWithPassphraseToDatabasePoolWithWrongPassphrase() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite", configuration: config)
|
||||
@@ -190,7 +190,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("wrong")
|
||||
}
|
||||
do {
|
||||
@@ -206,7 +206,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testDatabaseQueueWithPassphraseToDatabasePoolWithNewPassphrase() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite", configuration: config)
|
||||
@@ -219,7 +219,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
var passphrase = "secret"
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase(passphrase)
|
||||
}
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite", configuration: config)
|
||||
@@ -242,7 +242,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("newSecret")
|
||||
}
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite", configuration: config)
|
||||
@@ -255,7 +255,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testDatabasePoolWithPassphraseToDatabasePoolWithPassphrase() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite", configuration: config)
|
||||
@@ -267,7 +267,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite", configuration: config)
|
||||
@@ -280,7 +280,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testDatabasePoolWithPassphraseToDatabasePoolWithoutPassphrase() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite", configuration: config)
|
||||
@@ -304,7 +304,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testDatabasePoolWithPassphraseToDatabasePoolWithWrongPassphrase() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite", configuration: config)
|
||||
@@ -316,7 +316,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("wrong")
|
||||
}
|
||||
do {
|
||||
@@ -333,7 +333,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite", configuration: config)
|
||||
@@ -346,7 +346,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
do {
|
||||
var passphrase = "secret"
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase(passphrase)
|
||||
}
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite", configuration: config)
|
||||
@@ -369,7 +369,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("newSecret")
|
||||
}
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite", configuration: config)
|
||||
@@ -391,7 +391,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite", configuration: config)
|
||||
@@ -425,7 +425,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testCipherPageSize() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
try db.execute(sql: "PRAGMA cipher_page_size = 8192")
|
||||
}
|
||||
@@ -438,7 +438,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
try db.execute(sql: "PRAGMA cipher_page_size = 4096")
|
||||
}
|
||||
@@ -460,7 +460,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testCipherKDFIterations() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
try db.execute(sql: "PRAGMA kdf_iter = 128000")
|
||||
}
|
||||
@@ -473,7 +473,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
try db.execute(sql: "PRAGMA kdf_iter = 128000")
|
||||
}
|
||||
@@ -495,7 +495,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
func testCipherWithMismatchedKDFIterations() throws {
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
try db.execute(sql: "PRAGMA kdf_iter = 128000")
|
||||
}
|
||||
@@ -515,7 +515,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
try db.execute(sql: "PRAGMA kdf_iter = 64000")
|
||||
}
|
||||
@@ -545,7 +545,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
do {
|
||||
@@ -567,7 +567,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var config = Configuration()
|
||||
config.prepareDatabase = { db in
|
||||
config.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue(filename: "encrypted.sqlite", configuration: config)
|
||||
@@ -588,7 +588,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
let testBundle = Bundle(for: type(of: self))
|
||||
let path = testBundle.url(forResource: "db", withExtension: "SQLCipher3")!.path
|
||||
var configuration = Configuration()
|
||||
configuration.prepareDatabase = { db in
|
||||
configuration.prepareDatabase { db in
|
||||
try db.usePassphrase("secret")
|
||||
try db.execute(sql: "PRAGMA cipher_compatibility = 3")
|
||||
}
|
||||
|
||||
@@ -258,15 +258,17 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
var compressCalled = false
|
||||
var uncompressCalled = false
|
||||
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
db.add(function: DatabaseFunction("zipit", argumentCount: 1, pure: true, function: { dbValues in
|
||||
compressCalled = true
|
||||
return dbValues[0]
|
||||
}))
|
||||
db.add(function: DatabaseFunction("unzipit", argumentCount: 1, pure: true, function: { dbValues in
|
||||
uncompressCalled = true
|
||||
return dbValues[0]
|
||||
}))
|
||||
}
|
||||
let dbPool = try makeDatabasePool()
|
||||
dbPool.add(function: DatabaseFunction("zipit", argumentCount: 1, pure: true, function: { dbValues in
|
||||
compressCalled = true
|
||||
return dbValues[0]
|
||||
}))
|
||||
dbPool.add(function: DatabaseFunction("unzipit", argumentCount: 1, pure: true, function: { dbValues in
|
||||
uncompressCalled = true
|
||||
return dbValues[0]
|
||||
}))
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.create(virtualTable: "documents", using: FTS4()) { t in
|
||||
|
||||
@@ -196,9 +196,8 @@ class FTS5CustomTokenizerTests: GRDBTestCase {
|
||||
|
||||
func testStopWordsTokenizerDatabaseQueue() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.add(tokenizer: StopWordsTokenizer.self)
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(tokenizer: StopWordsTokenizer.self)
|
||||
try db.create(virtualTable: "documents", using: FTS5()) { t in
|
||||
t.tokenizer = StopWordsTokenizer.tokenizerDescriptor()
|
||||
t.column("content")
|
||||
@@ -217,9 +216,10 @@ class FTS5CustomTokenizerTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testStopWordsTokenizerDatabasePool() throws {
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
db.add(tokenizer: StopWordsTokenizer.self)
|
||||
}
|
||||
let dbPool = try makeDatabasePool()
|
||||
dbPool.add(tokenizer: StopWordsTokenizer.self)
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.create(virtualTable: "documents", using: FTS5()) { t in
|
||||
t.tokenizer = StopWordsTokenizer.tokenizerDescriptor()
|
||||
@@ -249,10 +249,10 @@ class FTS5CustomTokenizerTests: GRDBTestCase {
|
||||
|
||||
func testNFKCTokenizer() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.add(tokenizer: NFKCTokenizer.self)
|
||||
|
||||
// Without NFKC conversion
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(tokenizer: NFKCTokenizer.self)
|
||||
try db.create(virtualTable: "documents", using: FTS5()) { t in
|
||||
t.tokenizer = .unicode61()
|
||||
t.column("content")
|
||||
@@ -306,9 +306,9 @@ class FTS5CustomTokenizerTests: GRDBTestCase {
|
||||
|
||||
func testSynonymTokenizer() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.add(tokenizer: SynonymsTokenizer.self)
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(tokenizer: SynonymsTokenizer.self)
|
||||
try db.create(virtualTable: "documents", using: FTS5()) { t in
|
||||
t.tokenizer = SynonymsTokenizer.tokenizerDescriptor()
|
||||
t.column("content")
|
||||
|
||||
@@ -96,9 +96,9 @@ class FTS5WrapperTokenizerTests: GRDBTestCase {
|
||||
|
||||
func testStopWordsTokenizerDatabaseQueue() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.add(tokenizer: StopWordsTokenizer.self)
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(tokenizer: StopWordsTokenizer.self)
|
||||
try db.create(virtualTable: "documents", using: FTS5()) { t in
|
||||
t.tokenizer = StopWordsTokenizer.tokenizerDescriptor()
|
||||
t.column("content")
|
||||
@@ -117,8 +117,10 @@ class FTS5WrapperTokenizerTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testStopWordsTokenizerDatabasePool() throws {
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
db.add(tokenizer: StopWordsTokenizer.self)
|
||||
}
|
||||
let dbPool = try makeDatabaseQueue()
|
||||
dbPool.add(tokenizer: StopWordsTokenizer.self)
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.create(virtualTable: "documents", using: FTS5()) { t in
|
||||
@@ -149,10 +151,10 @@ class FTS5WrapperTokenizerTests: GRDBTestCase {
|
||||
|
||||
func testLatinAsciiTokenizer() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.add(tokenizer: LatinAsciiTokenizer.self)
|
||||
|
||||
// Without Latin ASCII conversion
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(tokenizer: LatinAsciiTokenizer.self)
|
||||
try db.create(virtualTable: "documents", using: FTS5()) { t in
|
||||
t.tokenizer = .unicode61()
|
||||
t.column("content")
|
||||
@@ -186,9 +188,9 @@ class FTS5WrapperTokenizerTests: GRDBTestCase {
|
||||
|
||||
func testSynonymsTokenizer() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.add(tokenizer: SynonymsTokenizer.self)
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(tokenizer: SynonymsTokenizer.self)
|
||||
try db.create(virtualTable: "documents", using: FTS5()) { t in
|
||||
t.tokenizer = SynonymsTokenizer.tokenizerDescriptor()
|
||||
t.column("content")
|
||||
|
||||
@@ -70,8 +70,9 @@ class FetchableRecordTests: GRDBTestCase {
|
||||
func testFetchCursorStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
|
||||
func test(_ cursor: RecordCursor<Fetched>, sql: String) throws {
|
||||
do {
|
||||
_ = try cursor.next()
|
||||
@@ -182,8 +183,8 @@ class FetchableRecordTests: GRDBTestCase {
|
||||
func testFetchAllStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ array: @autoclosure () throws -> [Fetched], sql: String) throws {
|
||||
do {
|
||||
_ = try array()
|
||||
@@ -287,8 +288,8 @@ class FetchableRecordTests: GRDBTestCase {
|
||||
func testFetchSetStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ set: @autoclosure () throws -> Set<Fetched>, sql: String) throws {
|
||||
do {
|
||||
_ = try set()
|
||||
@@ -416,8 +417,8 @@ class FetchableRecordTests: GRDBTestCase {
|
||||
func testFetchOneStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ value: @autoclosure () throws -> Fetched?, sql: String) throws {
|
||||
do {
|
||||
_ = try value()
|
||||
|
||||
@@ -103,7 +103,7 @@ class GRDBTestCase: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
dbConfiguration.prepareDatabase = { db in
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
db.trace { event in
|
||||
self.sqlQueries.append(event.description)
|
||||
}
|
||||
|
||||
@@ -15,21 +15,24 @@ private let tableRequest = Reader.all()
|
||||
|
||||
class QueryInterfaceExpressionsTests: GRDBTestCase {
|
||||
|
||||
var collation: DatabaseCollation!
|
||||
var customFunction: DatabaseFunction!
|
||||
let collation = DatabaseCollation("localized_case_insensitive") { (lhs, rhs) in
|
||||
return (lhs as NSString).localizedCaseInsensitiveCompare(rhs)
|
||||
}
|
||||
|
||||
let customFunction = DatabaseFunction("avgOf", pure: true) { dbValues in
|
||||
let sum = dbValues.compactMap { Int.fromDatabaseValue($0) }.reduce(0, +)
|
||||
return Double(sum) / Double(dbValues.count)
|
||||
}
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
db.add(collation: self.collation)
|
||||
db.add(function: self.customFunction)
|
||||
}
|
||||
}
|
||||
|
||||
override func setup(_ dbWriter: DatabaseWriter) throws {
|
||||
collation = DatabaseCollation("localized_case_insensitive") { (lhs, rhs) in
|
||||
return (lhs as NSString).localizedCaseInsensitiveCompare(rhs)
|
||||
}
|
||||
dbWriter.add(collation: collation)
|
||||
|
||||
customFunction = DatabaseFunction("avgOf", pure: true) { dbValues in
|
||||
let sum = dbValues.compactMap { Int.fromDatabaseValue($0) }.reduce(0, +)
|
||||
return Double(sum) / Double(dbValues.count)
|
||||
}
|
||||
dbWriter.add(function: self.customFunction)
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createReaders") { db in
|
||||
try db.execute(sql: """
|
||||
|
||||
@@ -15,14 +15,18 @@ private let tableRequest = Reader.all()
|
||||
|
||||
class QueryInterfaceRequestTests: GRDBTestCase {
|
||||
|
||||
var collation: DatabaseCollation!
|
||||
let collation = DatabaseCollation("localized_case_insensitive") { (lhs, rhs) in
|
||||
return (lhs as NSString).localizedCaseInsensitiveCompare(rhs)
|
||||
}
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
dbConfiguration.prepareDatabase { db in
|
||||
db.add(collation: self.collation)
|
||||
}
|
||||
}
|
||||
|
||||
override func setup(_ dbWriter: DatabaseWriter) throws {
|
||||
collation = DatabaseCollation("localized_case_insensitive") { (lhs, rhs) in
|
||||
return (lhs as NSString).localizedCaseInsensitiveCompare(rhs)
|
||||
}
|
||||
dbWriter.add(collation: collation)
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createReaders") { db in
|
||||
try db.execute(sql: """
|
||||
|
||||
@@ -51,9 +51,9 @@ class RowFetchTests: GRDBTestCase {
|
||||
|
||||
func testFetchCursorStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ cursor: RowCursor, sql: String) throws {
|
||||
do {
|
||||
_ = try cursor.next()
|
||||
@@ -160,9 +160,9 @@ class RowFetchTests: GRDBTestCase {
|
||||
|
||||
func testFetchAllStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ array: @autoclosure () throws -> [Row], sql: String) throws {
|
||||
do {
|
||||
_ = try array()
|
||||
@@ -262,9 +262,9 @@ class RowFetchTests: GRDBTestCase {
|
||||
|
||||
func testFetchSetStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ set: @autoclosure () throws -> Set<Row>, sql: String) throws {
|
||||
do {
|
||||
_ = try set()
|
||||
@@ -388,9 +388,9 @@ class RowFetchTests: GRDBTestCase {
|
||||
|
||||
func testFetchOneStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ value: @autoclosure () throws -> Row?, sql: String) throws {
|
||||
do {
|
||||
_ = try value()
|
||||
|
||||
@@ -40,9 +40,9 @@ class SelectStatementTests : GRDBTestCase {
|
||||
|
||||
func testStatementCursorStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ cursor: StatementCursor) throws {
|
||||
let sql = cursor._statement.sql
|
||||
do {
|
||||
@@ -134,14 +134,14 @@ class SelectStatementTests : GRDBTestCase {
|
||||
|
||||
func testCachedSelectStatementStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
var needsThrow = false
|
||||
dbQueue.add(function: DatabaseFunction("bomb", argumentCount: 0, pure: false) { _ in
|
||||
if needsThrow {
|
||||
throw DatabaseError(message: "boom")
|
||||
}
|
||||
return "success"
|
||||
})
|
||||
try dbQueue.inDatabase { db in
|
||||
var needsThrow = false
|
||||
db.add(function: DatabaseFunction("bomb", argumentCount: 0, pure: false) { _ in
|
||||
if needsThrow {
|
||||
throw DatabaseError(message: "boom")
|
||||
}
|
||||
return "success"
|
||||
})
|
||||
let sql = "SELECT bomb()"
|
||||
|
||||
needsThrow = false
|
||||
|
||||
@@ -116,9 +116,9 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testFetchCursorStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ cursor: FastDatabaseValueCursor<Fetched>, sql: String) throws {
|
||||
do {
|
||||
_ = try cursor.next()
|
||||
@@ -226,9 +226,9 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testFetchAllStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ array: @autoclosure () throws -> [Fetched], sql: String) throws {
|
||||
do {
|
||||
_ = try array()
|
||||
@@ -329,9 +329,9 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testFetchSetStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ set: @autoclosure () throws -> Set<Fetched>, sql: String) throws {
|
||||
do {
|
||||
_ = try set()
|
||||
@@ -477,9 +477,9 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testFetchOneStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ value: @autoclosure () throws -> Fetched?, sql: String) throws {
|
||||
do {
|
||||
_ = try value()
|
||||
@@ -658,9 +658,9 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testOptionalFetchAllStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ array: @autoclosure () throws -> [Fetched?], sql: String) throws {
|
||||
do {
|
||||
_ = try array()
|
||||
@@ -761,9 +761,9 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testOptionalFetchSetStepFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
db.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
func test(_ set: @autoclosure () throws -> Set<Fetched?>, sql: String) throws {
|
||||
do {
|
||||
_ = try set()
|
||||
|
||||
@@ -231,9 +231,9 @@ class TableDefinitionTests: GRDBTestCase {
|
||||
return .rollback
|
||||
}
|
||||
|
||||
let collation = DatabaseCollation("foo") { (lhs, rhs) in .orderedSame }
|
||||
dbQueue.add(collation: collation)
|
||||
try dbQueue.inTransaction { db in
|
||||
let collation = DatabaseCollation("foo") { (lhs, rhs) in .orderedSame }
|
||||
db.add(collation: collation)
|
||||
try db.create(table: "test") { t in
|
||||
t.column("name", .text).collate(collation)
|
||||
}
|
||||
|
||||
@@ -164,11 +164,11 @@ class UpdateStatementTests : GRDBTestCase {
|
||||
func testUpdateStatementAcceptsSelectQueriesAndConsumeAllRows() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
var index = 0
|
||||
dbQueue.add(function: DatabaseFunction("seq", argumentCount: 0, pure: false) { _ in
|
||||
defer { index += 1 }
|
||||
return index
|
||||
})
|
||||
try dbQueue.inDatabase { db in
|
||||
db.add(function: DatabaseFunction("seq", argumentCount: 0, pure: false) { _ in
|
||||
defer { index += 1 }
|
||||
return index
|
||||
})
|
||||
try db.execute(sql: "SELECT seq() UNION ALL SELECT seq() UNION ALL SELECT seq()")
|
||||
let statement = try db.makeUpdateStatement(sql: "SELECT seq() UNION ALL SELECT seq() UNION ALL SELECT seq()")
|
||||
try statement.execute()
|
||||
|
||||
Reference in new issue
Block a user