mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Principle of least astonishment: rrename argument label rawSQL to sql
This commit is contained in:
1 parent
2cd20b79f7
commit
db67d3840b
188 files changed
+3289
-3371
No files matched your search
@@ -246,7 +246,7 @@ extension PlayersViewController {
|
||||
}
|
||||
// Delete a random player
|
||||
if Bool.random() {
|
||||
try Player.order(rawSQL: "RANDOM()").limit(1).deleteAll(db)
|
||||
try Player.order(sql: "RANDOM()").limit(1).deleteAll(db)
|
||||
}
|
||||
// Update some players
|
||||
for var player in try Player.fetchAll(db) where Bool.random() {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
extension Array {
|
||||
/// Creates an array containing the elements of a cursor.
|
||||
///
|
||||
/// let cursor = try String.fetchCursor(db, rawSQL: "SELECT 'foo' UNION ALL SELECT 'bar'")
|
||||
/// let cursor = try String.fetchCursor(db, sql: "SELECT 'foo' UNION ALL SELECT 'bar'")
|
||||
/// let strings = try Array(cursor) // ["foo", "bar"]
|
||||
public init<C: Cursor>(_ cursor: C) throws where C.Element == Element {
|
||||
self.init()
|
||||
@@ -36,7 +36,7 @@ extension Sequence {
|
||||
extension Set {
|
||||
/// Creates a set containing the elements of a cursor.
|
||||
///
|
||||
/// let cursor = try String.fetchCursor(db, rawSQL: "SELECT 'foo' UNION ALL SELECT 'foo'")
|
||||
/// let cursor = try String.fetchCursor(db, sql: "SELECT 'foo' UNION ALL SELECT 'foo'")
|
||||
/// let strings = try Set(cursor) // ["foo"]
|
||||
public init<C: Cursor>(_ cursor: C) throws where C.Element == Element {
|
||||
self.init()
|
||||
@@ -111,7 +111,7 @@ extension Cursor {
|
||||
/// Returns a cursor of pairs (n, x), where n represents a consecutive
|
||||
/// integer starting at zero, and x represents an element of the cursor.
|
||||
///
|
||||
/// let cursor = try String.fetchCursor(db, rawSQL: "SELECT 'foo' UNION ALL SELECT 'bar'")
|
||||
/// let cursor = try String.fetchCursor(db, sql: "SELECT 'foo' UNION ALL SELECT 'bar'")
|
||||
/// let c = cursor.enumerated()
|
||||
/// while let (n, x) = c.next() {
|
||||
/// print("\(n): \(x)")
|
||||
@@ -595,7 +595,7 @@ public final class DropWhileCursor<Base: Cursor> : Cursor {
|
||||
/// To create an instance of `EnumeratedCursor`, call the `enumerated()` method
|
||||
/// on a cursor:
|
||||
///
|
||||
/// let cursor = try String.fetchCursor(db, rawSQL: "SELECT 'foo' UNION ALL SELECT 'bar'")
|
||||
/// let cursor = try String.fetchCursor(db, sql: "SELECT 'foo' UNION ALL SELECT 'bar'")
|
||||
/// let c = cursor.enumerated()
|
||||
/// while let (n, x) = c.next() {
|
||||
/// print("\(n): \(x)")
|
||||
|
||||
@@ -171,13 +171,13 @@ extension Database {
|
||||
}
|
||||
|
||||
let indexes = try Row
|
||||
.fetchAll(self, rawSQL: "PRAGMA index_list(\(tableName.quotedDatabaseIdentifier))")
|
||||
.fetchAll(self, sql: "PRAGMA index_list(\(tableName.quotedDatabaseIdentifier))")
|
||||
.map { row -> IndexInfo in
|
||||
// [seq:0 name:"index" unique:0 origin:"c" partial:0]
|
||||
let indexName: String = row[1]
|
||||
let unique: Bool = row[2]
|
||||
let columns = try Row
|
||||
.fetchAll(self, rawSQL: "PRAGMA index_info(\(indexName.quotedDatabaseIdentifier))")
|
||||
.fetchAll(self, sql: "PRAGMA index_info(\(indexName.quotedDatabaseIdentifier))")
|
||||
.map { row -> (Int, String) in
|
||||
// [seqno:0 cid:2 name:"column"]
|
||||
(row[0] as Int, row[2] as String)
|
||||
@@ -213,7 +213,7 @@ extension Database {
|
||||
|
||||
var rawForeignKeys: [(destinationTable: String, mapping: [(origin: String, destination: String?, seq: Int)])] = []
|
||||
var previousId: Int? = nil
|
||||
for row in try Row.fetchAll(self, rawSQL: "PRAGMA foreign_key_list(\(tableName.quotedDatabaseIdentifier))") {
|
||||
for row in try Row.fetchAll(self, sql: "PRAGMA foreign_key_list(\(tableName.quotedDatabaseIdentifier))") {
|
||||
// row = [id:0 seq:0 table:"parents" from:"parentId" to:"id" on_update:"..." on_delete:"..." match:"..."]
|
||||
let id: Int = row[0]
|
||||
let seq: Int = row[1]
|
||||
@@ -320,7 +320,7 @@ extension Database {
|
||||
}
|
||||
}
|
||||
let columns = try ColumnInfo
|
||||
.fetchAll(self, rawSQL: "PRAGMA table_info(\(tableName.quotedDatabaseIdentifier))")
|
||||
.fetchAll(self, sql: "PRAGMA table_info(\(tableName.quotedDatabaseIdentifier))")
|
||||
.sorted(by: { $0.cid < $1.cid })
|
||||
guard columns.count > 0 else {
|
||||
throw DatabaseError(message: "no such table: \(tableName)")
|
||||
@@ -386,7 +386,7 @@ public struct ColumnInfo : FetchableRecord {
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// try db.execute(rawSQL: """
|
||||
/// try db.execute(sql: """
|
||||
/// CREATE TABLE player(
|
||||
/// id INTEGER PRIMARY KEY,
|
||||
/// name TEXT DEFAULT 'Anonymous',
|
||||
@@ -579,7 +579,7 @@ struct SchemaInfo: Equatable {
|
||||
private var objects: Set<SchemaObject>
|
||||
|
||||
init(_ db: Database) throws {
|
||||
objects = try Set(SchemaObject.fetchCursor(db, rawSQL: """
|
||||
objects = try Set(SchemaObject.fetchCursor(db, sql: """
|
||||
SELECT type, name, tbl_name, sql, 0 AS isTemporary FROM sqlite_master \
|
||||
UNION \
|
||||
SELECT type, name, tbl_name, sql, 1 FROM sqlite_temp_master
|
||||
@@ -597,7 +597,7 @@ struct SchemaInfo: Equatable {
|
||||
|
||||
/// Returns the canonical name of the object:
|
||||
///
|
||||
/// try db.execute(rawSQL: "CREATE TABLE FooBar (...)")
|
||||
/// try db.execute(sql: "CREATE TABLE FooBar (...)")
|
||||
/// try db.schema().canonicalName("foobar", ofType: .table) // "FooBar"
|
||||
func canonicalName(_ name: String, ofType type: SchemaObjectType) -> String? {
|
||||
let name = name.lowercased()
|
||||
|
||||
@@ -110,10 +110,10 @@ extension Database {
|
||||
/// Executes one or several SQL statements, separated by semi-colons.
|
||||
///
|
||||
/// try db.execute(
|
||||
/// rawSQL: "INSERT INTO player (name) VALUES (:name)",
|
||||
/// sql: "INSERT INTO player (name) VALUES (:name)",
|
||||
/// arguments: ["name": "Arthur"])
|
||||
///
|
||||
/// try db.execute(rawSQL: """
|
||||
/// try db.execute(sql: """
|
||||
/// INSERT INTO player (name) VALUES (?);
|
||||
/// INSERT INTO player (name) VALUES (?);
|
||||
/// INSERT INTO player (name) VALUES (?);
|
||||
@@ -125,17 +125,17 @@ extension Database {
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs.
|
||||
public func execute(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) throws {
|
||||
try execute(literal: SQLLiteral(rawSQL: sql, arguments: arguments))
|
||||
public func execute(sql: String, arguments: StatementArguments = StatementArguments()) throws {
|
||||
try execute(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Executes one or several SQL statements, separated by semi-colons.
|
||||
///
|
||||
/// try db.execute(literal: SQLLiteral(
|
||||
/// rawSQL: "INSERT INTO player (name) VALUES (:name)",
|
||||
/// sql: "INSERT INTO player (name) VALUES (:name)",
|
||||
/// arguments: ["name": "Arthur"]))
|
||||
///
|
||||
/// try db.execute(literal: SQLLiteral(rawSQL: """
|
||||
/// try db.execute(literal: SQLLiteral(sql: """
|
||||
/// INSERT INTO player (name) VALUES (?);
|
||||
/// INSERT INTO player (name) VALUES (?);
|
||||
/// INSERT INTO player (name) VALUES (?);
|
||||
|
||||
+13
-13
@@ -151,7 +151,7 @@ public final class Database {
|
||||
|
||||
/// The list of compile options used when building SQLite
|
||||
static let sqliteCompileOptions: Set<String> = DatabaseQueue().inDatabase {
|
||||
try! Set(String.fetchCursor($0, rawSQL: "PRAGMA COMPILE_OPTIONS"))
|
||||
try! Set(String.fetchCursor($0, sql: "PRAGMA COMPILE_OPTIONS"))
|
||||
}
|
||||
|
||||
// MARK: - Private properties
|
||||
@@ -353,7 +353,7 @@ extension Database {
|
||||
private func setupForeignKeys() throws {
|
||||
// Foreign keys are disabled by default with SQLite3
|
||||
if configuration.foreignKeysEnabled {
|
||||
try execute(rawSQL: "PRAGMA foreign_keys = ON")
|
||||
try execute(sql: "PRAGMA foreign_keys = ON")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +489,7 @@ extension Database {
|
||||
/// return int + 1
|
||||
/// }
|
||||
/// db.add(function: fn)
|
||||
/// try Int.fetchOne(db, rawSQL: "SELECT succ(1)")! // 2
|
||||
/// try Int.fetchOne(db, sql: "SELECT succ(1)")! // 2
|
||||
public func add(function: DatabaseFunction) {
|
||||
functions.update(with: function)
|
||||
function.install(in: self)
|
||||
@@ -512,7 +512,7 @@ extension Database {
|
||||
/// return (string1 as NSString).localizedStandardCompare(string2)
|
||||
/// }
|
||||
/// db.add(collation: collation)
|
||||
/// try db.execute(rawSQL: "CREATE TABLE files (name TEXT COLLATE localized_standard")
|
||||
/// try db.execute(sql: "CREATE TABLE files (name TEXT COLLATE localized_standard")
|
||||
public func add(collation: DatabaseCollation) {
|
||||
collations.update(with: collation)
|
||||
let collationPointer = Unmanaged.passUnretained(collation).toOpaque()
|
||||
@@ -569,7 +569,7 @@ extension Database {
|
||||
///
|
||||
/// try dbQueue.inDatabase do {
|
||||
/// try db.inTransaction {
|
||||
/// try db.execute(rawSQL: "INSERT ...")
|
||||
/// try db.execute(sql: "INSERT ...")
|
||||
/// return .commit
|
||||
/// }
|
||||
/// }
|
||||
@@ -629,7 +629,7 @@ extension Database {
|
||||
///
|
||||
/// try dbQueue.inDatabase do {
|
||||
/// try db.inSavepoint {
|
||||
/// try db.execute(rawSQL: "INSERT ...")
|
||||
/// try db.execute(sql: "INSERT ...")
|
||||
/// return .commit
|
||||
/// }
|
||||
/// }
|
||||
@@ -665,7 +665,7 @@ extension Database {
|
||||
// using unique savepoint names. User could still mess with them
|
||||
// with raw SQL queries, but let's assume that it is unlikely that
|
||||
// the user uses "grdb" as a savepoint name.
|
||||
try execute(rawSQL: "SAVEPOINT grdb")
|
||||
try execute(sql: "SAVEPOINT grdb")
|
||||
|
||||
// Now that savepoint has begun, we'll rollback in case of error.
|
||||
// But we'll throw the first caught error, so that user knows
|
||||
@@ -676,7 +676,7 @@ extension Database {
|
||||
let completion = try block()
|
||||
switch completion {
|
||||
case .commit:
|
||||
try execute(rawSQL: "RELEASE SAVEPOINT grdb")
|
||||
try execute(sql: "RELEASE SAVEPOINT grdb")
|
||||
assert(!topLevelSavepoint || !isInsideTransaction)
|
||||
needsRollback = false
|
||||
case .rollback:
|
||||
@@ -695,8 +695,8 @@ extension Database {
|
||||
// Rollback, and release the savepoint.
|
||||
// Rollback alone is not enough to clear the savepoint from
|
||||
// the SQLite savepoint stack.
|
||||
try execute(rawSQL: "ROLLBACK TRANSACTION TO SAVEPOINT grdb")
|
||||
try execute(rawSQL: "RELEASE SAVEPOINT grdb")
|
||||
try execute(sql: "ROLLBACK TRANSACTION TO SAVEPOINT grdb")
|
||||
try execute(sql: "RELEASE SAVEPOINT grdb")
|
||||
}
|
||||
} catch {
|
||||
if firstError == nil {
|
||||
@@ -719,7 +719,7 @@ extension Database {
|
||||
/// - throws: The error thrown by the block.
|
||||
public func beginTransaction(_ kind: TransactionKind? = nil) throws {
|
||||
let kind = kind ?? configuration.defaultTransactionKind
|
||||
try execute(rawSQL: "BEGIN \(kind.rawValue) TRANSACTION")
|
||||
try execute(sql: "BEGIN \(kind.rawValue) TRANSACTION")
|
||||
assert(isInsideTransaction)
|
||||
}
|
||||
|
||||
@@ -815,14 +815,14 @@ extension Database {
|
||||
// should be exposed to the library user.
|
||||
SchedulingWatchdog.preconditionValidQueue(self) // guard sqlite3_get_autocommit
|
||||
if sqlite3_get_autocommit(sqliteConnection) == 0 {
|
||||
try execute(rawSQL: "ROLLBACK TRANSACTION")
|
||||
try execute(sql: "ROLLBACK TRANSACTION")
|
||||
}
|
||||
assert(!isInsideTransaction)
|
||||
}
|
||||
|
||||
/// Commits a database transaction.
|
||||
public func commit() throws {
|
||||
try execute(rawSQL: "COMMIT TRANSACTION")
|
||||
try execute(sql: "COMMIT TRANSACTION")
|
||||
assert(!isInsideTransaction)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public final class DatabaseCollation {
|
||||
/// return (string1 as NSString).localizedStandardCompare(string2)
|
||||
/// }
|
||||
/// db.add(collation: collation)
|
||||
/// try db.execute(rawSQL: "CREATE TABLE file (name TEXT COLLATE localized_standard")
|
||||
/// try db.execute(sql: "CREATE TABLE file (name TEXT COLLATE localized_standard")
|
||||
///
|
||||
/// - parameters:
|
||||
/// - name: The function name.
|
||||
|
||||
@@ -27,7 +27,7 @@ public final class DatabaseFunction: Hashable {
|
||||
/// return int + 1
|
||||
/// }
|
||||
/// db.add(function: fn)
|
||||
/// try Int.fetchOne(db, rawSQL: "SELECT succ(1)")! // 2
|
||||
/// try Int.fetchOne(db, sql: "SELECT succ(1)")! // 2
|
||||
///
|
||||
/// - parameters:
|
||||
/// - name: The function name.
|
||||
@@ -73,10 +73,10 @@ public final class DatabaseFunction: Hashable {
|
||||
/// let fn = DatabaseFunction("mysum", argumentCount: 1, aggregate: MySum.self)
|
||||
/// dbQueue.add(function: fn)
|
||||
/// try dbQueue.write { db in
|
||||
/// try db.execute(rawSQL: "CREATE TABLE test(i)")
|
||||
/// try db.execute(rawSQL: "INSERT INTO test(i) VALUES (1)")
|
||||
/// try db.execute(rawSQL: "INSERT INTO test(i) VALUES (2)")
|
||||
/// try Int.fetchOne(db, rawSQL: "SELECT mysum(i) FROM test")! // 3
|
||||
/// 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)")
|
||||
/// try Int.fetchOne(db, sql: "SELECT mysum(i) FROM test")! // 3
|
||||
/// }
|
||||
///
|
||||
/// - parameters:
|
||||
@@ -353,10 +353,10 @@ extension DatabaseFunction {
|
||||
/// let fn = DatabaseFunction("mysum", argumentCount: 1, aggregate: MySum.self)
|
||||
/// dbQueue.add(function: fn)
|
||||
/// try dbQueue.write { db in
|
||||
/// try db.execute(rawSQL: "CREATE TABLE test(i)")
|
||||
/// try db.execute(rawSQL: "INSERT INTO test(i) VALUES (1)")
|
||||
/// try db.execute(rawSQL: "INSERT INTO test(i) VALUES (2)")
|
||||
/// try Int.fetchOne(db, rawSQL: "SELECT mysum(i) FROM test")! // 3
|
||||
/// 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)")
|
||||
/// try Int.fetchOne(db, sql: "SELECT mysum(i) FROM test")! // 3
|
||||
/// }
|
||||
public protocol DatabaseAggregate {
|
||||
/// Creates an aggregate.
|
||||
|
||||
@@ -58,14 +58,14 @@ public final class DatabasePool: DatabaseWriter {
|
||||
// Activate WAL Mode unless readonly
|
||||
if !configuration.readonly {
|
||||
try writer.sync { db in
|
||||
let journalMode = try String.fetchOne(db, rawSQL: "PRAGMA journal_mode = WAL")
|
||||
let journalMode = try String.fetchOne(db, sql: "PRAGMA journal_mode = WAL")
|
||||
guard journalMode == "wal" else {
|
||||
throw DatabaseError(message: "could not activate WAL Mode at path: \(path)")
|
||||
}
|
||||
|
||||
// https://www.sqlite.org/pragma.html#pragma_synchronous
|
||||
// > Many applications choose NORMAL when in WAL mode
|
||||
try db.execute(rawSQL: "PRAGMA synchronous = NORMAL")
|
||||
try db.execute(sql: "PRAGMA synchronous = NORMAL")
|
||||
|
||||
if !FileManager.default.fileExists(atPath: path + "-wal") {
|
||||
// Create the -wal file if it does not exist yet. This
|
||||
@@ -73,7 +73,7 @@ public final class DatabasePool: DatabaseWriter {
|
||||
// opens a pool to an existing non-WAL database, and
|
||||
// attempts to read from it.
|
||||
// See https://github.com/groue/GRDB.swift/issues/102
|
||||
try db.execute(rawSQL: "CREATE TABLE grdb_issue_102 (id INTEGER PRIMARY KEY); DROP TABLE grdb_issue_102;")
|
||||
try db.execute(sql: "CREATE TABLE grdb_issue_102 (id INTEGER PRIMARY KEY); DROP TABLE grdb_issue_102;")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,13 +247,13 @@ extension DatabasePool : DatabaseReader {
|
||||
/// try dbPool.read { db in
|
||||
/// // Those two values are guaranteed to be equal, even if the
|
||||
/// // `wine` table is modified between the two requests:
|
||||
/// let count1 = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count2 = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count1 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count2 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// }
|
||||
///
|
||||
/// try dbPool.read { db in
|
||||
/// // Now this value may be different:
|
||||
/// let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// }
|
||||
///
|
||||
/// This method is *not* reentrant.
|
||||
@@ -288,15 +288,15 @@ extension DatabasePool : DatabaseReader {
|
||||
/// try dbPool.unsafeRead { db in
|
||||
/// // Those two values may be different because some other thread
|
||||
/// // may have inserted or deleted a wine between the two requests:
|
||||
/// let count1 = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count2 = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count1 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count2 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// }
|
||||
///
|
||||
/// Cursor iteration is safe, though:
|
||||
///
|
||||
/// try dbPool.unsafeRead { db in
|
||||
/// // No concurrent update can mess with this iteration:
|
||||
/// let rows = try Row.fetchCursor(db, rawSQL: "SELECT ...")
|
||||
/// let rows = try Row.fetchCursor(db, sql: "SELECT ...")
|
||||
/// while let row = try rows.next() { ... }
|
||||
/// }
|
||||
///
|
||||
@@ -325,15 +325,15 @@ extension DatabasePool : DatabaseReader {
|
||||
/// try dbPool.unsafeReentrantRead { db in
|
||||
/// // Those two values may be different because some other thread
|
||||
/// // may have inserted or deleted a wine between the two requests:
|
||||
/// let count1 = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count2 = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count1 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count2 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// }
|
||||
///
|
||||
/// Cursor iteration is safe, though:
|
||||
///
|
||||
/// try dbPool.unsafeReentrantRead { db in
|
||||
/// // No concurrent update can mess with this iteration:
|
||||
/// let rows = try Row.fetchCursor(db, rawSQL: "SELECT ...")
|
||||
/// let rows = try Row.fetchCursor(db, sql: "SELECT ...")
|
||||
/// while let row = try rows.next() { ... }
|
||||
/// }
|
||||
///
|
||||
@@ -557,7 +557,7 @@ extension DatabasePool : DatabaseReader {
|
||||
/// }
|
||||
/// dbPool.add(function: fn)
|
||||
/// try dbPool.read { db in
|
||||
/// try Int.fetchOne(db, rawSQL: "SELECT succ(1)") // 2
|
||||
/// try Int.fetchOne(db, sql: "SELECT succ(1)") // 2
|
||||
/// }
|
||||
public func add(function: DatabaseFunction) {
|
||||
functions.update(with: function)
|
||||
@@ -579,7 +579,7 @@ extension DatabasePool : DatabaseReader {
|
||||
/// }
|
||||
/// dbPool.add(collation: collation)
|
||||
/// try dbPool.write { db in
|
||||
/// try db.execute(rawSQL: "CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD")
|
||||
/// try db.execute(sql: "CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD")
|
||||
/// }
|
||||
public func add(collation: DatabaseCollation) {
|
||||
collations.update(with: collation)
|
||||
|
||||
@@ -332,7 +332,7 @@ extension DatabaseQueue {
|
||||
/// }
|
||||
/// dbQueue.add(function: fn)
|
||||
/// try dbQueue.read { db in
|
||||
/// try Int.fetchOne(db, rawSQL: "SELECT succ(1)") // 2
|
||||
/// try Int.fetchOne(db, sql: "SELECT succ(1)") // 2
|
||||
/// }
|
||||
public func add(function: DatabaseFunction) {
|
||||
writer.sync { $0.add(function: function) }
|
||||
@@ -352,7 +352,7 @@ extension DatabaseQueue {
|
||||
/// }
|
||||
/// dbQueue.add(collation: collation)
|
||||
/// try dbQueue.write { db in
|
||||
/// try db.execute(rawSQL: "CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD")
|
||||
/// try db.execute(sql: "CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD")
|
||||
/// }
|
||||
public func add(collation: DatabaseCollation) {
|
||||
writer.sync { $0.add(collation: collation) }
|
||||
|
||||
@@ -32,13 +32,13 @@ public protocol DatabaseReader : class {
|
||||
/// try reader.read { db in
|
||||
/// // Those two values are guaranteed to be equal, even if the
|
||||
/// // `wine` table is modified between the two requests:
|
||||
/// let count1 = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count2 = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count1 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count2 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// }
|
||||
///
|
||||
/// try reader.read { db in
|
||||
/// // Now this value may be different:
|
||||
/// let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// }
|
||||
///
|
||||
/// Guarantee 2: Starting iOS 8.2, OSX 10.10, and with custom SQLite builds
|
||||
@@ -61,15 +61,15 @@ public protocol DatabaseReader : class {
|
||||
/// try reader.unsafeRead { db in
|
||||
/// // Those two values may be different because some other thread
|
||||
/// // may have inserted or deleted a wine between the two requests:
|
||||
/// let count1 = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count2 = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count1 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count2 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// }
|
||||
///
|
||||
/// Cursor iterations are isolated, though:
|
||||
///
|
||||
/// try reader.unsafeRead { db in
|
||||
/// // No concurrent update can mess with this iteration:
|
||||
/// let rows = try Row.fetchCursor(db, rawSQL: "SELECT ...")
|
||||
/// let rows = try Row.fetchCursor(db, sql: "SELECT ...")
|
||||
/// while let row = try rows.next() { ... }
|
||||
/// }
|
||||
///
|
||||
@@ -92,15 +92,15 @@ public protocol DatabaseReader : class {
|
||||
/// try reader.unsafeReentrantRead { db in
|
||||
/// // Those two values may be different because some other thread
|
||||
/// // may have inserted or deleted a wine between the two requests:
|
||||
/// let count1 = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count2 = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count1 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// let count2 = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM wine")!
|
||||
/// }
|
||||
///
|
||||
/// Cursor iterations are isolated, though:
|
||||
///
|
||||
/// try reader.unsafeReentrantRead { db in
|
||||
/// // No concurrent update can mess with this iteration:
|
||||
/// let rows = try Row.fetchCursor(db, rawSQL: "SELECT ...")
|
||||
/// let rows = try Row.fetchCursor(db, sql: "SELECT ...")
|
||||
/// while let row = try rows.next() { ... }
|
||||
/// }
|
||||
///
|
||||
@@ -128,7 +128,7 @@ public protocol DatabaseReader : class {
|
||||
/// }
|
||||
/// reader.add(function: fn)
|
||||
/// try reader.read { db in
|
||||
/// try Int.fetchOne(db, rawSQL: "SELECT succ(1)")! // 2
|
||||
/// try Int.fetchOne(db, sql: "SELECT succ(1)")! // 2
|
||||
/// }
|
||||
func add(function: DatabaseFunction)
|
||||
|
||||
@@ -144,7 +144,7 @@ public protocol DatabaseReader : class {
|
||||
/// return (string1 as NSString).localizedStandardCompare(string2)
|
||||
/// }
|
||||
/// reader.add(collation: collation)
|
||||
/// try reader.execute(rawSQL: "SELECT * FROM file ORDER BY name COLLATE localized_standard")
|
||||
/// try reader.execute(sql: "SELECT * FROM file ORDER BY name COLLATE localized_standard")
|
||||
func add(collation: DatabaseCollation)
|
||||
|
||||
/// Remove a collation.
|
||||
|
||||
@@ -28,7 +28,7 @@ public class DatabaseSnapshot : DatabaseReader {
|
||||
|
||||
try serializedDatabase.sync { db in
|
||||
// Assert WAL mode
|
||||
let journalMode = try String.fetchOne(db, rawSQL: "PRAGMA journal_mode")
|
||||
let journalMode = try String.fetchOne(db, sql: "PRAGMA journal_mode")
|
||||
guard journalMode == "wal" else {
|
||||
throw DatabaseError(message: "WAL mode is not activated at path: \(path)")
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ extension DatabaseValue {
|
||||
} else {
|
||||
// Correctness above all: use SQLite to quote the value.
|
||||
// Assume that the Quote function always succeeds
|
||||
return DatabaseQueue().inDatabase { try! String.fetchOne($0, rawSQL: "SELECT QUOTE(?)", arguments: [self])! }
|
||||
return DatabaseQueue().inDatabase { try! String.fetchOne($0, sql: "SELECT QUOTE(?)", arguments: [self])! }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
/// The protocol comes with built-in methods that allow to fetch cursors,
|
||||
/// arrays, or single values:
|
||||
///
|
||||
/// try String.fetchCursor(db, rawSQL: "SELECT name FROM ...", arguments:...) // Cursor of String
|
||||
/// try String.fetchAll(db, rawSQL: "SELECT name FROM ...", arguments:...) // [String]
|
||||
/// try String.fetchOne(db, rawSQL: "SELECT name FROM ...", arguments:...) // String?
|
||||
/// try String.fetchCursor(db, sql: "SELECT name FROM ...", arguments:...) // Cursor of String
|
||||
/// try String.fetchAll(db, sql: "SELECT name FROM ...", arguments:...) // [String]
|
||||
/// try String.fetchOne(db, sql: "SELECT name FROM ...", arguments:...) // String?
|
||||
///
|
||||
/// let statement = try db.makeSelectStatement("SELECT name FROM ...")
|
||||
/// try String.fetchCursor(statement, arguments:...) // Cursor of String
|
||||
@@ -42,7 +42,7 @@ extension DatabaseValueConvertible {
|
||||
/// For example:
|
||||
///
|
||||
/// try dbQueue.read { db in
|
||||
/// let urls: DatabaseValueCursor<URL> = try URL.fetchCursor(db, rawSQL: "SELECT url FROM link")
|
||||
/// let urls: DatabaseValueCursor<URL> = try URL.fetchCursor(db, sql: "SELECT url FROM link")
|
||||
/// while let url = urls.next() { // URL
|
||||
/// print(url)
|
||||
/// }
|
||||
@@ -102,7 +102,7 @@ public final class DatabaseValueCursor<Value: DatabaseValueConvertible> : Cursor
|
||||
/// For example:
|
||||
///
|
||||
/// try dbQueue.read { db in
|
||||
/// let urls: NullableDatabaseValueCursor<URL> = try Optional<URL>.fetchCursor(db, rawSQL: "SELECT url FROM link")
|
||||
/// let urls: NullableDatabaseValueCursor<URL> = try Optional<URL>.fetchCursor(db, sql: "SELECT url FROM link")
|
||||
/// while let url = urls.next() { // URL?
|
||||
/// print(url)
|
||||
/// }
|
||||
@@ -161,9 +161,9 @@ public final class NullableDatabaseValueCursor<Value: DatabaseValueConvertible>
|
||||
/// DatabaseValueConvertible comes with built-in methods that allow to fetch
|
||||
/// cursors, arrays, or single values:
|
||||
///
|
||||
/// try String.fetchCursor(db, rawSQL: "SELECT name FROM ...", arguments:...) // Cursor of String
|
||||
/// try String.fetchAll(db, rawSQL: "SELECT name FROM ...", arguments:...) // [String]
|
||||
/// try String.fetchOne(db, rawSQL: "SELECT name FROM ...", arguments:...) // String?
|
||||
/// try String.fetchCursor(db, sql: "SELECT name FROM ...", arguments:...) // Cursor of String
|
||||
/// try String.fetchAll(db, sql: "SELECT name FROM ...", arguments:...) // [String]
|
||||
/// try String.fetchOne(db, sql: "SELECT name FROM ...", arguments:...) // String?
|
||||
///
|
||||
/// let statement = try db.makeSelectStatement("SELECT name FROM ...")
|
||||
/// try String.fetchCursor(statement, arguments:...) // Cursor of String
|
||||
@@ -240,7 +240,7 @@ extension DatabaseValueConvertible {
|
||||
|
||||
/// Returns a cursor over values fetched from an SQL query.
|
||||
///
|
||||
/// let names = try String.fetchCursor(db, rawSQL: "SELECT name FROM ...") // Cursor of String
|
||||
/// let names = try String.fetchCursor(db, sql: "SELECT name FROM ...") // Cursor of String
|
||||
/// while let name = try name.next() { // String
|
||||
/// ...
|
||||
/// }
|
||||
@@ -257,13 +257,13 @@ extension DatabaseValueConvertible {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DatabaseValueCursor<Self> {
|
||||
return try fetchCursor(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DatabaseValueCursor<Self> {
|
||||
return try fetchCursor(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of values fetched from an SQL query.
|
||||
///
|
||||
/// let names = try String.fetchAll(db, rawSQL: "SELECT name FROM ...") // [String]
|
||||
/// let names = try String.fetchAll(db, sql: "SELECT name FROM ...") // [String]
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
@@ -272,8 +272,8 @@ extension DatabaseValueConvertible {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
return try fetchAll(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
return try fetchAll(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from an SQL query.
|
||||
@@ -281,7 +281,7 @@ extension DatabaseValueConvertible {
|
||||
/// The result is nil if the query returns no row, or if no value can be
|
||||
/// extracted from the first row.
|
||||
///
|
||||
/// let name = try String.fetchOne(db, rawSQL: "SELECT name FROM ...") // String?
|
||||
/// let name = try String.fetchOne(db, sql: "SELECT name FROM ...") // String?
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
@@ -290,8 +290,8 @@ extension DatabaseValueConvertible {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? {
|
||||
return try fetchOne(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? {
|
||||
return try fetchOne(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ extension DatabaseValueConvertible {
|
||||
|
||||
/// Returns a cursor over values fetched from an SQL query.
|
||||
///
|
||||
/// let firstNames = try String.fetchCursor(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let firstNames = try String.fetchCursor(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT firstName FROM player
|
||||
/// WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // Cursor of String
|
||||
@@ -334,7 +334,7 @@ extension DatabaseValueConvertible {
|
||||
|
||||
/// Returns an array of values fetched from an SQL query.
|
||||
///
|
||||
/// let firstNames = try String.fetchAll(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let firstNames = try String.fetchAll(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT firstName FROM player
|
||||
/// WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // [String]
|
||||
@@ -365,7 +365,7 @@ extension DatabaseValueConvertible {
|
||||
/// The result is nil if the query returns no row, or if no value can be
|
||||
/// extracted from the first row.
|
||||
///
|
||||
/// let firstName = try String.fetchOne(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let firstName = try String.fetchOne(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT firstName FROM player
|
||||
/// WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // String?
|
||||
@@ -505,8 +505,8 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible {
|
||||
/// Swift's Optional comes with built-in methods that allow to fetch cursors
|
||||
/// and arrays of optional DatabaseValueConvertible:
|
||||
///
|
||||
/// try Optional<String>.fetchCursor(db, rawSQL: "SELECT name FROM ...", arguments:...) // Cursor of String?
|
||||
/// try Optional<String>.fetchAll(db, rawSQL: "SELECT name FROM ...", arguments:...) // [String?]
|
||||
/// try Optional<String>.fetchCursor(db, sql: "SELECT name FROM ...", arguments:...) // Cursor of String?
|
||||
/// try Optional<String>.fetchAll(db, sql: "SELECT name FROM ...", arguments:...) // [String?]
|
||||
///
|
||||
/// let statement = try db.makeSelectStatement("SELECT name FROM ...")
|
||||
/// try Optional<String>.fetchCursor(statement, arguments:...) // Cursor of String?
|
||||
@@ -562,7 +562,7 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a cursor over optional values fetched from an SQL query.
|
||||
///
|
||||
/// let names = try Optional<String>.fetchCursor(db, rawSQL: "SELECT name FROM ...") // Cursor of String?
|
||||
/// let names = try Optional<String>.fetchCursor(db, sql: "SELECT name FROM ...") // Cursor of String?
|
||||
/// while let name = try names.next() { // String?
|
||||
/// ...
|
||||
/// }
|
||||
@@ -579,13 +579,13 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A cursor over fetched optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor<Wrapped> {
|
||||
return try fetchCursor(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor<Wrapped> {
|
||||
return try fetchCursor(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of optional values fetched from an SQL query.
|
||||
///
|
||||
/// let names = try String.fetchAll(db, rawSQL: "SELECT name FROM ...") // [String?]
|
||||
/// let names = try String.fetchAll(db, sql: "SELECT name FROM ...") // [String?]
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
@@ -594,8 +594,8 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] {
|
||||
return try fetchAll(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] {
|
||||
return try fetchAll(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -605,7 +605,7 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a cursor over optional values fetched from an SQL query.
|
||||
///
|
||||
/// let firstNames = try Optional<String>.fetchCursor(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let firstNames = try Optional<String>.fetchCursor(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT firstName FROM player
|
||||
/// WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // Cursor of String?
|
||||
@@ -638,7 +638,7 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
|
||||
/// Returns an array of optional values fetched from an SQL query.
|
||||
///
|
||||
/// let firstNames = try Optional<String>.fetchAll(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let firstNames = try Optional<String>.fetchAll(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT firstName FROM player
|
||||
/// WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // [String?]
|
||||
|
||||
@@ -132,30 +132,30 @@ extension DatabaseWriter {
|
||||
// So we'll drop all database objects one after the other.
|
||||
try writeWithoutTransaction { db in
|
||||
// Prevent foreign keys from messing with drop table statements
|
||||
let foreignKeysEnabled = try Bool.fetchOne(db, rawSQL: "PRAGMA foreign_keys")!
|
||||
let foreignKeysEnabled = try Bool.fetchOne(db, sql: "PRAGMA foreign_keys")!
|
||||
if foreignKeysEnabled {
|
||||
try db.execute(rawSQL: "PRAGMA foreign_keys = OFF")
|
||||
try db.execute(sql: "PRAGMA foreign_keys = OFF")
|
||||
}
|
||||
|
||||
// Remove all database objects, one after the other
|
||||
do {
|
||||
try db.inTransaction {
|
||||
while let row = try Row.fetchOne(db, rawSQL: "SELECT type, name FROM sqlite_master WHERE name NOT LIKE 'sqlite_%'") {
|
||||
while let row = try Row.fetchOne(db, sql: "SELECT type, name FROM sqlite_master WHERE name NOT LIKE 'sqlite_%'") {
|
||||
let type: String = row["type"]
|
||||
let name: String = row["name"]
|
||||
try db.execute(rawSQL: "DROP \(type) \(name.quotedDatabaseIdentifier)")
|
||||
try db.execute(sql: "DROP \(type) \(name.quotedDatabaseIdentifier)")
|
||||
}
|
||||
return .commit
|
||||
}
|
||||
|
||||
// Restore foreign keys if needed
|
||||
if foreignKeysEnabled {
|
||||
try db.execute(rawSQL: "PRAGMA foreign_keys = ON")
|
||||
try db.execute(sql: "PRAGMA foreign_keys = ON")
|
||||
}
|
||||
} catch {
|
||||
// Restore foreign keys if needed
|
||||
if foreignKeysEnabled {
|
||||
try? db.execute(rawSQL: "PRAGMA foreign_keys = ON")
|
||||
try? db.execute(sql: "PRAGMA foreign_keys = ON")
|
||||
}
|
||||
throw error
|
||||
}
|
||||
@@ -172,7 +172,7 @@ extension DatabaseWriter {
|
||||
///
|
||||
/// See https://www.sqlite.org/lang_vacuum.html for more information.
|
||||
public func vacuum() throws {
|
||||
try writeWithoutTransaction { try $0.execute(rawSQL: "VACUUM") }
|
||||
try writeWithoutTransaction { try $0.execute(sql: "VACUUM") }
|
||||
}
|
||||
|
||||
// MARK: - Value Observation
|
||||
|
||||
@@ -47,7 +47,7 @@ extension FetchRequest {
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
let (statement, _) = try prepare(db)
|
||||
let sql = "SELECT COUNT(*) FROM (\(statement.sql))"
|
||||
return try Int.fetchOne(db, rawSQL: sql, arguments: statement.arguments)!
|
||||
return try Int.fetchOne(db, sql: sql, arguments: statement.arguments)!
|
||||
}
|
||||
|
||||
/// Returns the database region that the request looks into.
|
||||
@@ -129,7 +129,7 @@ public struct AnyFetchRequest<T> : FetchRequest {
|
||||
_fetchCount = { db in
|
||||
let (statement, _) = try prepare(db)
|
||||
let sql = "SELECT COUNT(*) FROM (\(statement.sql))"
|
||||
return try Int.fetchOne(db, rawSQL: sql, arguments: statement.arguments)!
|
||||
return try Int.fetchOne(db, sql: sql, arguments: statement.arguments)!
|
||||
}
|
||||
|
||||
_databaseRegion = { db in
|
||||
|
||||
+21
-21
@@ -14,8 +14,8 @@ public final class Row : Equatable, Hashable, RandomAccessCollection, Expressibl
|
||||
/// Unless we are producing a row array, we use a single row when iterating
|
||||
/// a statement:
|
||||
///
|
||||
/// let rows = try Row.fetchCursor(db, rawSQL: "SELECT ...")
|
||||
/// let players = try Player.fetchAll(db, rawSQL: "SELECT ...")
|
||||
/// let rows = try Row.fetchCursor(db, sql: "SELECT ...")
|
||||
/// let players = try Player.fetchAll(db, sql: "SELECT ...")
|
||||
///
|
||||
/// This row keeps an unmanaged reference to the statement, and a handle to
|
||||
/// the sqlite statement, so that we avoid many retain/release invocations.
|
||||
@@ -162,10 +162,10 @@ extension Row {
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// let row = try Row.fetchOne(db, rawSQL: "SELECT 'foo', 1")!
|
||||
/// let row = try Row.fetchOne(db, sql: "SELECT 'foo', 1")!
|
||||
/// row.containsNonNullValue // true
|
||||
///
|
||||
/// let row = try Row.fetchOne(db, rawSQL: "SELECT NULL, NULL")!
|
||||
/// let row = try Row.fetchOne(db, sql: "SELECT NULL, NULL")!
|
||||
/// row.containsNonNullValue // false
|
||||
public var containsNonNullValue: Bool {
|
||||
for i in (0..<count) where !impl.hasNull(atUncheckedIndex: i) {
|
||||
@@ -541,7 +541,7 @@ extension Row {
|
||||
///
|
||||
/// // Fetch
|
||||
/// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz"
|
||||
/// let row = try Row.fetchOne(db, rawSQL: sql, adapter: adapter)!
|
||||
/// let row = try Row.fetchOne(db, sql: sql, adapter: adapter)!
|
||||
///
|
||||
/// row.scopes.count // 2
|
||||
/// row.scopes.names // ["foo", "bar"]
|
||||
@@ -565,7 +565,7 @@ extension Row {
|
||||
///
|
||||
/// // Fetch
|
||||
/// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz"
|
||||
/// let row = try Row.fetchOne(db, rawSQL: sql, adapter: adapter)!
|
||||
/// let row = try Row.fetchOne(db, sql: sql, adapter: adapter)!
|
||||
///
|
||||
/// row.scopesTree.names // ["foo", "bar", "baz"]
|
||||
///
|
||||
@@ -602,7 +602,7 @@ extension Row {
|
||||
/// A cursor of database rows. For example:
|
||||
///
|
||||
/// try dbQueue.read { db in
|
||||
/// let rows: RowCursor = try Row.fetchCursor(db, rawSQL: "SELECT * FROM player")
|
||||
/// let rows: RowCursor = try Row.fetchCursor(db, sql: "SELECT * FROM player")
|
||||
/// }
|
||||
public final class RowCursor : Cursor {
|
||||
public let statement: SelectStatement
|
||||
@@ -722,7 +722,7 @@ extension Row {
|
||||
|
||||
/// Returns a cursor over rows fetched from an SQL query.
|
||||
///
|
||||
/// let rows = try Row.fetchCursor(db, rawSQL: "SELECT id, name FROM player") // RowCursor
|
||||
/// let rows = try Row.fetchCursor(db, sql: "SELECT id, name FROM player") // RowCursor
|
||||
/// while let row = try rows.next() { // Row
|
||||
/// let id: Int64 = row[0]
|
||||
/// let name: String = row[1]
|
||||
@@ -748,13 +748,13 @@ extension Row {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A cursor over fetched rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RowCursor {
|
||||
return try fetchCursor(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RowCursor {
|
||||
return try fetchCursor(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of rows fetched from an SQL query.
|
||||
///
|
||||
/// let rows = try Row.fetchAll(db, rawSQL: "SELECT id, name FROM player") // [Row]
|
||||
/// let rows = try Row.fetchAll(db, sql: "SELECT id, name FROM player") // [Row]
|
||||
/// for row in rows {
|
||||
/// let id: Int64 = row[0]
|
||||
/// let name: String = row[1]
|
||||
@@ -767,13 +767,13 @@ extension Row {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Row] {
|
||||
return try fetchAll(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Row] {
|
||||
return try fetchAll(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns a single row fetched from an SQL query.
|
||||
///
|
||||
/// let row = try Row.fetchOne(db, rawSQL: "SELECT id, name FROM player") // Row?
|
||||
/// let row = try Row.fetchOne(db, sql: "SELECT id, name FROM player") // Row?
|
||||
/// if let row = row {
|
||||
/// let id: Int64 = row[0]
|
||||
/// let name: String = row[1]
|
||||
@@ -786,8 +786,8 @@ extension Row {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An optional row.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Row? {
|
||||
return try fetchOne(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Row? {
|
||||
return try fetchOne(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -797,7 +797,7 @@ extension Row {
|
||||
|
||||
/// Returns a cursor over rows fetched from an SQL query.
|
||||
///
|
||||
/// let rows = try Row.fetchCursor(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let rows = try Row.fetchCursor(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT * FROM player WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // RowCursor
|
||||
/// while let row = try rows.next() { // Row
|
||||
@@ -838,7 +838,7 @@ extension Row {
|
||||
|
||||
/// Returns an array of rows fetched from an SQL query.
|
||||
///
|
||||
/// let rows = try Row.fetchAll(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let rows = try Row.fetchAll(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT * FROM player WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // [Row]
|
||||
/// for row in rows {
|
||||
@@ -866,7 +866,7 @@ extension Row {
|
||||
|
||||
/// Returns a single row fetched from an SQL query.
|
||||
///
|
||||
/// let row = try Row.fetchOne(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let row = try Row.fetchOne(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT * FROM player WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // Row?
|
||||
/// if let row = row {
|
||||
@@ -1203,7 +1203,7 @@ extension Row {
|
||||
///
|
||||
/// // Fetch
|
||||
/// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz"
|
||||
/// let row = try Row.fetchOne(db, rawSQL: sql, adapter: adapter)!
|
||||
/// let row = try Row.fetchOne(db, sql: sql, adapter: adapter)!
|
||||
///
|
||||
/// row.scopes.count // 2
|
||||
/// row.scopes.names // ["foo", "bar"]
|
||||
@@ -1278,7 +1278,7 @@ extension Row {
|
||||
///
|
||||
/// // Fetch
|
||||
/// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz"
|
||||
/// let row = try Row.fetchOne(db, rawSQL: sql, adapter: adapter)!
|
||||
/// let row = try Row.fetchOne(db, sql: sql, adapter: adapter)!
|
||||
///
|
||||
/// row.scopesTree.names // ["foo", "bar", "baz"]
|
||||
///
|
||||
|
||||
+10
-10
@@ -13,7 +13,7 @@ import Foundation
|
||||
/// "b": adapters[1],
|
||||
/// "c": adapters[2],
|
||||
/// "d": adapters[3]])
|
||||
/// let row = try Row.fetchOne(db, rawSQL: sql, adapter: adapter)
|
||||
/// let row = try Row.fetchOne(db, sql: sql, adapter: adapter)
|
||||
/// row.scopes["a"] // [1]
|
||||
/// row.scopes["b"] // [2, 3, 4]
|
||||
/// row.scopes["c"] // [5, 6]
|
||||
@@ -78,7 +78,7 @@ public struct LayoutedColumnMapping {
|
||||
/// }
|
||||
///
|
||||
/// // [foo:"foo" bar: "bar"]
|
||||
/// try Row.fetchOne(db, rawSQL: "SELECT NULL, 'foo', 'bar'", adapter: FooBarAdapter())
|
||||
/// try Row.fetchOne(db, sql: "SELECT NULL, 'foo', 'bar'", adapter: FooBarAdapter())
|
||||
public init<S: Sequence>(layoutColumns: S) where S.Iterator.Element == (Int, String) {
|
||||
self.layoutColumns = Array(layoutColumns)
|
||||
self.lowercaseColumnIndexes = Dictionary(
|
||||
@@ -201,7 +201,7 @@ extension SelectStatement : RowLayout {
|
||||
/// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz"
|
||||
///
|
||||
/// // [baz:3]
|
||||
/// try Row.fetchOne(db, rawSQL: sql, adapter: adapter)
|
||||
/// try Row.fetchOne(db, sql: sql, adapter: adapter)
|
||||
public protocol RowAdapter {
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
@@ -224,7 +224,7 @@ public protocol RowAdapter {
|
||||
/// }
|
||||
///
|
||||
/// // [foo:1]
|
||||
/// try Row.fetchOne(db, rawSQL: "SELECT 1, 2, 3", adapter: FirstColumnAdapter())
|
||||
/// try Row.fetchOne(db, sql: "SELECT 1, 2, 3", adapter: FirstColumnAdapter())
|
||||
func layoutedAdapter(from layout: RowLayout) throws -> LayoutedRowAdapter
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ public struct EmptyRowAdapter: RowAdapter {
|
||||
/// let sql = "SELECT 'foo' AS foo, 'bar' AS bar, 'baz' AS baz"
|
||||
///
|
||||
/// // [foo:"bar"]
|
||||
/// try Row.fetchOne(db, rawSQL: sql, adapter: adapter)
|
||||
/// try Row.fetchOne(db, sql: sql, adapter: adapter)
|
||||
public struct ColumnMapping : RowAdapter {
|
||||
/// A dictionary from mapped column names to column names in a base row.
|
||||
let mapping: [String: String]
|
||||
@@ -303,7 +303,7 @@ public struct ColumnMapping : RowAdapter {
|
||||
/// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz"
|
||||
///
|
||||
/// // [baz:3]
|
||||
/// try Row.fetchOne(db, rawSQL: sql, adapter: adapter)
|
||||
/// try Row.fetchOne(db, sql: sql, adapter: adapter)
|
||||
public struct SuffixRowAdapter : RowAdapter {
|
||||
/// The suffix index
|
||||
let index: Int
|
||||
@@ -330,7 +330,7 @@ public struct SuffixRowAdapter : RowAdapter {
|
||||
/// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz, 4 as qux"
|
||||
///
|
||||
/// // [bar:2 baz:3]
|
||||
/// try Row.fetchOne(db, rawSQL: sql, adapter: adapter)
|
||||
/// try Row.fetchOne(db, sql: sql, adapter: adapter)
|
||||
public struct RangeRowAdapter : RowAdapter {
|
||||
/// The range
|
||||
let range: CountableRange<Int>
|
||||
@@ -367,7 +367,7 @@ public struct RangeRowAdapter : RowAdapter {
|
||||
///
|
||||
/// // Fetch
|
||||
/// let sql = "SELECT 'foo' AS foo, 'bar' AS bar"
|
||||
/// let row = try Row.fetchOne(db, rawSQL: sql, adapter: adapter)!
|
||||
/// let row = try Row.fetchOne(db, sql: sql, adapter: adapter)!
|
||||
///
|
||||
/// // Scoped rows:
|
||||
/// if let fooRow = row.scopes["foo"] {
|
||||
@@ -389,7 +389,7 @@ public struct ScopeAdapter : RowAdapter {
|
||||
/// For example:
|
||||
///
|
||||
/// let adapter = ScopeAdapter(["suffix": SuffixRowAdapter(fromIndex: 1)])
|
||||
/// let row = try Row.fetchOne(db, rawSQL: "SELECT 1, 2, 3", adapter: adapter)!
|
||||
/// let row = try Row.fetchOne(db, sql: "SELECT 1, 2, 3", adapter: adapter)!
|
||||
/// row // [1, 2, 3]
|
||||
/// row.scopes["suffix"] // [2, 3]
|
||||
///
|
||||
@@ -406,7 +406,7 @@ public struct ScopeAdapter : RowAdapter {
|
||||
///
|
||||
/// let baseAdapter = RangeRowAdapter(0..<1)
|
||||
/// let adapter = ScopeAdapter(base: baseAdapter, scopes: ["suffix": SuffixRowAdapter(fromIndex: 1)])
|
||||
/// let row = try Row.fetchOne(db, rawSQL: "SELECT 1, 2, 3", adapter: adapter)!
|
||||
/// let row = try Row.fetchOne(db, sql: "SELECT 1, 2, 3", adapter: adapter)!
|
||||
/// row // [1]
|
||||
/// row.scopes["initial"] // [2, 3]
|
||||
///
|
||||
|
||||
@@ -18,8 +18,8 @@ public struct SQLInterpolation: StringInterpolationProtocol {
|
||||
self.sql += sql
|
||||
}
|
||||
|
||||
/// "SELECT * FROM \(rawSQL: "player")"
|
||||
public mutating func appendInterpolation(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) {
|
||||
/// "SELECT * FROM \(sql: "player")"
|
||||
public mutating func appendInterpolation(sql: String, arguments: StatementArguments = StatementArguments()) {
|
||||
self.sql += sql
|
||||
self.arguments += arguments
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ public struct SQLLiteral {
|
||||
private(set) public var sql: String
|
||||
private(set) public var arguments: StatementArguments
|
||||
|
||||
public init(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) {
|
||||
public init(sql: String, arguments: StatementArguments = StatementArguments()) {
|
||||
self.sql = sql
|
||||
self.arguments = arguments
|
||||
}
|
||||
@@ -32,8 +32,8 @@ extension SQLLiteral {
|
||||
self += sqlLiteral
|
||||
}
|
||||
|
||||
public mutating func append(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) {
|
||||
self += SQLLiteral(rawSQL: sql, arguments: arguments)
|
||||
public mutating func append(sql: String, arguments: StatementArguments = StatementArguments()) {
|
||||
self += SQLLiteral(sql: sql, arguments: arguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,22 +43,22 @@ extension SQLLiteral {
|
||||
extension SQLLiteral: ExpressibleByStringInterpolation {
|
||||
/// :nodoc
|
||||
public init(unicodeScalarLiteral: String) {
|
||||
self.init(rawSQL: unicodeScalarLiteral, arguments: [])
|
||||
self.init(sql: unicodeScalarLiteral, arguments: [])
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public init(extendedGraphemeClusterLiteral: String) {
|
||||
self.init(rawSQL: extendedGraphemeClusterLiteral, arguments: [])
|
||||
self.init(sql: extendedGraphemeClusterLiteral, arguments: [])
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public init(stringLiteral: String) {
|
||||
self.init(rawSQL: stringLiteral, arguments: [])
|
||||
self.init(sql: stringLiteral, arguments: [])
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public init(stringInterpolation sqlInterpolation: SQLInterpolation) {
|
||||
self.init(rawSQL: sqlInterpolation.sql, arguments: sqlInterpolation.arguments)
|
||||
self.init(sql: sqlInterpolation.sql, arguments: sqlInterpolation.arguments)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+10
-10
@@ -12,10 +12,10 @@ public struct SQLRequest<T> : FetchRequest {
|
||||
/// Creates a request from an SQL string, optional arguments, and
|
||||
/// optional row adapter.
|
||||
///
|
||||
/// let request = SQLRequest<String>(rawSQL: """
|
||||
/// let request = SQLRequest<String>(sql: """
|
||||
/// SELECT name FROM player
|
||||
/// """)
|
||||
/// let request = SQLRequest<Player>(rawSQL: """
|
||||
/// let request = SQLRequest<Player>(sql: """
|
||||
/// SELECT * FROM player WHERE id = ?
|
||||
/// """, arguments: [1])
|
||||
///
|
||||
@@ -26,16 +26,16 @@ public struct SQLRequest<T> : FetchRequest {
|
||||
/// - cached: Defaults to false. If true, the request reuses a cached
|
||||
/// prepared statement.
|
||||
/// - returns: A SQLRequest
|
||||
public init(rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil, cached: Bool = false) {
|
||||
self.init(literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter, fromCache: cached ? .public : nil)
|
||||
public init(sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil, cached: Bool = false) {
|
||||
self.init(literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter, fromCache: cached ? .public : nil)
|
||||
}
|
||||
|
||||
/// Creates a request from an SQLLiteral, and optional row adapter.
|
||||
///
|
||||
/// let request = SQLRequest<String>(literal: SQLLiteral(rawSQL: """
|
||||
/// let request = SQLRequest<String>(literal: SQLLiteral(sql: """
|
||||
/// SELECT name FROM player
|
||||
/// """))
|
||||
/// let request = SQLRequest<Player>(literal: SQLLiteral(rawSQL: """
|
||||
/// let request = SQLRequest<Player>(literal: SQLLiteral(sql: """
|
||||
/// SELECT * FROM player WHERE name = ?
|
||||
/// """, arguments: ["O'Brien"]))
|
||||
///
|
||||
@@ -67,7 +67,7 @@ public struct SQLRequest<T> : FetchRequest {
|
||||
/// - returns: An SQLRequest
|
||||
public init<Request: FetchRequest>(_ db: Database, request: Request, cached: Bool = false) throws where Request.RowDecoder == RowDecoder {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
self.init(literal: SQLLiteral(rawSQL: statement.sql, arguments: statement.arguments), adapter: adapter, cached: cached)
|
||||
self.init(literal: SQLLiteral(sql: statement.sql, arguments: statement.arguments), adapter: adapter, cached: cached)
|
||||
}
|
||||
|
||||
/// Creates an SQL request from an SQL string, optional arguments, and
|
||||
@@ -125,17 +125,17 @@ public struct SQLRequest<T> : FetchRequest {
|
||||
extension SQLRequest: ExpressibleByStringInterpolation {
|
||||
/// :nodoc
|
||||
public init(unicodeScalarLiteral: String) {
|
||||
self.init(rawSQL: unicodeScalarLiteral)
|
||||
self.init(sql: unicodeScalarLiteral)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public init(extendedGraphemeClusterLiteral: String) {
|
||||
self.init(rawSQL: extendedGraphemeClusterLiteral)
|
||||
self.init(sql: extendedGraphemeClusterLiteral)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public init(stringLiteral: String) {
|
||||
self.init(rawSQL: stringLiteral)
|
||||
self.init(sql: stringLiteral)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
|
||||
+13
-13
@@ -479,17 +479,17 @@ public final class UpdateStatement : Statement {
|
||||
// The statement did return a row, and the user ignores the
|
||||
// content of this row:
|
||||
//
|
||||
// try db.execute(rawSQL: "SELECT ...")
|
||||
// try db.execute(sql: "SELECT ...")
|
||||
//
|
||||
// That's OK: maybe the selected rows perform side effects.
|
||||
// For example:
|
||||
//
|
||||
// try db.execute(rawSQL: "SELECT sqlcipher_export(...)")
|
||||
// try db.execute(sql: "SELECT sqlcipher_export(...)")
|
||||
//
|
||||
// Or maybe the user doesn't know that the executed statement
|
||||
// return rows (https://github.com/groue/GRDB.swift/issues/15);
|
||||
//
|
||||
// try db.execute(rawSQL: "PRAGMA journal_mode=WAL")
|
||||
// try db.execute(sql: "PRAGMA journal_mode=WAL")
|
||||
//
|
||||
// It is thus important that we consume *all* rows.
|
||||
continue
|
||||
@@ -526,12 +526,12 @@ public final class UpdateStatement : Statement {
|
||||
/// To fill question marks placeholders, feed StatementArguments with an array:
|
||||
///
|
||||
/// db.execute(
|
||||
/// rawSQL: "INSERT ... (?, ?)",
|
||||
/// sql: "INSERT ... (?, ?)",
|
||||
/// arguments: StatementArguments(["Arthur", 41]))
|
||||
///
|
||||
/// // Array literals are automatically converted:
|
||||
/// db.execute(
|
||||
/// rawSQL: "INSERT ... (?, ?)",
|
||||
/// sql: "INSERT ... (?, ?)",
|
||||
/// arguments: ["Arthur", 41])
|
||||
///
|
||||
/// ## Named Arguments
|
||||
@@ -539,12 +539,12 @@ public final class UpdateStatement : Statement {
|
||||
/// To fill named arguments, feed StatementArguments with a dictionary:
|
||||
///
|
||||
/// db.execute(
|
||||
/// rawSQL: "INSERT ... (:name, :score)",
|
||||
/// sql: "INSERT ... (:name, :score)",
|
||||
/// arguments: StatementArguments(["name": "Arthur", "score": 41]))
|
||||
///
|
||||
/// // Dictionary literals are automatically converted:
|
||||
/// db.execute(
|
||||
/// rawSQL: "INSERT ... (:name, :score)",
|
||||
/// sql: "INSERT ... (:name, :score)",
|
||||
/// arguments: ["name": "Arthur", "score": 41])
|
||||
///
|
||||
/// ## Concatenating Arguments
|
||||
@@ -554,7 +554,7 @@ public final class UpdateStatement : Statement {
|
||||
///
|
||||
/// var arguments: StatementArguments = ["Arthur"]
|
||||
/// arguments += [41]
|
||||
/// db.execute(rawSQL: "INSERT ... (?, ?)", arguments: arguments)
|
||||
/// db.execute(sql: "INSERT ... (?, ?)", arguments: arguments)
|
||||
///
|
||||
/// `+` and `+=` operators consider that overriding named arguments is a
|
||||
/// programmer error:
|
||||
@@ -577,7 +577,7 @@ public final class UpdateStatement : Statement {
|
||||
///
|
||||
/// let sql = "SELECT ?2 AS two, :foo AS foo, ?1 AS one, :foo AS foo2, :bar AS bar"
|
||||
/// var arguments: StatementArguments = [1, 2, "bar"] + ["foo": "foo"]
|
||||
/// let row = try Row.fetchOne(db, rawSQL: sql, arguments: arguments)!
|
||||
/// let row = try Row.fetchOne(db, sql: sql, arguments: arguments)!
|
||||
/// print(row)
|
||||
/// // Prints [two:2 foo:"foo" one:1 foo2:"foo" bar:"bar"]
|
||||
///
|
||||
@@ -607,7 +607,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable, Expressibl
|
||||
/// Creates statement arguments from a sequence of optional values.
|
||||
///
|
||||
/// let values: [DatabaseValueConvertible?] = ["foo", 1, nil]
|
||||
/// db.execute(rawSQL: "INSERT ... (?,?,?)", arguments: StatementArguments(values))
|
||||
/// db.execute(sql: "INSERT ... (?,?,?)", arguments: StatementArguments(values))
|
||||
///
|
||||
/// - parameter sequence: A sequence of DatabaseValueConvertible values.
|
||||
/// - returns: A StatementArguments.
|
||||
@@ -618,7 +618,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable, Expressibl
|
||||
/// Creates statement arguments from a sequence of optional values.
|
||||
///
|
||||
/// let values: [String] = ["foo", "bar"]
|
||||
/// db.execute(rawSQL: "INSERT ... (?,?)", arguments: StatementArguments(values))
|
||||
/// db.execute(sql: "INSERT ... (?,?)", arguments: StatementArguments(values))
|
||||
///
|
||||
/// - parameter sequence: A sequence of DatabaseValueConvertible values.
|
||||
/// - returns: A StatementArguments.
|
||||
@@ -649,7 +649,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable, Expressibl
|
||||
/// such as a dictionary.
|
||||
///
|
||||
/// let values: [String: DatabaseValueConvertible?] = ["firstName": nil, "lastName": "Miller"]
|
||||
/// db.execute(rawSQL: "INSERT ... (:firstName, :lastName)", arguments: StatementArguments(values))
|
||||
/// db.execute(sql: "INSERT ... (:firstName, :lastName)", arguments: StatementArguments(values))
|
||||
///
|
||||
/// - parameter sequence: A sequence of (key, value) pairs
|
||||
/// - returns: A StatementArguments.
|
||||
@@ -661,7 +661,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable, Expressibl
|
||||
/// as a dictionary.
|
||||
///
|
||||
/// let values: [String: DatabaseValueConvertible?] = ["firstName": nil, "lastName": "Miller"]
|
||||
/// db.execute(rawSQL: "INSERT ... (:firstName, :lastName)", arguments: StatementArguments(values))
|
||||
/// db.execute(sql: "INSERT ... (:firstName, :lastName)", arguments: StatementArguments(values))
|
||||
///
|
||||
/// - parameter sequence: A sequence of (key, value) pairs
|
||||
/// - returns: A StatementArguments.
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
/// DatabaseValueConvertible. GRDB will then automatically apply the
|
||||
/// optimization whenever direct access to SQLite is possible:
|
||||
///
|
||||
/// let rows = Row.fetchCursor(db, rawSQL: "SELECT ...")
|
||||
/// let rows = Row.fetchCursor(db, sql: "SELECT ...")
|
||||
/// while let row = try rows.next() {
|
||||
/// let int: Int = row[0] // there
|
||||
/// }
|
||||
/// let ints = Int.fetchAll(db, rawSQL: "SELECT ...") // there
|
||||
/// let ints = Int.fetchAll(db, sql: "SELECT ...") // there
|
||||
/// struct Player {
|
||||
/// init(row: Row) {
|
||||
/// name = row["name"] // there
|
||||
@@ -54,7 +54,7 @@ public protocol StatementColumnConvertible {
|
||||
/// For example:
|
||||
///
|
||||
/// try dbQueue.read { db in
|
||||
/// let names: ColumnCursor<String> = try String.fetchCursor(db, rawSQL: "SELECT name FROM player")
|
||||
/// let names: ColumnCursor<String> = try String.fetchCursor(db, sql: "SELECT name FROM player")
|
||||
/// while let name = names.next() { // String
|
||||
/// print(name)
|
||||
/// }
|
||||
@@ -107,7 +107,7 @@ public final class FastDatabaseValueCursor<Value: DatabaseValueConvertible & Sta
|
||||
/// For example:
|
||||
///
|
||||
/// try dbQueue.read { db in
|
||||
/// let emails: NullableColumnCursor<String> = try Optional<String>.fetchCursor(db, rawSQL: "SELECT email FROM player")
|
||||
/// let emails: NullableColumnCursor<String> = try Optional<String>.fetchCursor(db, sql: "SELECT email FROM player")
|
||||
/// while let email = emails.next() { // String?
|
||||
/// print(email ?? "<NULL>")
|
||||
/// }
|
||||
@@ -228,7 +228,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
|
||||
/// Returns a cursor over values fetched from an SQL query.
|
||||
///
|
||||
/// let names = try String.fetchCursor(db, rawSQL: "SELECT name FROM ...") // Cursor of String
|
||||
/// let names = try String.fetchCursor(db, sql: "SELECT name FROM ...") // Cursor of String
|
||||
/// while let name = try names.next() { // String
|
||||
/// ...
|
||||
/// }
|
||||
@@ -245,13 +245,13 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor<Self> {
|
||||
return try fetchCursor(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor<Self> {
|
||||
return try fetchCursor(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of values fetched from an SQL query.
|
||||
///
|
||||
/// let names = try String.fetchAll(db, rawSQL: "SELECT name FROM ...") // [String]
|
||||
/// let names = try String.fetchAll(db, sql: "SELECT name FROM ...") // [String]
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
@@ -260,13 +260,13 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
return try fetchAll(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
return try fetchAll(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from an SQL query.
|
||||
///
|
||||
/// let name = try String.fetchOne(db, rawSQL: "SELECT name FROM ...") // String?
|
||||
/// let name = try String.fetchOne(db, sql: "SELECT name FROM ...") // String?
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
@@ -275,8 +275,8 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? {
|
||||
return try fetchOne(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? {
|
||||
return try fetchOne(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
|
||||
/// Returns a cursor over values fetched from an SQL query.
|
||||
///
|
||||
/// let firstNames = try String.fetchCursor(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let firstNames = try String.fetchCursor(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT firstName FROM player
|
||||
/// WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // Cursor of String
|
||||
@@ -319,7 +319,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
|
||||
/// Returns an array of values fetched from an SQL query.
|
||||
///
|
||||
/// let firstNames = try String.fetchAll(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let firstNames = try String.fetchAll(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT firstName FROM player
|
||||
/// WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // [String]
|
||||
@@ -350,7 +350,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// The result is nil if the query returns no row, or if no value can be
|
||||
/// extracted from the first row.
|
||||
///
|
||||
/// let firstName = try String.fetchOne(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let firstName = try String.fetchOne(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT firstName FROM player
|
||||
/// WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // String?
|
||||
@@ -486,8 +486,8 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol
|
||||
/// Swift's Optional comes with built-in methods that allow to fetch cursors
|
||||
/// and arrays of optional DatabaseValueConvertible:
|
||||
///
|
||||
/// try Optional<String>.fetchCursor(db, rawSQL: "SELECT name FROM ...", arguments:...) // Cursor of String?
|
||||
/// try Optional<String>.fetchAll(db, rawSQL: "SELECT name FROM ...", arguments:...) // [String?]
|
||||
/// try Optional<String>.fetchCursor(db, sql: "SELECT name FROM ...", arguments:...) // Cursor of String?
|
||||
/// try Optional<String>.fetchAll(db, sql: "SELECT name FROM ...", arguments:...) // [String?]
|
||||
///
|
||||
/// let statement = try db.makeSelectStatement("SELECT name FROM ...")
|
||||
/// try Optional<String>.fetchCursor(statement, arguments:...) // Cursor of String?
|
||||
@@ -543,7 +543,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv
|
||||
|
||||
/// Returns a cursor over optional values fetched from an SQL query.
|
||||
///
|
||||
/// let names = try Optional<String>.fetchCursor(db, rawSQL: "SELECT name FROM ...") // Cursor of String?
|
||||
/// let names = try Optional<String>.fetchCursor(db, sql: "SELECT name FROM ...") // Cursor of String?
|
||||
/// while let name = try names.next() { // String?
|
||||
/// ...
|
||||
/// }
|
||||
@@ -560,13 +560,13 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A cursor over fetched optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor<Wrapped> {
|
||||
return try fetchCursor(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor<Wrapped> {
|
||||
return try fetchCursor(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of optional values fetched from an SQL query.
|
||||
///
|
||||
/// let names = try String.fetchAll(db, rawSQL: "SELECT name FROM ...") // [String?]
|
||||
/// let names = try String.fetchAll(db, sql: "SELECT name FROM ...") // [String?]
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
@@ -575,8 +575,8 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] {
|
||||
return try fetchAll(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] {
|
||||
return try fetchAll(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,7 +586,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv
|
||||
|
||||
/// Returns a cursor over optional values fetched from an SQL query.
|
||||
///
|
||||
/// let firstNames = try Optional<String>.fetchCursor(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let firstNames = try Optional<String>.fetchCursor(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT firstName FROM player
|
||||
/// WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // Cursor of String?
|
||||
@@ -619,7 +619,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv
|
||||
|
||||
/// Returns an array of optional values fetched from an SQL query.
|
||||
///
|
||||
/// let firstNames = try Optional<String>.fetchAll(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let firstNames = try Optional<String>.fetchAll(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT firstName FROM player
|
||||
/// WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // [String?]
|
||||
|
||||
@@ -616,7 +616,7 @@ extension DatabaseCollation {
|
||||
/// You can use it when creating database tables:
|
||||
///
|
||||
/// let collationName = DatabaseCollation.caseInsensitiveCompare.name
|
||||
/// dbQueue.execute(rawSQL: """
|
||||
/// dbQueue.execute(sql: """
|
||||
/// CREATE TABLE players (
|
||||
/// name TEXT COLLATE \(collationName)
|
||||
/// )
|
||||
@@ -634,7 +634,7 @@ extension DatabaseCollation {
|
||||
/// You can use it when creating database tables:
|
||||
///
|
||||
/// let collationName = DatabaseCollation.caseInsensitiveCompare.name
|
||||
/// dbQueue.execute(rawSQL: """
|
||||
/// dbQueue.execute(sql: """
|
||||
/// CREATE TABLE players (
|
||||
/// name TEXT COLLATE \(collationName)
|
||||
/// )
|
||||
@@ -652,7 +652,7 @@ extension DatabaseCollation {
|
||||
/// You can use it when creating database tables:
|
||||
///
|
||||
/// let collationName = DatabaseCollation.localizedCaseInsensitiveCompare.name
|
||||
/// dbQueue.execute(rawSQL: """
|
||||
/// dbQueue.execute(sql: """
|
||||
/// CREATE TABLE players (
|
||||
/// name TEXT COLLATE \(collationName)
|
||||
/// )
|
||||
@@ -670,7 +670,7 @@ extension DatabaseCollation {
|
||||
/// You can use it when creating database tables:
|
||||
///
|
||||
/// let collationName = DatabaseCollation.localizedCompare.name
|
||||
/// dbQueue.execute(rawSQL: """
|
||||
/// dbQueue.execute(sql: """
|
||||
/// CREATE TABLE players (
|
||||
/// name TEXT COLLATE \(collationName)
|
||||
/// )
|
||||
@@ -688,7 +688,7 @@ extension DatabaseCollation {
|
||||
/// You can use it when creating database tables:
|
||||
///
|
||||
/// let collationName = DatabaseCollation.localizedStandardCompare.name
|
||||
/// dbQueue.execute(rawSQL: """
|
||||
/// dbQueue.execute(sql: """
|
||||
/// CREATE TABLE players (
|
||||
/// name TEXT COLLATE \(collationName)
|
||||
/// )
|
||||
|
||||
@@ -95,11 +95,11 @@ extension Database {
|
||||
/// let observer = MyObserver()
|
||||
/// dbQueue.add(transactionObserver: observer)
|
||||
/// dbQueue.inDatabase { db in
|
||||
/// try db.execute(rawSQL: "BEGIN TRANSACTION")
|
||||
/// try db.execute(sql: "BEGIN TRANSACTION")
|
||||
///
|
||||
/// Then a statement is executed:
|
||||
///
|
||||
/// try db.execute(rawSQL: "INSERT INTO document ...")
|
||||
/// try db.execute(sql: "INSERT INTO document ...")
|
||||
///
|
||||
/// The observation process starts when the statement is *compiled*:
|
||||
/// sqlite3_set_authorizer tells that the statement performs insertion into the
|
||||
@@ -117,7 +117,7 @@ extension Database {
|
||||
///
|
||||
/// Now a savepoint is started:
|
||||
///
|
||||
/// try db.execute(rawSQL: "SAVEPOINT foo")
|
||||
/// try db.execute(sql: "SAVEPOINT foo")
|
||||
///
|
||||
/// Statement compilation has sqlite3_set_authorizer tell that this statement
|
||||
/// begins a "foo" savepoint.
|
||||
@@ -128,7 +128,7 @@ extension Database {
|
||||
///
|
||||
/// Then another statement is executed:
|
||||
///
|
||||
/// try db.execute(rawSQL: "INSERT INTO document ...")
|
||||
/// try db.execute(sql: "INSERT INTO document ...")
|
||||
///
|
||||
/// This time, when the statement is *executed* and SQLite tells that a row has
|
||||
/// been inserted, the broker buffers the change event instead of immediately
|
||||
@@ -138,7 +138,7 @@ extension Database {
|
||||
///
|
||||
/// The savepoint is released:
|
||||
///
|
||||
/// try db.execute(rawSQL: "RELEASE SAVEPOINT foo")
|
||||
/// try db.execute(sql: "RELEASE SAVEPOINT foo")
|
||||
///
|
||||
/// Statement compilation has sqlite3_set_authorizer tell that this statement
|
||||
/// releases the "foo" savepoint.
|
||||
@@ -149,7 +149,7 @@ extension Database {
|
||||
///
|
||||
/// Finally the transaction is committed:
|
||||
///
|
||||
/// try db.execute(rawSQL: "COMMIT")
|
||||
/// try db.execute(sql: "COMMIT")
|
||||
///
|
||||
/// During the statement *execution*, SQlite tells the broker that the
|
||||
/// transaction is about to be committed through sqlite3_commit_hook. The broker
|
||||
@@ -440,8 +440,8 @@ class DatabaseObservationBroker {
|
||||
// SQLite, no transaction at all has started, and sqlite3_commit_hook
|
||||
// was not triggered:
|
||||
//
|
||||
// try db.execute(rawSQL: "BEGIN DEFERRED TRANSACTION")
|
||||
// try db.execute(rawSQL: "COMMIT") // <- no sqlite3_commit_hook callback invocation
|
||||
// try db.execute(sql: "BEGIN DEFERRED TRANSACTION")
|
||||
// try db.execute(sql: "COMMIT") // <- no sqlite3_commit_hook callback invocation
|
||||
//
|
||||
// Should we tell transaction observers of this transaction, or not?
|
||||
// The code says that a transaction was open, but SQLite says the
|
||||
@@ -517,7 +517,7 @@ class DatabaseObservationBroker {
|
||||
//
|
||||
// But we have to deal with a particular case:
|
||||
//
|
||||
// let journalMode = String.fetchOne(db, rawSQL: "PRAGMA journal_mode = wal")
|
||||
// let journalMode = String.fetchOne(db, sql: "PRAGMA journal_mode = wal")
|
||||
//
|
||||
// It runs a SelectStatement, not an UpdateStatement. But this not why
|
||||
// this case is particular. What is unexpected is that it triggers
|
||||
|
||||
@@ -19,8 +19,8 @@ public struct FTS3Pattern {
|
||||
// that pattern.
|
||||
do {
|
||||
try DatabaseQueue().inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE VIRTUAL TABLE documents USING fts3()")
|
||||
try db.execute(rawSQL: "SELECT * FROM documents WHERE content MATCH ?", arguments: [rawPattern])
|
||||
try db.execute(sql: "CREATE VIRTUAL TABLE documents USING fts3()")
|
||||
try db.execute(sql: "SELECT * FROM documents WHERE content MATCH ?", arguments: [rawPattern])
|
||||
}
|
||||
} catch let error as DatabaseError {
|
||||
// Remove private SQL & arguments from the thrown error
|
||||
|
||||
@@ -116,8 +116,8 @@ public struct FTS3TokenizerDescriptor {
|
||||
}
|
||||
let tokenizerSQL = tokenizerChunks.joined(separator: ", ")
|
||||
// Assume fts3tokenize virtual table in an in-memory database always succeeds
|
||||
try! db.execute(rawSQL: "CREATE VIRTUAL TABLE tokens USING fts3tokenize(\(tokenizerSQL))")
|
||||
return try! String.fetchAll(db, rawSQL: "SELECT token FROM tokens WHERE input = ? ORDER BY position", arguments: [string])
|
||||
try! db.execute(sql: "CREATE VIRTUAL TABLE tokens USING fts3tokenize(\(tokenizerSQL))")
|
||||
return try! String.fetchAll(db, sql: "SELECT token FROM tokens WHERE input = ? ORDER BY position", arguments: [string])
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -110,7 +110,7 @@ public struct FTS4 : VirtualTableModule {
|
||||
|
||||
let oldRowID = "old.\(rowIDColumn.quotedDatabaseIdentifier)"
|
||||
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TRIGGER \("__\(tableName)_bu".quotedDatabaseIdentifier) BEFORE UPDATE ON \(content) BEGIN
|
||||
DELETE FROM \(ftsTable) WHERE docid=\(oldRowID);
|
||||
END;
|
||||
@@ -127,7 +127,7 @@ public struct FTS4 : VirtualTableModule {
|
||||
|
||||
// https://www.sqlite.org/fts3.html#*fts4rebuidcmd
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO \(ftsTable)(\(ftsTable)) VALUES('rebuild')")
|
||||
try db.execute(sql: "INSERT INTO \(ftsTable)(\(ftsTable)) VALUES('rebuild')")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -318,7 +318,7 @@ public final class FTS4ColumnDefinition {
|
||||
extension Database {
|
||||
/// Deletes the synchronization triggers for a synchronized FTS4 table
|
||||
public func dropFTS4SynchronizationTriggers(forTable tableName: String) throws {
|
||||
try execute(rawSQL: """
|
||||
try execute(sql: """
|
||||
DROP TRIGGER IF EXISTS \("__\(tableName)_bu".quotedDatabaseIdentifier);
|
||||
DROP TRIGGER IF EXISTS \("__\(tableName)_bd".quotedDatabaseIdentifier);
|
||||
DROP TRIGGER IF EXISTS \("__\(tableName)_au".quotedDatabaseIdentifier);
|
||||
|
||||
+4
-4
@@ -110,7 +110,7 @@
|
||||
.map { "old.\($0.quotedDatabaseIdentifier)" }
|
||||
.joined(separator: ", ")
|
||||
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TRIGGER \("__\(tableName)_ai".quotedDatabaseIdentifier) AFTER INSERT ON \(content) BEGIN
|
||||
INSERT INTO \(ftsTable)(\(ftsColumns)) VALUES (\(newContentColumns));
|
||||
END;
|
||||
@@ -125,7 +125,7 @@
|
||||
|
||||
// https://sqlite.org/fts5.html#the_rebuild_command
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO \(ftsTable)(\(ftsTable)) VALUES('rebuild')")
|
||||
try db.execute(sql: "INSERT INTO \(ftsTable)(\(ftsTable)) VALUES('rebuild')")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@
|
||||
}
|
||||
|
||||
private static func api_v1(_ db: Database) -> UnsafePointer<fts5_api> {
|
||||
guard let data = try! Data.fetchOne(db, rawSQL: "SELECT fts5()") else {
|
||||
guard let data = try! Data.fetchOne(db, sql: "SELECT fts5()") else {
|
||||
fatalError("FTS5 is not available")
|
||||
}
|
||||
#if swift(>=5.0)
|
||||
@@ -371,7 +371,7 @@
|
||||
extension Database {
|
||||
/// Deletes the synchronization triggers for a synchronized FTS5 table
|
||||
public func dropFTS5SynchronizationTriggers(forTable tableName: String) throws {
|
||||
try execute(rawSQL: """
|
||||
try execute(sql: """
|
||||
DROP TRIGGER IF EXISTS \("__\(tableName)_ai".quotedDatabaseIdentifier);
|
||||
DROP TRIGGER IF EXISTS \("__\(tableName)_ad".quotedDatabaseIdentifier);
|
||||
DROP TRIGGER IF EXISTS \("__\(tableName)_au".quotedDatabaseIdentifier);
|
||||
|
||||
+16
-95
@@ -27,146 +27,67 @@ public typealias ColumnCursor<Value: DatabaseValueConvertible & StatementColumnC
|
||||
public typealias NullableColumnCursor<Value: DatabaseValueConvertible & StatementColumnConvertible> = FastNullableDatabaseValueCursor<Value>
|
||||
|
||||
extension Database {
|
||||
@available(*, unavailable, renamed: "execute(rawSQL:arguments:)")
|
||||
@available(*, unavailable, renamed: "execute(sql:arguments:)")
|
||||
public func execute(_ sql: String, arguments: StatementArguments? = nil) throws { }
|
||||
}
|
||||
|
||||
extension DatabaseValueConvertible {
|
||||
@available(*, unavailable, renamed: "fetchCursor(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchCursor(_:sql:arguments:adapter:)")
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseValueCursor<Self> { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "fetchAll(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchAll(_:sql:arguments:adapter:)")
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "fetchOne(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchOne(_:sql:arguments:adapter:)")
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
@available(*, unavailable, renamed: "fetchCursor(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchCursor(_:sql:arguments:adapter:)")
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor<Wrapped> { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "fetchAll(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchAll(_:sql:arguments:adapter:)")
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension Row {
|
||||
@available(*, unavailable, renamed: "fetchCursor(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchCursor(_:sql:arguments:adapter:)")
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RowCursor { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "fetchAll(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchAll(_:sql:arguments:adapter:)")
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Row] { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "fetchOne(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchOne(_:sql:arguments:adapter:)")
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Row? { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
@available(*, unavailable, renamed: "fetchCursor(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchCursor(_:sql:arguments:adapter:)")
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor<Self> { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConvertible {
|
||||
@available(*, unavailable, renamed: "fetchCursor(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchCursor(_:sql:arguments:adapter:)")
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor<Wrapped> { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension FetchableRecord {
|
||||
@available(*, unavailable, renamed: "fetchCursor(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchCursor(_:sql:arguments:adapter:)")
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RecordCursor<Self> { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "fetchAll(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchAll(_:sql:arguments:adapter:)")
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "fetchOne(_:rawSQL:arguments:adapter:)")
|
||||
@available(*, unavailable, renamed: "fetchOne(_:sql:arguments:adapter:)")
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension SQLRequest {
|
||||
@available(*, unavailable, renamed: "init(rawSQL:arguments:adapter:cached:)")
|
||||
@available(*, unavailable, renamed: "init(sql:arguments:adapter:cached:)")
|
||||
public init(_ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, cached: Bool = false) { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension SQLExpressionLiteral {
|
||||
@available(*, unavailable, renamed: "init(rawSQL:arguments:)")
|
||||
@available(*, unavailable, renamed: "init(sql:arguments:)")
|
||||
public init(_ sql: String, arguments: StatementArguments? = nil) { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension QueryInterfaceRequest {
|
||||
@available(*, unavailable, renamed: "select(rawSQL:arguments:as:)")
|
||||
public func select<RowDecoder>(sql: String, arguments: StatementArguments? = nil, as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension TableRecord {
|
||||
@available(*, unavailable, renamed: "select(rawSQL:arguments:)")
|
||||
public static func select(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest<Self> { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "select(rawSQL:arguments:as:)")
|
||||
public static func select<RowDecoder>(sql: String, arguments: StatementArguments? = nil, as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "filter(rawSQL:arguments:)")
|
||||
public static func filter(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest<Self> { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "order(rawSQL:arguments:)")
|
||||
public static func order(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest<Self> { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension SelectionRequest {
|
||||
@available(*, unavailable, renamed: "select(rawSQL:arguments:)")
|
||||
public func select(sql: String, arguments: StatementArguments? = nil) -> Self { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension FilteredRequest {
|
||||
@available(*, unavailable, renamed: "filter(rawSQL:arguments:)")
|
||||
public func filter(sql: String, arguments: StatementArguments? = nil) -> Self { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension AggregatingRequest {
|
||||
@available(*, unavailable, renamed: "group(rawSQL:arguments:)")
|
||||
public func group(sql: String, arguments: StatementArguments? = nil) -> Self { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "having(rawSQL:arguments:)")
|
||||
public func having(sql: String, arguments: StatementArguments? = nil) -> Self { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension OrderedRequest {
|
||||
@available(*, unavailable, renamed: "order(rawSQL:arguments:)")
|
||||
public func order(sql: String, arguments: StatementArguments? = nil) -> Self { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension TableDefinition {
|
||||
@available(*, unavailable, renamed: "check(rawSQL:)")
|
||||
public func check(sql: String) { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension ColumnDefinition {
|
||||
@available(*, unavailable, renamed: "check(rawSQL:)")
|
||||
public func check(sql: String) { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "defaults(rawSQL:)")
|
||||
public func defaults(sql: String) -> Self { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension FetchedRecordsController {
|
||||
@available(*, unavailable, renamed: "init(_:rawSQL:arguments:adapter:queue:isSameRecord:)")
|
||||
public convenience init(
|
||||
_ databaseWriter: DatabaseWriter,
|
||||
sql: String,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: RowAdapter? = nil,
|
||||
queue: DispatchQueue = .main,
|
||||
isSameRecord: ((Record, Record) -> Bool)? = nil) throws { preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, renamed: "setRequest(rawSQL:arguments:adapter:)")
|
||||
public func setRequest(sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { preconditionFailure() }
|
||||
}
|
||||
|
||||
extension FetchedRecordsController where Record: TableRecord {
|
||||
@available(*, unavailable, renamed: "init(_:rawSQL:arguments:adapter:queue:)")
|
||||
public convenience init(
|
||||
_ databaseWriter: DatabaseWriter,
|
||||
sql: String,
|
||||
arguments: StatementArguments? = nil,
|
||||
adapter: RowAdapter? = nil,
|
||||
queue: DispatchQueue = .main) throws { preconditionFailure() }
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public struct DatabaseMigrator {
|
||||
/// t.autoIncrementedPrimaryKey("id")
|
||||
/// t.column("name", .text).notNull()
|
||||
/// }
|
||||
/// try db.execute(rawSQL: "INSERT INTO new_player SELECT * FROM player")
|
||||
/// try db.execute(sql: "INSERT INTO new_player SELECT * FROM player")
|
||||
/// try db.drop(table: "player")
|
||||
/// try db.rename(table: "new_player", to: "player")
|
||||
/// }
|
||||
@@ -128,7 +128,7 @@ public struct DatabaseMigrator {
|
||||
/// t.autoIncrementedPrimaryKey("id")
|
||||
/// t.column("name", .text).notNull()
|
||||
/// }
|
||||
/// try db.execute(rawSQL: "INSERT INTO new_player SELECT * FROM player")
|
||||
/// try db.execute(sql: "INSERT INTO new_player SELECT * FROM player")
|
||||
/// try db.drop(table: "player")
|
||||
/// try db.rename(table: "new_player", to: "player")
|
||||
/// }
|
||||
@@ -237,11 +237,11 @@ public struct DatabaseMigrator {
|
||||
}
|
||||
|
||||
private func setupMigrations(_ db: Database) throws {
|
||||
try db.execute(rawSQL: "CREATE TABLE IF NOT EXISTS grdb_migrations (identifier TEXT NOT NULL PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE IF NOT EXISTS grdb_migrations (identifier TEXT NOT NULL PRIMARY KEY)")
|
||||
}
|
||||
|
||||
private func appliedIdentifiers(_ db: Database) throws -> Set<String> {
|
||||
return try Set(String.fetchAll(db, rawSQL: "SELECT identifier FROM grdb_migrations"))
|
||||
return try Set(String.fetchAll(db, sql: "SELECT identifier FROM grdb_migrations"))
|
||||
}
|
||||
|
||||
private func runMigrations(_ db: Database, upTo targetIdentifier: String) throws {
|
||||
|
||||
@@ -28,7 +28,7 @@ struct Migration {
|
||||
#endif
|
||||
|
||||
func run(_ db: Database) throws {
|
||||
if try disabledForeignKeyChecks && (Bool.fetchOne(db, rawSQL: "PRAGMA foreign_keys") ?? false) {
|
||||
if try disabledForeignKeyChecks && (Bool.fetchOne(db, sql: "PRAGMA foreign_keys") ?? false) {
|
||||
try runWithDisabledForeignKeys(db)
|
||||
} else {
|
||||
try runWithoutDisabledForeignKeys(db)
|
||||
@@ -50,7 +50,7 @@ struct Migration {
|
||||
//
|
||||
// > 1. If foreign key constraints are enabled, disable them using
|
||||
// > PRAGMA foreign_keys=OFF.
|
||||
try db.execute(rawSQL: "PRAGMA foreign_keys = OFF")
|
||||
try db.execute(sql: "PRAGMA foreign_keys = OFF")
|
||||
|
||||
// > 2. Start a transaction.
|
||||
try db.inTransaction(.immediate) {
|
||||
@@ -60,7 +60,7 @@ struct Migration {
|
||||
// > 10. If foreign key constraints were originally enabled then run PRAGMA
|
||||
// > foreign_key_check to verify that the schema change did not break any foreign key
|
||||
// > constraints.
|
||||
if try Row.fetchOne(db, rawSQL: "PRAGMA foreign_key_check") != nil {
|
||||
if try Row.fetchOne(db, sql: "PRAGMA foreign_key_check") != nil {
|
||||
// https://www.sqlite.org/pragma.html#pragma_foreign_key_check
|
||||
//
|
||||
// PRAGMA foreign_key_check does not return an error,
|
||||
@@ -76,10 +76,10 @@ struct Migration {
|
||||
}
|
||||
|
||||
// > 12. If foreign keys constraints were originally enabled, reenable them now.
|
||||
try db.execute(rawSQL: "PRAGMA foreign_keys = ON")
|
||||
try db.execute(sql: "PRAGMA foreign_keys = ON")
|
||||
}
|
||||
|
||||
private func insertAppliedIdentifier(_ db: Database) throws {
|
||||
try db.execute(rawSQL: "INSERT INTO grdb_migrations (identifier) VALUES (?)", arguments: [identifier])
|
||||
try db.execute(sql: "INSERT INTO grdb_migrations (identifier) VALUES (?)", arguments: [identifier])
|
||||
}
|
||||
}
|
||||
@@ -103,11 +103,11 @@ extension QueryInterfaceRequest : DerivableRequest, AggregatingRequest {
|
||||
///
|
||||
/// try dbQueue.read { db in
|
||||
/// // SELECT max(score) FROM player
|
||||
/// let request = Player.all().select(rawSQL: "max(score)", as: Int.self)
|
||||
/// let request = Player.all().select(sql: "max(score)", as: Int.self)
|
||||
/// let maxScore: Int? = try request.fetchOne(db)
|
||||
/// }
|
||||
public func select<RowDecoder>(rawSQL sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
return select(literal: SQLLiteral(rawSQL: sql, arguments: arguments), as: type)
|
||||
public func select<RowDecoder>(sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
return select(literal: SQLLiteral(sql: sql, arguments: arguments), as: type)
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*, and fetches values of
|
||||
@@ -119,7 +119,7 @@ extension QueryInterfaceRequest : DerivableRequest, AggregatingRequest {
|
||||
/// .filter(primaryKey: 42)
|
||||
/// .select(
|
||||
/// SQLLiteral(
|
||||
/// rawSQL: "IFNULL(name, ?)",
|
||||
/// sql: "IFNULL(name, ?)",
|
||||
/// arguments: ["Anonymous"]),
|
||||
/// as: String.self)
|
||||
/// let name: String? = try request.fetchOne(db)
|
||||
@@ -370,15 +370,15 @@ extension TableRecord {
|
||||
/// Creates a request which selects *sql*.
|
||||
///
|
||||
/// // SELECT id, email FROM player
|
||||
/// let request = Player.select(rawSQL: "id, email")
|
||||
public static func select(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self> {
|
||||
return select(literal: SQLLiteral(rawSQL: sql, arguments: arguments))
|
||||
/// let request = Player.select(sql: "id, email")
|
||||
public static func select(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self> {
|
||||
return select(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*.
|
||||
///
|
||||
/// // SELECT id, email FROM player
|
||||
/// let request = Player.select(literal: SQLLiteral(rawSQL: "id, email"))
|
||||
/// let request = Player.select(literal: SQLLiteral(sql: "id, email"))
|
||||
public static func select(literal sqlLiteral: SQLLiteral) -> QueryInterfaceRequest<Self> {
|
||||
return all().select(literal: sqlLiteral)
|
||||
}
|
||||
@@ -412,11 +412,11 @@ extension TableRecord {
|
||||
///
|
||||
/// try dbQueue.read { db in
|
||||
/// // SELECT max(score) FROM player
|
||||
/// let request = Player.select(rawSQL: "max(score)", as: Int.self)
|
||||
/// let request = Player.select(sql: "max(score)", as: Int.self)
|
||||
/// let maxScore: Int? = try request.fetchOne(db)
|
||||
/// }
|
||||
public static func select<RowDecoder>(rawSQL sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
return all().select(literal: SQLLiteral(rawSQL: sql, arguments: arguments), as: type)
|
||||
public static func select<RowDecoder>(sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
return all().select(literal: SQLLiteral(sql: sql, arguments: arguments), as: type)
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*, and fetches values of
|
||||
@@ -424,7 +424,7 @@ extension TableRecord {
|
||||
///
|
||||
/// try dbQueue.read { db in
|
||||
/// // SELECT max(score) FROM player
|
||||
/// let request = Player.select(literal: SQLLiteral(rawSQL: "max(score)"), as: Int.self)
|
||||
/// let request = Player.select(literal: SQLLiteral(sql: "max(score)"), as: Int.self)
|
||||
/// let maxScore: Int? = try request.fetchOne(db)
|
||||
/// }
|
||||
public static func select<RowDecoder>(literal sqlLiteral: SQLLiteral, as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
@@ -500,19 +500,19 @@ extension TableRecord {
|
||||
/// Creates a request with the provided *predicate*.
|
||||
///
|
||||
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
|
||||
/// let request = Player.filter(rawSQL: "email = ?", arguments: ["arthur@example.com"])
|
||||
/// let request = Player.filter(sql: "email = ?", arguments: ["arthur@example.com"])
|
||||
///
|
||||
/// The selection defaults to all columns. This default can be changed for
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func filter(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self> {
|
||||
return filter(literal: SQLLiteral(rawSQL: sql, arguments: arguments))
|
||||
public static func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self> {
|
||||
return filter(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *predicate*.
|
||||
///
|
||||
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
|
||||
/// let request = Player.filter(literal: SQLLiteral(rawSQL: "email = ?", arguments: ["arthur@example.com"]))
|
||||
/// let request = Player.filter(literal: SQLLiteral(sql: "email = ?", arguments: ["arthur@example.com"]))
|
||||
///
|
||||
/// With Swift 5, you can safely embed raw values in your SQL queries,
|
||||
/// without any risk of syntax errors or SQL injection:
|
||||
@@ -571,19 +571,19 @@ extension TableRecord {
|
||||
/// Creates a request sorted according to *sql*.
|
||||
///
|
||||
/// // SELECT * FROM player ORDER BY name
|
||||
/// let request = Player.order(rawSQL: "name")
|
||||
/// let request = Player.order(sql: "name")
|
||||
///
|
||||
/// The selection defaults to all columns. This default can be changed for
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func order(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self> {
|
||||
return all().order(literal: SQLLiteral(rawSQL: sql, arguments: arguments))
|
||||
public static func order(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self> {
|
||||
return all().order(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request sorted according to *sql*.
|
||||
///
|
||||
/// // SELECT * FROM player ORDER BY name
|
||||
/// let request = Player.order(literal: SQLLiteral(rawSQL: "name"))
|
||||
/// let request = Player.order(literal: SQLLiteral(sql: "name"))
|
||||
///
|
||||
/// With Swift 5, you can safely embed raw values in your SQL queries,
|
||||
/// without any risk of syntax errors or SQL injection:
|
||||
|
||||
@@ -43,16 +43,16 @@ extension SelectionRequest {
|
||||
///
|
||||
/// // SELECT id, email FROM player
|
||||
/// var request = Player.all()
|
||||
/// request = request.select(rawSQL: "id, email")
|
||||
/// request = request.select(sql: "id, email")
|
||||
///
|
||||
/// Any previous selection is replaced:
|
||||
///
|
||||
/// // SELECT email FROM player
|
||||
/// request
|
||||
/// .select(rawSQL: "id")
|
||||
/// .select(rawSQL: "email")
|
||||
public func select(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return select(literal: SQLLiteral(rawSQL: sql, arguments: arguments))
|
||||
/// .select(sql: "id")
|
||||
/// .select(sql: "email")
|
||||
public func select(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return select(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*.
|
||||
@@ -60,7 +60,7 @@ extension SelectionRequest {
|
||||
/// // SELECT id, email, score + 1000 FROM player
|
||||
/// let bonus = 1000
|
||||
/// var request = Player.all()
|
||||
/// request = request.select(literal: SQLLiteral(rawSQL: """
|
||||
/// request = request.select(literal: SQLLiteral(sql: """
|
||||
/// id, email, score + ?
|
||||
/// """, arguments: [bonus]))
|
||||
///
|
||||
@@ -79,7 +79,7 @@ extension SelectionRequest {
|
||||
/// // SELECT email FROM player
|
||||
/// request
|
||||
/// .select(...)
|
||||
/// .select(literal: SQLLiteral(rawSQL: "email"))
|
||||
/// .select(literal: SQLLiteral(sql: "email"))
|
||||
public func select(literal sqlLiteral: SQLLiteral) -> Self {
|
||||
// NOT TESTED
|
||||
return select(SQLSelectionLiteral(literal: sqlLiteral))
|
||||
@@ -120,9 +120,9 @@ extension FilteredRequest {
|
||||
///
|
||||
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
|
||||
/// var request = Player.all()
|
||||
/// request = request.filter(rawSQL: "email = ?", arguments: ["arthur@example.com"])
|
||||
public func filter(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return filter(literal: SQLLiteral(rawSQL: sql, arguments: arguments))
|
||||
/// request = request.filter(sql: "email = ?", arguments: ["arthur@example.com"])
|
||||
public func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return filter(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *predicate* added to the
|
||||
@@ -130,7 +130,7 @@ extension FilteredRequest {
|
||||
///
|
||||
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
|
||||
/// var request = Player.all()
|
||||
/// request = request.filter(literal: SQLLiteral(rawSQL: """
|
||||
/// request = request.filter(literal: SQLLiteral(sql: """
|
||||
/// email = ?
|
||||
/// """, arguments: ["arthur@example.com"])
|
||||
///
|
||||
@@ -320,8 +320,8 @@ extension AggregatingRequest {
|
||||
}
|
||||
|
||||
/// Creates a request with a new grouping.
|
||||
public func group(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return group(literal: SQLLiteral(rawSQL: sql, arguments: arguments))
|
||||
public func group(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return group(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with a new grouping.
|
||||
@@ -340,8 +340,8 @@ extension AggregatingRequest {
|
||||
|
||||
/// Creates a request with the provided *sql* added to the
|
||||
/// eventual set of already applied predicates.
|
||||
public func having(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return having(literal: SQLLiteral(rawSQL: sql, arguments: arguments))
|
||||
public func having(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return having(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *sql* added to the
|
||||
@@ -429,16 +429,16 @@ extension OrderedRequest {
|
||||
///
|
||||
/// // SELECT * FROM player ORDER BY name
|
||||
/// var request = Player.all()
|
||||
/// request = request.order(rawSQL: "name")
|
||||
/// request = request.order(sql: "name")
|
||||
///
|
||||
/// Any previous ordering is replaced:
|
||||
///
|
||||
/// // SELECT * FROM player ORDER BY name
|
||||
/// request
|
||||
/// .order(rawSQL: "email")
|
||||
/// .order(rawSQL: "name")
|
||||
public func order(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return order(literal: SQLLiteral(rawSQL: sql, arguments: arguments))
|
||||
/// .order(sql: "email")
|
||||
/// .order(sql: "name")
|
||||
public func order(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return order(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *sql* used for sorting.
|
||||
|
||||
@@ -9,7 +9,7 @@ extension SQLExpression {
|
||||
public var sqlLiteral: SQLLiteral {
|
||||
var context = SQLGenerationContext.literalGenerationContext(withArguments: true)
|
||||
let sql = expressionSQL(&context)
|
||||
return SQLLiteral(rawSQL: sql, arguments: context.arguments!)
|
||||
return SQLLiteral(sql: sql, arguments: context.arguments!)
|
||||
}
|
||||
|
||||
/// The expression as a quoted SQL literal (not public in order to avoid abuses)
|
||||
@@ -27,12 +27,12 @@ extension SQLExpression {
|
||||
///
|
||||
/// SQLExpressionLiteral is an expression built from a raw SQL snippet.
|
||||
///
|
||||
/// SQLExpressionLiteral(rawSQL: "1 + 2")
|
||||
/// SQLExpressionLiteral(sql: "1 + 2")
|
||||
///
|
||||
/// The SQL literal may contain `?` and colon-prefixed arguments:
|
||||
///
|
||||
/// SQLExpressionLiteral(rawSQL: "? + ?", arguments: [1, 2])
|
||||
/// SQLExpressionLiteral(rawSQL: ":one + :two", arguments: ["one": 1, "two": 2])
|
||||
/// SQLExpressionLiteral(sql: "? + ?", arguments: [1, 2])
|
||||
/// SQLExpressionLiteral(sql: ":one + :two", arguments: ["one": 1, "two": 2])
|
||||
public struct SQLExpressionLiteral : SQLExpression {
|
||||
private let sqlLiteral: SQLLiteral
|
||||
|
||||
@@ -40,20 +40,20 @@ public struct SQLExpressionLiteral : SQLExpression {
|
||||
///
|
||||
/// Creates an SQL literal expression.
|
||||
///
|
||||
/// SQLExpressionLiteral(rawSQL: "1 + 2")
|
||||
/// SQLExpressionLiteral(rawSQL: "? + ?", arguments: [1, 2])
|
||||
/// SQLExpressionLiteral(rawSQL: ":one + :two", arguments: ["one": 1, "two": 2])
|
||||
public init(rawSQL sql: String, arguments: StatementArguments = StatementArguments()) {
|
||||
self.init(literal: SQLLiteral(rawSQL: sql, arguments: arguments))
|
||||
/// SQLExpressionLiteral(sql: "1 + 2")
|
||||
/// SQLExpressionLiteral(sql: "? + ?", arguments: [1, 2])
|
||||
/// SQLExpressionLiteral(sql: ":one + :two", arguments: ["one": 1, "two": 2])
|
||||
public init(sql: String, arguments: StatementArguments = StatementArguments()) {
|
||||
self.init(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// Creates an SQL literal expression.
|
||||
///
|
||||
/// SQLExpressionLiteral(literal: SQLLiteral(rawSQL: "1 + 2")
|
||||
/// SQLExpressionLiteral(literal: SQLLiteral(rawSQL: "? + ?", arguments: [1, 2]))
|
||||
/// SQLExpressionLiteral(literal: SQLLiteral(rawSQL: ":one + :two", arguments: ["one": 1, "two": 2]))
|
||||
/// SQLExpressionLiteral(literal: SQLLiteral(sql: "1 + 2")
|
||||
/// SQLExpressionLiteral(literal: SQLLiteral(sql: "? + ?", arguments: [1, 2]))
|
||||
/// SQLExpressionLiteral(literal: SQLLiteral(sql: ":one + :two", arguments: ["one": 1, "two": 2]))
|
||||
///
|
||||
/// With Swift 5, you can safely embed raw values in your SQL queries,
|
||||
/// without any risk of syntax errors or SQL injection:
|
||||
|
||||
@@ -29,7 +29,7 @@ extension Database {
|
||||
let definition = TableDefinition(name: name, temporary: temporary, ifNotExists: ifNotExists, withoutRowID: withoutRowID)
|
||||
body(definition)
|
||||
let sql = try definition.sql(self)
|
||||
try execute(rawSQL: sql)
|
||||
try execute(sql: sql)
|
||||
}
|
||||
#else
|
||||
/// Creates a database table.
|
||||
@@ -61,7 +61,7 @@ extension Database {
|
||||
let definition = TableDefinition(name: name, temporary: temporary, ifNotExists: ifNotExists, withoutRowID: withoutRowID)
|
||||
body(definition)
|
||||
let sql = try definition.sql(self)
|
||||
try execute(rawSQL: sql)
|
||||
try execute(sql: sql)
|
||||
}
|
||||
|
||||
/// Creates a database table.
|
||||
@@ -88,7 +88,7 @@ extension Database {
|
||||
let definition = TableDefinition(name: name, temporary: temporary, ifNotExists: ifNotExists, withoutRowID: false)
|
||||
body(definition)
|
||||
let sql = try definition.sql(self)
|
||||
try execute(rawSQL: sql)
|
||||
try execute(sql: sql)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -98,7 +98,7 @@ extension Database {
|
||||
///
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs.
|
||||
public func rename(table name: String, to newName: String) throws {
|
||||
try execute(rawSQL: "ALTER TABLE \(name.quotedDatabaseIdentifier) RENAME TO \(newName.quotedDatabaseIdentifier)")
|
||||
try execute(sql: "ALTER TABLE \(name.quotedDatabaseIdentifier) RENAME TO \(newName.quotedDatabaseIdentifier)")
|
||||
}
|
||||
|
||||
/// Modifies a database table.
|
||||
@@ -117,7 +117,7 @@ extension Database {
|
||||
let alteration = TableAlteration(name: name)
|
||||
body(alteration)
|
||||
let sql = try alteration.sql(self)
|
||||
try execute(rawSQL: sql)
|
||||
try execute(sql: sql)
|
||||
}
|
||||
|
||||
/// Deletes a database table.
|
||||
@@ -126,7 +126,7 @@ extension Database {
|
||||
///
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs.
|
||||
public func drop(table name: String) throws {
|
||||
try execute(rawSQL: "DROP TABLE \(name.quotedDatabaseIdentifier)")
|
||||
try execute(sql: "DROP TABLE \(name.quotedDatabaseIdentifier)")
|
||||
}
|
||||
|
||||
#if GRDBCUSTOMSQLITE || GRDBCIPHER
|
||||
@@ -138,7 +138,7 @@ extension Database {
|
||||
/// and use specific collations. To create such an index, use a raw SQL
|
||||
/// query.
|
||||
///
|
||||
/// try db.execute(rawSQL: "CREATE INDEX ...")
|
||||
/// try db.execute(sql: "CREATE INDEX ...")
|
||||
///
|
||||
/// See https://www.sqlite.org/lang_createindex.html
|
||||
///
|
||||
@@ -155,7 +155,7 @@ extension Database {
|
||||
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
|
||||
let definition = IndexDefinition(name: name, table: table, columns: columns, unique: unique, ifNotExists: ifNotExists, condition: condition?.sqlExpression)
|
||||
let sql = definition.sql()
|
||||
try execute(rawSQL: sql)
|
||||
try execute(sql: sql)
|
||||
}
|
||||
#else
|
||||
/// Creates an index.
|
||||
@@ -166,7 +166,7 @@ extension Database {
|
||||
/// and use specific collations. To create such an index, use a raw SQL
|
||||
/// query.
|
||||
///
|
||||
/// try db.execute(rawSQL: "CREATE INDEX ...")
|
||||
/// try db.execute(sql: "CREATE INDEX ...")
|
||||
///
|
||||
/// See https://www.sqlite.org/lang_createindex.html
|
||||
///
|
||||
@@ -181,7 +181,7 @@ extension Database {
|
||||
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
|
||||
let definition = IndexDefinition(name: name, table: table, columns: columns, unique: unique, ifNotExists: ifNotExists, condition: nil)
|
||||
let sql = definition.sql()
|
||||
try execute(rawSQL: sql)
|
||||
try execute(sql: sql)
|
||||
}
|
||||
|
||||
/// Creates a partial index.
|
||||
@@ -204,7 +204,7 @@ extension Database {
|
||||
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
|
||||
let definition = IndexDefinition(name: name, table: table, columns: columns, unique: unique, ifNotExists: ifNotExists, condition: condition.sqlExpression)
|
||||
let sql = definition.sql()
|
||||
try execute(rawSQL: sql)
|
||||
try execute(sql: sql)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -214,7 +214,7 @@ extension Database {
|
||||
///
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs.
|
||||
public func drop(index name: String) throws {
|
||||
try execute(rawSQL: "DROP INDEX \(name.quotedDatabaseIdentifier)")
|
||||
try execute(sql: "DROP INDEX \(name.quotedDatabaseIdentifier)")
|
||||
}
|
||||
|
||||
/// Delete and recreate from scratch all indices that use this collation.
|
||||
@@ -226,7 +226,7 @@ extension Database {
|
||||
///
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs.
|
||||
public func reindex(collation: Database.CollationName) throws {
|
||||
try execute(rawSQL: "REINDEX \(collation.rawValue)")
|
||||
try execute(sql: "REINDEX \(collation.rawValue)")
|
||||
}
|
||||
|
||||
/// Delete and recreate from scratch all indices that use this collation.
|
||||
@@ -409,16 +409,16 @@ public final class TableDefinition {
|
||||
/// try db.create(table: "player") { t in
|
||||
/// t.column("personalPhone", .text)
|
||||
/// t.column("workPhone", .text)
|
||||
/// t.check(rawSQL: "personalPhone IS NOT NULL OR workPhone IS NOT NULL")
|
||||
/// t.check(sql: "personalPhone IS NOT NULL OR workPhone IS NOT NULL")
|
||||
/// }
|
||||
///
|
||||
/// See https://www.sqlite.org/lang_createtable.html#ckconst
|
||||
///
|
||||
/// - parameter sql: An SQL snippet
|
||||
public func check(rawSQL sql: String) {
|
||||
public func check(sql: String) {
|
||||
// We do not want to wrap the SQL snippet inside parentheses around the
|
||||
// checked SQL. This is why we use the "unsafeLiteral" initializer.
|
||||
checkConstraints.append(SQLExpressionLiteral(unsafeLiteral: SQLLiteral(rawSQL: sql)))
|
||||
checkConstraints.append(SQLExpressionLiteral(unsafeLiteral: SQLLiteral(sql: sql)))
|
||||
}
|
||||
|
||||
fileprivate func sql(_ db: Database) throws -> String {
|
||||
@@ -712,7 +712,7 @@ public final class ColumnDefinition {
|
||||
/// Adds a CHECK constraint on the column.
|
||||
///
|
||||
/// try db.create(table: "player") { t in
|
||||
/// t.column("name", .text).check(rawSQL: "LENGTH(name) > 0")
|
||||
/// t.column("name", .text).check(sql: "LENGTH(name) > 0")
|
||||
/// }
|
||||
///
|
||||
/// See https://www.sqlite.org/lang_createtable.html#ckconst
|
||||
@@ -720,10 +720,10 @@ public final class ColumnDefinition {
|
||||
/// - parameter sql: An SQL snippet.
|
||||
/// - returns: Self so that you can further refine the column definition.
|
||||
@discardableResult
|
||||
public func check(rawSQL sql: String) -> Self {
|
||||
public func check(sql: String) -> Self {
|
||||
// We do not want to wrap the SQL snippet inside parentheses around the
|
||||
// checked SQL. This is why we use the "unsafeLiteral" initializer.
|
||||
checkConstraints.append(SQLExpressionLiteral(unsafeLiteral: SQLLiteral(rawSQL: sql)))
|
||||
checkConstraints.append(SQLExpressionLiteral(unsafeLiteral: SQLLiteral(sql: sql)))
|
||||
return self
|
||||
}
|
||||
|
||||
@@ -746,7 +746,7 @@ public final class ColumnDefinition {
|
||||
/// Defines the default column value.
|
||||
///
|
||||
/// try db.create(table: "player") { t in
|
||||
/// t.column("creationDate", .DateTime).defaults(rawSQL: "CURRENT_TIMESTAMP")
|
||||
/// t.column("creationDate", .DateTime).defaults(sql: "CURRENT_TIMESTAMP")
|
||||
/// }
|
||||
///
|
||||
/// See https://www.sqlite.org/lang_createtable.html#dfltval
|
||||
@@ -754,10 +754,10 @@ public final class ColumnDefinition {
|
||||
/// - parameter sql: An SQL snippet.
|
||||
/// - returns: Self so that you can further refine the column definition.
|
||||
@discardableResult
|
||||
public func defaults(rawSQL sql: String) -> Self {
|
||||
public func defaults(sql: String) -> Self {
|
||||
// We do not want to wrap the SQL snippet inside parentheses around the
|
||||
// checked SQL. This is why we use the "unsafeLiteral" initializer.
|
||||
defaultExpression = SQLExpressionLiteral(unsafeLiteral: SQLLiteral(rawSQL: sql))
|
||||
defaultExpression = SQLExpressionLiteral(unsafeLiteral: SQLLiteral(sql: sql))
|
||||
return self
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ extension Database {
|
||||
chunks.append("USING")
|
||||
chunks.append(module)
|
||||
let sql = chunks.joined(separator: " ")
|
||||
try execute(rawSQL: sql)
|
||||
try execute(sql: sql)
|
||||
}
|
||||
|
||||
/// Creates a virtual database table.
|
||||
@@ -121,7 +121,7 @@ extension Database {
|
||||
let sql = chunks.joined(separator: " ")
|
||||
|
||||
try inSavepoint {
|
||||
try execute(rawSQL: sql)
|
||||
try execute(sql: sql)
|
||||
try module.database(self, didCreate: tableName, using: definition)
|
||||
return .commit
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@ import Foundation
|
||||
|
||||
/// Types that adopt FetchableRecord can be initialized from a database Row.
|
||||
///
|
||||
/// let row = try Row.fetchOne(db, rawSQL: "SELECT ...")!
|
||||
/// let row = try Row.fetchOne(db, sql: "SELECT ...")!
|
||||
/// let player = Player(row)
|
||||
///
|
||||
/// The protocol comes with built-in methods that allow to fetch cursors,
|
||||
/// arrays, or single records:
|
||||
///
|
||||
/// try Player.fetchCursor(db, rawSQL: "SELECT ...", arguments:...) // Cursor of Player
|
||||
/// try Player.fetchAll(db, rawSQL: "SELECT ...", arguments:...) // [Player]
|
||||
/// try Player.fetchOne(db, rawSQL: "SELECT ...", arguments:...) // Player?
|
||||
/// try Player.fetchCursor(db, sql: "SELECT ...", arguments:...) // Cursor of Player
|
||||
/// try Player.fetchAll(db, sql: "SELECT ...", arguments:...) // [Player]
|
||||
/// try Player.fetchOne(db, sql: "SELECT ...", arguments:...) // Player?
|
||||
///
|
||||
/// let statement = try db.makeSelectStatement("SELECT ...")
|
||||
/// try Player.fetchCursor(statement, arguments:...) // Cursor of Player
|
||||
@@ -199,7 +199,7 @@ extension FetchableRecord {
|
||||
|
||||
/// Returns a cursor over records fetched from an SQL query.
|
||||
///
|
||||
/// let players = try Player.fetchCursor(db, rawSQL: "SELECT * FROM player") // Cursor of Player
|
||||
/// let players = try Player.fetchCursor(db, sql: "SELECT * FROM player") // Cursor of Player
|
||||
/// while let player = try players.next() { // Player
|
||||
/// ...
|
||||
/// }
|
||||
@@ -216,13 +216,13 @@ extension FetchableRecord {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A cursor over fetched records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RecordCursor<Self> {
|
||||
return try fetchCursor(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RecordCursor<Self> {
|
||||
return try fetchCursor(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of records fetched from an SQL query.
|
||||
///
|
||||
/// let players = try Player.fetchAll(db, rawSQL: "SELECT * FROM player") // [Player]
|
||||
/// let players = try Player.fetchAll(db, sql: "SELECT * FROM player") // [Player]
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
@@ -231,13 +231,13 @@ extension FetchableRecord {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
return try fetchAll(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
return try fetchAll(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns a single record fetched from an SQL query.
|
||||
///
|
||||
/// let player = try Player.fetchOne(db, rawSQL: "SELECT * FROM player") // Player?
|
||||
/// let player = try Player.fetchOne(db, sql: "SELECT * FROM player") // Player?
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
@@ -246,8 +246,8 @@ extension FetchableRecord {
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An optional record.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? {
|
||||
return try fetchOne(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
public static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? {
|
||||
return try fetchOne(db, literal: SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ extension FetchableRecord {
|
||||
|
||||
/// Returns a cursor over records fetched from an SQL query.
|
||||
///
|
||||
/// let players = try Player.fetchCursor(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let players = try Player.fetchCursor(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT * FROM player WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // Cursor of Player
|
||||
/// while let player = try players.next() { // Player
|
||||
@@ -288,7 +288,7 @@ extension FetchableRecord {
|
||||
|
||||
/// Returns an array of records fetched from an SQL query.
|
||||
///
|
||||
/// let players = try Player.fetchAll(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let players = try Player.fetchAll(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT * FROM player WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // [Player]
|
||||
/// for player in players {
|
||||
@@ -314,7 +314,7 @@ extension FetchableRecord {
|
||||
|
||||
/// Returns a single record fetched from an SQL query.
|
||||
///
|
||||
/// let player = try Player.fetchOne(db, literal: SQLLiteral(rawSQL: """
|
||||
/// let player = try Player.fetchOne(db, literal: SQLLiteral(sql: """
|
||||
/// SELECT * FROM player WHERE lastName = ?
|
||||
/// """, arguments: ["O'Brien"])) // Player?
|
||||
/// if let player = player {
|
||||
@@ -454,7 +454,7 @@ extension FetchRequest where RowDecoder: FetchableRecord {
|
||||
///
|
||||
/// struct Player : FetchableRecord { ... }
|
||||
/// try dbQueue.read { db in
|
||||
/// let players: RecordCursor<Player> = try Player.fetchCursor(db, rawSQL: "SELECT * FROM player")
|
||||
/// let players: RecordCursor<Player> = try Player.fetchCursor(db, sql: "SELECT * FROM player")
|
||||
/// }
|
||||
public final class RecordCursor<Record: FetchableRecord> : Cursor {
|
||||
private let statement: SelectStatement
|
||||
|
||||
@@ -18,7 +18,7 @@ public final class FetchedRecordsController<Record: FetchableRecord> {
|
||||
///
|
||||
/// let controller = FetchedRecordsController<Wine>(
|
||||
/// dbQueue,
|
||||
/// rawSQL: "SELECT * FROM wine WHERE color = ? ORDER BY name",
|
||||
/// sql: "SELECT * FROM wine WHERE color = ? ORDER BY name",
|
||||
/// arguments: [Color.red],
|
||||
/// isSameRecord: { (wine1, wine2) in wine1.id == wine2.id })
|
||||
///
|
||||
@@ -39,16 +39,15 @@ public final class FetchedRecordsController<Record: FetchableRecord> {
|
||||
/// same identity. For example, they have the same id.
|
||||
public convenience init(
|
||||
_ databaseWriter: DatabaseWriter,
|
||||
rawSQL sql: String,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: RowAdapter? = nil,
|
||||
queue: DispatchQueue = .main,
|
||||
isSameRecord: ((Record, Record) -> Bool)? = nil) throws
|
||||
{
|
||||
// TODO: rename sql parameter to rawSQL
|
||||
try self.init(
|
||||
databaseWriter,
|
||||
request: SQLRequest<Record>(rawSQL: sql, arguments: arguments, adapter: adapter),
|
||||
request: SQLRequest<Record>(sql: sql, arguments: arguments, adapter: adapter),
|
||||
queue: queue,
|
||||
isSameRecord: isSameRecord)
|
||||
}
|
||||
@@ -197,9 +196,8 @@ public final class FetchedRecordsController<Record: FetchableRecord> {
|
||||
///
|
||||
/// This method must be used from the controller's dispatch queue (the
|
||||
/// main queue unless stated otherwise in the controller's initializer).
|
||||
public func setRequest(rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws {
|
||||
// TODO: rename sql parameter to rawSQL
|
||||
try setRequest(SQLRequest(rawSQL: sql, arguments: arguments, adapter: adapter))
|
||||
public func setRequest(sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws {
|
||||
try setRequest(SQLRequest(sql: sql, arguments: arguments, adapter: adapter))
|
||||
}
|
||||
|
||||
/// Registers changes notification callbacks.
|
||||
@@ -404,7 +402,7 @@ extension FetchedRecordsController where Record: TableRecord {
|
||||
///
|
||||
/// let controller = FetchedRecordsController<Wine>(
|
||||
/// dbQueue,
|
||||
/// rawSQL: "SELECT * FROM wine WHERE color = ? ORDER BY name",
|
||||
/// sql: "SELECT * FROM wine WHERE color = ? ORDER BY name",
|
||||
/// arguments: [Color.red])
|
||||
///
|
||||
/// The records are compared by primary key (single-column primary key,
|
||||
@@ -414,7 +412,7 @@ extension FetchedRecordsController where Record: TableRecord {
|
||||
/// // Assuming the wine table has an `id` primary key:
|
||||
/// let controller = FetchedRecordsController<Wine>(
|
||||
/// dbQueue,
|
||||
/// rawSQL: "SELECT * FROM wine WHERE color = ? ORDER BY name",
|
||||
/// sql: "SELECT * FROM wine WHERE color = ? ORDER BY name",
|
||||
/// arguments: [Color.red],
|
||||
/// isSameRecord: { (wine1, wine2) in wine1.id == wine2.id })
|
||||
///
|
||||
@@ -430,15 +428,14 @@ extension FetchedRecordsController where Record: TableRecord {
|
||||
/// used from this queue.
|
||||
public convenience init(
|
||||
_ databaseWriter: DatabaseWriter,
|
||||
rawSQL sql: String,
|
||||
sql: String,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: RowAdapter? = nil,
|
||||
queue: DispatchQueue = .main) throws
|
||||
{
|
||||
// TODO: rename sql parameter to rawSQL
|
||||
try self.init(
|
||||
databaseWriter,
|
||||
request: SQLRequest(rawSQL: sql, arguments: arguments, adapter: adapter),
|
||||
request: SQLRequest(sql: sql, arguments: arguments, adapter: adapter),
|
||||
queue: queue)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ extension String {
|
||||
/// Returns the receiver, quoted for safe insertion as an identifier in an
|
||||
/// SQL query.
|
||||
///
|
||||
/// db.execute(rawSQL: "SELECT * FROM \(tableName.quotedDatabaseIdentifier)")
|
||||
/// db.execute(sql: "SELECT * FROM \(tableName.quotedDatabaseIdentifier)")
|
||||
public var quotedDatabaseIdentifier: String {
|
||||
// See https://www.sqlite.org/lang_keywords.html
|
||||
return "\"" + self + "\""
|
||||
|
||||
@@ -7,7 +7,7 @@ extension ValueObservation where Reducer == Void {
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// let request = SQLRequest<Row>(rawSQL: "SELECT * FROM player")
|
||||
/// let request = SQLRequest<Row>(sql: "SELECT * FROM player")
|
||||
/// let observation = ValueObservation.trackingAll(request)
|
||||
///
|
||||
/// let observer = try observation.start(in: dbQueue) { rows: [Row] in
|
||||
@@ -39,7 +39,7 @@ extension ValueObservation where Reducer == Void {
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// let request = SQLRequest<Row>(rawSQL: "SELECT * FROM player WHERE id = ?", arguments: [1])
|
||||
/// let request = SQLRequest<Row>(sql: "SELECT * FROM player WHERE id = ?", arguments: [1])
|
||||
/// let observation = ValueObservation.trackingOne(request)
|
||||
///
|
||||
/// let observer = try observation.start(in: dbQueue) { row: Row? in
|
||||
|
||||
@@ -388,15 +388,15 @@ extension MyDatabaseDecoder {
|
||||
|
||||
// MARK: - Fetch from SQL
|
||||
|
||||
static func fetchCursor(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> MapCursor<RowCursor, DecodedType> {
|
||||
static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> MapCursor<RowCursor, DecodedType> {
|
||||
return try fetchCursor(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
static func fetchAll(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [DecodedType] {
|
||||
static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [DecodedType] {
|
||||
return try fetchAll(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
static func fetchOne(_ db: Database, rawSQL sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DecodedType? {
|
||||
static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DecodedType? {
|
||||
return try fetchOne(db, literal: SQLLiteral(rawSQL: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ See [Database Connections](#database-connections)
|
||||
|
||||
```swift
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE place (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
@@ -109,7 +109,7 @@ try dbQueue.write { db in
|
||||
longitude DOUBLE NOT NULL)
|
||||
""")
|
||||
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
INSERT INTO place (title, favorite, latitude, longitude)
|
||||
VALUES (?, ?, ?, ?)
|
||||
""", arguments: ["Paris", true, 48.85341, 2.3488])
|
||||
@@ -128,7 +128,7 @@ See [Executing Updates](#executing-updates)
|
||||
```swift
|
||||
try dbQueue.read { db in
|
||||
// Fetch database rows
|
||||
let rows = try Row.fetchCursor(db, rawSQL: "SELECT * FROM place")
|
||||
let rows = try Row.fetchCursor(db, sql: "SELECT * FROM place")
|
||||
while let row = try rows.next() {
|
||||
let title: String = row["title"]
|
||||
let isFavorite: Bool = row["favorite"]
|
||||
@@ -138,12 +138,12 @@ try dbQueue.read { db in
|
||||
}
|
||||
|
||||
// Fetch values
|
||||
let placeCount = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM place")! // Int
|
||||
let placeTitles = try String.fetchAll(db, rawSQL: "SELECT title FROM place") // [String]
|
||||
let placeCount = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM place")! // Int
|
||||
let placeTitles = try String.fetchAll(db, sql: "SELECT title FROM place") // [String]
|
||||
}
|
||||
|
||||
let placeCount = try dbQueue.read { db in
|
||||
try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM place")!
|
||||
try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM place")!
|
||||
}
|
||||
```
|
||||
|
||||
@@ -214,7 +214,7 @@ try dbQueue.write { db in
|
||||
let favoriteCount = try Place.filter(Column("favorite")).fetchCount(db)
|
||||
|
||||
// SQL is always welcome
|
||||
let places = try Place.fetchAll(db, rawSQL: "SELECT * FROM place")
|
||||
let places = try Place.fetchAll(db, sql: "SELECT * FROM place")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -582,7 +582,7 @@ For example:
|
||||
|
||||
```swift
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE player (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
@@ -590,11 +590,11 @@ try dbQueue.write { db in
|
||||
""")
|
||||
|
||||
try db.execute(
|
||||
rawSQL: "INSERT INTO player (name, score) VALUES (?, ?)",
|
||||
sql: "INSERT INTO player (name, score) VALUES (?, ?)",
|
||||
arguments: ["Barbara", 1000])
|
||||
|
||||
try db.execute(
|
||||
rawSQL: "UPDATE player SET score = :score WHERE id = :id",
|
||||
sql: "UPDATE player SET score = :score WHERE id = :id",
|
||||
arguments: ["score": 1000, "id": 1])
|
||||
}
|
||||
}
|
||||
@@ -608,18 +608,18 @@ The `?` and colon-prefixed keys like `:score` in the SQL query are the **stateme
|
||||
// WRONG
|
||||
let id = 123
|
||||
let name = textField.text
|
||||
try db.execute(rawSQL: "UPDATE player SET name = '\(name)' WHERE id = \(id)")
|
||||
try db.execute(sql: "UPDATE player SET name = '\(name)' WHERE id = \(id)")
|
||||
|
||||
// CORRECT
|
||||
try db.execute(
|
||||
rawSQL: "UPDATE player SET name = :name WHERE id = :id",
|
||||
sql: "UPDATE player SET name = :name WHERE id = :id",
|
||||
arguments: ["name": name, "id": id])
|
||||
```
|
||||
|
||||
**Join multiple statements with a semicolon**:
|
||||
|
||||
```swift
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
INSERT INTO player (name, score) VALUES (?, ?);
|
||||
INSERT INTO player (name, score) VALUES (?, ?)
|
||||
""", arguments: ["Arthur", 750, "Barbara", 1000])
|
||||
@@ -631,7 +631,7 @@ When you want to make sure that a single statement is executed, use [Prepared St
|
||||
|
||||
```swift
|
||||
try db.execute(
|
||||
rawSQL: "INSERT INTO player (name, score) VALUES (?, ?)",
|
||||
sql: "INSERT INTO player (name, score) VALUES (?, ?)",
|
||||
arguments: ["Arthur", 1000])
|
||||
let playerId = db.lastInsertedRowID
|
||||
```
|
||||
@@ -653,7 +653,7 @@ let playerId = player.id
|
||||
|
||||
```swift
|
||||
try dbQueue.read { db in
|
||||
if let row = try Row.fetchOne(db, rawSQL: "SELECT * FROM wine WHERE id = ?", arguments: [1]) {
|
||||
if let row = try Row.fetchOne(db, sql: "SELECT * FROM wine WHERE id = ?", arguments: [1]) {
|
||||
let name: String = row["name"]
|
||||
let color: Color = row["color"]
|
||||
print(name, color)
|
||||
@@ -666,7 +666,7 @@ try dbQueue.read { db in
|
||||
|
||||
```swift
|
||||
try dbQueue.read { db in
|
||||
let urls = try URL.fetchCursor(db, rawSQL: "SELECT url FROM wine")
|
||||
let urls = try URL.fetchCursor(db, sql: "SELECT url FROM wine")
|
||||
while let url = try urls.next() {
|
||||
print(url)
|
||||
}
|
||||
@@ -678,7 +678,7 @@ try dbQueue.read { db in
|
||||
|
||||
```swift
|
||||
let wines = try dbQueue.read { db in
|
||||
try Wine.fetchAll(db, rawSQL: "SELECT * FROM wine")
|
||||
try Wine.fetchAll(db, sql: "SELECT * FROM wine")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -701,19 +701,19 @@ try Row.fetchOne(...) // Row?
|
||||
- `fetchCursor` returns a **[cursor](#cursors)** over fetched values:
|
||||
|
||||
```swift
|
||||
let rows = try Row.fetchCursor(db, rawSQL: "SELECT ...") // A Cursor of Row
|
||||
let rows = try Row.fetchCursor(db, sql: "SELECT ...") // A Cursor of Row
|
||||
```
|
||||
|
||||
- `fetchAll` returns an **array**:
|
||||
|
||||
```swift
|
||||
let players = try Player.fetchAll(db, rawSQL: "SELECT ...") // [Player]
|
||||
let players = try Player.fetchAll(db, sql: "SELECT ...") // [Player]
|
||||
```
|
||||
|
||||
- `fetchOne` returns a **single optional value**, and consumes a single database row (if any).
|
||||
|
||||
```swift
|
||||
let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) ...") // Int?
|
||||
let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) ...") // Int?
|
||||
```
|
||||
|
||||
|
||||
@@ -726,7 +726,7 @@ The `fetchAll()` method returns a regular Swift array, that you iterate like all
|
||||
```swift
|
||||
try dbQueue.read { db in
|
||||
// [Player]
|
||||
let players = try Player.fetchAll(db, rawSQL: "SELECT ...")
|
||||
let players = try Player.fetchAll(db, sql: "SELECT ...")
|
||||
for player in players {
|
||||
// use player
|
||||
}
|
||||
@@ -738,7 +738,7 @@ Unlike arrays, cursors returned by `fetchCursor()` load their results step after
|
||||
```swift
|
||||
try dbQueue.read { db in
|
||||
// Cursor of Player
|
||||
let players = try Player.fetchCursor(db, rawSQL: "SELECT ...")
|
||||
let players = try Player.fetchCursor(db, sql: "SELECT ...")
|
||||
while let player = try players.next() {
|
||||
// use player
|
||||
}
|
||||
@@ -778,13 +778,13 @@ Both arrays and cursors can iterate over database results. How do you choose one
|
||||
```swift
|
||||
// Prints all Github links
|
||||
try URL
|
||||
.fetchCursor(db, rawSQL: "SELECT url FROM link")
|
||||
.fetchCursor(db, sql: "SELECT url FROM link")
|
||||
.filter { url in url.host == "github.com" }
|
||||
.forEach { url in print(url) }
|
||||
|
||||
// An efficient cursor of coordinates:
|
||||
let locations = try Row.
|
||||
.fetchCursor(db, rawSQL: "SELECT latitude, longitude FROM place")
|
||||
.fetchCursor(db, sql: "SELECT latitude, longitude FROM place")
|
||||
.map { row in
|
||||
CLLocationCoordinate2D(latitude: row[0], longitude: row[1])
|
||||
}
|
||||
@@ -803,7 +803,7 @@ Both arrays and cursors can iterate over database results. How do you choose one
|
||||
```swift
|
||||
// Undefined behavior
|
||||
while let player = try players.next() {
|
||||
try db.execute(rawSQL: "DELETE ...")
|
||||
try db.execute(sql: "DELETE ...")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -826,11 +826,11 @@ Fetch **cursors** of rows, **arrays**, or **single** rows (see [fetching methods
|
||||
|
||||
```swift
|
||||
try dbQueue.read { db in
|
||||
try Row.fetchCursor(db, rawSQL: "SELECT ...", arguments: ...) // A Cursor of Row
|
||||
try Row.fetchAll(db, rawSQL: "SELECT ...", arguments: ...) // [Row]
|
||||
try Row.fetchOne(db, rawSQL: "SELECT ...", arguments: ...) // Row?
|
||||
try Row.fetchCursor(db, sql: "SELECT ...", arguments: ...) // A Cursor of Row
|
||||
try Row.fetchAll(db, sql: "SELECT ...", arguments: ...) // [Row]
|
||||
try Row.fetchOne(db, sql: "SELECT ...", arguments: ...) // Row?
|
||||
|
||||
let rows = try Row.fetchCursor(db, rawSQL: "SELECT * FROM wine")
|
||||
let rows = try Row.fetchCursor(db, sql: "SELECT * FROM wine")
|
||||
while let row = try rows.next() {
|
||||
let name: String = row["name"]
|
||||
let color: Color = row["color"]
|
||||
@@ -839,7 +839,7 @@ try dbQueue.read { db in
|
||||
}
|
||||
|
||||
let rows = try dbQueue.read { db in
|
||||
try Row.fetchAll(db, rawSQL: "SELECT * FROM player")
|
||||
try Row.fetchAll(db, sql: "SELECT * FROM player")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -847,11 +847,11 @@ Arguments are optional arrays or dictionaries that fill the positional `?` and c
|
||||
|
||||
```swift
|
||||
let rows = try Row.fetchAll(db,
|
||||
rawSQL: "SELECT * FROM player WHERE name = ?",
|
||||
sql: "SELECT * FROM player WHERE name = ?",
|
||||
arguments: ["Arthur"])
|
||||
|
||||
let rows = try Row.fetchAll(db,
|
||||
rawSQL: "SELECT * FROM player WHERE name = :name",
|
||||
sql: "SELECT * FROM player WHERE name = :name",
|
||||
arguments: ["name": "Arthur"])
|
||||
```
|
||||
|
||||
@@ -917,7 +917,7 @@ Generally speaking, you can extract the type you need, provided it can be conver
|
||||
- **NULL returns nil.**
|
||||
|
||||
```swift
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT NULL")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT NULL")!
|
||||
row[0] as Int? // nil
|
||||
row[0] as Int // fatal error: could not convert NULL to Int.
|
||||
```
|
||||
@@ -931,7 +931,7 @@ Generally speaking, you can extract the type you need, provided it can be conver
|
||||
- **Missing columns return nil.**
|
||||
|
||||
```swift
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 'foo' AS foo")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 'foo' AS foo")!
|
||||
row["missing"] as String? // nil
|
||||
row["missing"] as String // fatal error: no such column: missing
|
||||
```
|
||||
@@ -941,12 +941,12 @@ Generally speaking, you can extract the type you need, provided it can be conver
|
||||
- **Invalid conversions throw a fatal error.**
|
||||
|
||||
```swift
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 'Mom’s birthday'")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 'Mom’s birthday'")!
|
||||
row[0] as String // "Mom’s birthday"
|
||||
row[0] as Date? // fatal error: could not convert "Mom’s birthday" to Date.
|
||||
row[0] as Date // fatal error: could not convert "Mom’s birthday" to Date.
|
||||
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 256")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 256")!
|
||||
row[0] as Int // 256
|
||||
row[0] as UInt8? // fatal error: could not convert 256 to UInt8.
|
||||
row[0] as UInt8 // fatal error: could not convert 256 to UInt8.
|
||||
@@ -955,7 +955,7 @@ Generally speaking, you can extract the type you need, provided it can be conver
|
||||
Those conversion fatal errors can be avoided with the [DatabaseValue](#databasevalue) type:
|
||||
|
||||
```swift
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 'Mom’s birthday'")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 'Mom’s birthday'")!
|
||||
let dbValue: DatabaseValue = row[0]
|
||||
if dbValue.isNull {
|
||||
// Handle NULL
|
||||
@@ -973,7 +973,7 @@ Generally speaking, you can extract the type you need, provided it can be conver
|
||||
GRDB will sometimes let those conversions go through:
|
||||
|
||||
```swift
|
||||
let rows = try Row.fetchCursor(db, rawSQL: "SELECT '20 small cigars'")
|
||||
let rows = try Row.fetchCursor(db, sql: "SELECT '20 small cigars'")
|
||||
while let row = try rows.next() {
|
||||
row[0] as Int // 20
|
||||
}
|
||||
@@ -1024,7 +1024,7 @@ let date = Date.fromDatabaseValue(dbValue) // Date?
|
||||
`fromDatabaseValue` returns nil for invalid conversions:
|
||||
|
||||
```swift
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 'Mom’s birthday'")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 'Mom’s birthday'")!
|
||||
let dbValue: DatabaseValue = row[0]
|
||||
let string = String.fromDatabaseValue(dbValue) // "Mom’s birthday"
|
||||
let int = Int.fromDatabaseValue(dbValue) // nil
|
||||
@@ -1054,7 +1054,7 @@ let row = Row(/* [AnyHashable: Any] */) // nil if invalid dictionary
|
||||
Yet rows are not real dictionaries: they may contain duplicate columns:
|
||||
|
||||
```swift
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 1 AS foo, 2 AS foo")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 1 AS foo, 2 AS foo")!
|
||||
row.columnNames // ["foo", "foo"]
|
||||
row.databaseValues // [1, 2]
|
||||
row["foo"] // 1 (leftmost matching column)
|
||||
@@ -1098,17 +1098,17 @@ Instead of rows, you can directly fetch **[values](#values)**. Like rows, fetch
|
||||
|
||||
```swift
|
||||
try dbQueue.read { db in
|
||||
try Int.fetchCursor(db, rawSQL: "SELECT ...", arguments: ...) // A Cursor of Int
|
||||
try Int.fetchAll(db, rawSQL: "SELECT ...", arguments: ...) // [Int]
|
||||
try Int.fetchOne(db, rawSQL: "SELECT ...", arguments: ...) // Int?
|
||||
try Int.fetchCursor(db, sql: "SELECT ...", arguments: ...) // A Cursor of Int
|
||||
try Int.fetchAll(db, sql: "SELECT ...", arguments: ...) // [Int]
|
||||
try Int.fetchOne(db, sql: "SELECT ...", arguments: ...) // Int?
|
||||
|
||||
// When database may contain NULL:
|
||||
try Optional<Int>.fetchCursor(db, rawSQL: "SELECT ...", arguments: ...) // A Cursor of Int?
|
||||
try Optional<Int>.fetchAll(db, rawSQL: "SELECT ...", arguments: ...) // [Int?]
|
||||
try Optional<Int>.fetchCursor(db, sql: "SELECT ...", arguments: ...) // A Cursor of Int?
|
||||
try Optional<Int>.fetchAll(db, sql: "SELECT ...", arguments: ...) // [Int?]
|
||||
}
|
||||
|
||||
let playerCount = try dbQueue.read { db in
|
||||
try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM player")!
|
||||
try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM player")!
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1117,8 +1117,8 @@ let playerCount = try dbQueue.read { db in
|
||||
There are many supported value types (Bool, Int, String, Date, Swift enums, etc.). See [Values](#values) for more information:
|
||||
|
||||
```swift
|
||||
let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM player")! // Int
|
||||
let urls = try URL.fetchAll(db, rawSQL: "SELECT url FROM link") // [URL]
|
||||
let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM player")! // Int
|
||||
let urls = try URL.fetchAll(db, sql: "SELECT url FROM link") // [URL]
|
||||
```
|
||||
|
||||
|
||||
@@ -1144,14 +1144,14 @@ Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/do
|
||||
let url: URL = ...
|
||||
let verified: Bool = ...
|
||||
try db.execute(
|
||||
rawSQL: "INSERT INTO link (url, verified) VALUES (?, ?)",
|
||||
sql: "INSERT INTO link (url, verified) VALUES (?, ?)",
|
||||
arguments: [url, verified])
|
||||
```
|
||||
|
||||
Values can be [extracted from rows](#column-values):
|
||||
|
||||
```swift
|
||||
let rows = try Row.fetchCursor(db, rawSQL: "SELECT * FROM link")
|
||||
let rows = try Row.fetchCursor(db, sql: "SELECT * FROM link")
|
||||
while let row = try rows.next() {
|
||||
let url: URL = row["url"]
|
||||
let verified: Bool = row["verified"]
|
||||
@@ -1161,7 +1161,7 @@ while let row = try rows.next() {
|
||||
Values can be [directly fetched](#value-queries):
|
||||
|
||||
```swift
|
||||
let urls = try URL.fetchAll(db, rawSQL: "SELECT url FROM link") // [URL]
|
||||
let urls = try URL.fetchAll(db, sql: "SELECT url FROM link") // [URL]
|
||||
```
|
||||
|
||||
Use values in [Records](#records):
|
||||
@@ -1191,7 +1191,7 @@ let link = try Link.filter(Column("url") == url).fetchOne(db)
|
||||
**Data** suits the BLOB SQLite columns. It can be stored and fetched from the database just like other [values](#values):
|
||||
|
||||
```swift
|
||||
let rows = try Row.fetchCursor(db, rawSQL: "SELECT data, ...")
|
||||
let rows = try Row.fetchCursor(db, sql: "SELECT data, ...")
|
||||
while let row = try rows.next() {
|
||||
let data: Data = row["data"]
|
||||
}
|
||||
@@ -1242,7 +1242,7 @@ Here is how GRDB supports the various [date formats](https://www.sqlite.org/lang
|
||||
|
||||
```swift
|
||||
try db.execute(
|
||||
rawSQL: "INSERT INTO player (creationDate, ...) VALUES (?, ...)",
|
||||
sql: "INSERT INTO player (creationDate, ...) VALUES (?, ...)",
|
||||
arguments: [Date(), ...])
|
||||
|
||||
let row = try Row.fetchOne(db, ...)!
|
||||
@@ -1262,7 +1262,7 @@ When the default format does not fit your needs, customize date conversions. For
|
||||
|
||||
```swift
|
||||
try db.execute(
|
||||
rawSQL: "INSERT INTO player (creationDate, ...) VALUES (?, ...)",
|
||||
sql: "INSERT INTO player (creationDate, ...) VALUES (?, ...)",
|
||||
arguments: [Date().timeIntervalSinceReferenceDate, ...])
|
||||
|
||||
let row = try Row.fetchOne(db, ...)!
|
||||
@@ -1289,11 +1289,11 @@ components.day = 18
|
||||
// Store "1973-09-18"
|
||||
let dbComponents = DatabaseDateComponents(components, format: .YMD)
|
||||
try db.execute(
|
||||
rawSQL: "INSERT INTO player (birthDate, ...) VALUES (?, ...)",
|
||||
sql: "INSERT INTO player (birthDate, ...) VALUES (?, ...)",
|
||||
arguments: [dbComponents, ...])
|
||||
|
||||
// Read "1973-09-18"
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT birthDate ...")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT birthDate ...")!
|
||||
let dbComponents: DatabaseDateComponents = row["birthDate"]
|
||||
dbComponents.format // .YMD (the actual format found in the database)
|
||||
dbComponents.dateComponents // DateComponents
|
||||
@@ -1317,9 +1317,9 @@ CREATE TABLE transfer (
|
||||
This means that computations will not be exact:
|
||||
|
||||
```swift
|
||||
try db.execute(rawSQL: "INSERT INTO transfer (amount) VALUES (0.1)")
|
||||
try db.execute(rawSQL: "INSERT INTO transfer (amount) VALUES (0.2)")
|
||||
let sum = try NSDecimalNumber.fetchOne(db, rawSQL: "SELECT SUM(amount) FROM transfer")!
|
||||
try db.execute(sql: "INSERT INTO transfer (amount) VALUES (0.1)")
|
||||
try db.execute(sql: "INSERT INTO transfer (amount) VALUES (0.2)")
|
||||
let sum = try NSDecimalNumber.fetchOne(db, sql: "SELECT SUM(amount) FROM transfer")!
|
||||
|
||||
// Yikes! 0.3000000000000000512
|
||||
print(sum)
|
||||
@@ -1333,10 +1333,10 @@ A classic technique is to store *integers* instead, since SQLite performs exact
|
||||
// Write
|
||||
let amount = NSDecimalNumber(string: "0.10")
|
||||
let integerAmount = amount.multiplying(byPowerOf10: 2).int64Value
|
||||
try db.execute(rawSQL: "INSERT INTO transfer (amount) VALUES (?)", arguments: [integerAmount])
|
||||
try db.execute(sql: "INSERT INTO transfer (amount) VALUES (?)", arguments: [integerAmount])
|
||||
|
||||
// Read
|
||||
let integerAmount = try Int64.fetchOne(db, rawSQL: "SELECT SUM(amount) FROM transfer")!
|
||||
let integerAmount = try Int64.fetchOne(db, sql: "SELECT SUM(amount) FROM transfer")!
|
||||
let amount = NSDecimalNumber(value: integerAmount).multiplying(byPowerOf10: -2) // 0.10
|
||||
```
|
||||
|
||||
@@ -1367,11 +1367,11 @@ extension Grape : DatabaseValueConvertible { }
|
||||
|
||||
// Store
|
||||
try db.execute(
|
||||
rawSQL: "INSERT INTO wine (grape, color) VALUES (?, ?)",
|
||||
sql: "INSERT INTO wine (grape, color) VALUES (?, ?)",
|
||||
arguments: [Grape.merlot, Color.red])
|
||||
|
||||
// Read
|
||||
let rows = try Row.fetchCursor(db, rawSQL: "SELECT * FROM wine")
|
||||
let rows = try Row.fetchCursor(db, sql: "SELECT * FROM wine")
|
||||
while let row = try rows.next() {
|
||||
let grape: Grape = row["grape"]
|
||||
let color: Color = row["color"]
|
||||
@@ -1381,7 +1381,7 @@ while let row = try rows.next() {
|
||||
**When a database value does not match any enum case**, you get a fatal error. This fatal error can be avoided with the [DatabaseValue](#databasevalue) type:
|
||||
|
||||
```swift
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 'syrah'")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 'syrah'")!
|
||||
|
||||
row[0] as String // "syrah"
|
||||
row[0] as Grape? // fatal error: could not convert "syrah" to Grape.
|
||||
@@ -1539,9 +1539,9 @@ try dbQueue.inDatabase { db in // or dbPool.writeWithoutTransaction
|
||||
...
|
||||
try db.commit()
|
||||
|
||||
try db.execute(rawSQL: "BEGIN TRANSACTION")
|
||||
try db.execute(sql: "BEGIN TRANSACTION")
|
||||
...
|
||||
try db.execute(rawSQL: "ROLLBACK")
|
||||
try db.execute(sql: "ROLLBACK")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1550,7 +1550,7 @@ Transactions can't be left opened unless you set the [allowsUnsafeTransactions](
|
||||
```swift
|
||||
// fatal error: A transaction has been left opened at the end of a database access
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "BEGIN TRANSACTION")
|
||||
try db.execute(sql: "BEGIN TRANSACTION")
|
||||
// <- no commit or rollback
|
||||
}
|
||||
```
|
||||
@@ -1740,7 +1740,7 @@ dbQueue.add(function: reverse) // Or dbPool.add(function: ...)
|
||||
|
||||
try dbQueue.read { db in
|
||||
// "oof"
|
||||
try String.fetchOne(db, rawSQL: "SELECT reverse('foo')")!
|
||||
try String.fetchOne(db, sql: "SELECT reverse('foo')")!
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1762,7 +1762,7 @@ dbQueue.add(function: averageOf)
|
||||
|
||||
try dbQueue.read { db in
|
||||
// 2.0
|
||||
try Double.fetchOne(db, rawSQL: "SELECT averageOf(1, 2, 3)")!
|
||||
try Double.fetchOne(db, sql: "SELECT averageOf(1, 2, 3)")!
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1783,7 +1783,7 @@ dbQueue.add(function: sqrt)
|
||||
|
||||
// SQLite error 1 with statement `SELECT sqrt(-1)`: invalid negative number
|
||||
try dbQueue.read { db in
|
||||
try Double.fetchOne(db, rawSQL: "SELECT sqrt(-1)")!
|
||||
try Double.fetchOne(db, sql: "SELECT sqrt(-1)")!
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1849,7 +1849,7 @@ dbQueue.add(function: maxLength) // Or dbPool.add(function: ...)
|
||||
|
||||
try dbQueue.read { db in
|
||||
// Some Int
|
||||
try Int.fetchOne(db, rawSQL: "SELECT maxLength(name) FROM player")!
|
||||
try Int.fetchOne(db, sql: "SELECT maxLength(name) FROM player")!
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1913,7 +1913,7 @@ In this case, the `ColumnMapping` row adapter comes in handy:
|
||||
```swift
|
||||
// Fetch a 'produced' column, and consume a 'consumed' column:
|
||||
let adapter = ColumnMapping(["consumed": "produced"])
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 'Hello' AS produced", adapter: adapter)!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 'Hello' AS produced", adapter: adapter)!
|
||||
row["consumed"] // "Hello"
|
||||
row["produced"] // nil
|
||||
```
|
||||
@@ -1930,7 +1930,7 @@ ColumnMapping renames columns. Build one with a dictionary whose keys are adapte
|
||||
```swift
|
||||
// [newName:"Hello"]
|
||||
let adapter = ColumnMapping(["newName": "oldName"])
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 'Hello' AS oldName", adapter: adapter)!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 'Hello' AS oldName", adapter: adapter)!
|
||||
```
|
||||
|
||||
### SuffixRowAdapter
|
||||
@@ -1940,7 +1940,7 @@ let row = try Row.fetchOne(db, rawSQL: "SELECT 'Hello' AS oldName", adapter: ada
|
||||
```swift
|
||||
// [b:1 c:2]
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)!
|
||||
```
|
||||
|
||||
### RangeRowAdapter
|
||||
@@ -1950,7 +1950,7 @@ let row = try Row.fetchOne(db, rawSQL: "SELECT 0 AS a, 1 AS b, 2 AS c", adapter:
|
||||
```swift
|
||||
// [b:1]
|
||||
let adapter = RangeRowAdapter(1..<2)
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)!
|
||||
```
|
||||
|
||||
### EmptyRowAdapter
|
||||
@@ -1959,7 +1959,7 @@ let row = try Row.fetchOne(db, rawSQL: "SELECT 0 AS a, 1 AS b, 2 AS c", adapter:
|
||||
|
||||
```swift
|
||||
let adapter = EmptyRowAdapter()
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)!
|
||||
row.isEmpty // true
|
||||
```
|
||||
|
||||
@@ -1974,7 +1974,7 @@ This limit adapter may turn out useful in some narrow use cases. You'll be happy
|
||||
let adapter = ScopeAdapter([
|
||||
"left": RangeRowAdapter(0..<2),
|
||||
"right": RangeRowAdapter(2..<4)])
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)!
|
||||
```
|
||||
|
||||
ScopeAdapter does not change the columns and values of the fetched row. Instead, it defines *scopes*, which you access through the `Row.scopes` property:
|
||||
@@ -1997,7 +1997,7 @@ let adapter = ScopeAdapter([
|
||||
"left": RangeRowAdapter(2..<3),
|
||||
"right": RangeRowAdapter(3..<4)])
|
||||
])
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)!
|
||||
|
||||
let leftRow = row.scopes["left"]!
|
||||
leftRow.scopes["left"] // [a:0]
|
||||
@@ -2014,7 +2014,7 @@ Any adapter can be extended with scopes:
|
||||
let baseAdapter = RangeRowAdapter(0..<2)
|
||||
let adapter = ScopeAdapter(base: baseAdapter, scopes: [
|
||||
"remainder": SuffixRowAdapter(fromIndex: 2)])
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)!
|
||||
|
||||
row // [a:0 b:1]
|
||||
row.scopes["remainder"] // [c:2 d:3]
|
||||
@@ -2149,7 +2149,7 @@ To fetch records from the database, call a [fetching method](#fetching-methods):
|
||||
|
||||
```swift
|
||||
let arthur = try Player.fetchOne(db, // Player?
|
||||
rawSQL: "SELECT * FROM players WHERE name = ?",
|
||||
sql: "SELECT * FROM players WHERE name = ?",
|
||||
arguments: ["Arthur"])
|
||||
|
||||
let bestPlayers = try Player // [Player]
|
||||
@@ -2190,7 +2190,7 @@ if let player = try Player.fetchOne(db, key: 1) {
|
||||
For batch updates, execute an [SQL query](#executing-updates):
|
||||
|
||||
```swift
|
||||
try db.execute(rawSQL: "UPDATE player SET synchronized = 1")
|
||||
try db.execute(sql: "UPDATE player SET synchronized = 1")
|
||||
```
|
||||
|
||||
:point_right: update methods are available for subclasses of the [Record](#record-class) class, and types that adopt the [PersistableRecord] protocol.
|
||||
@@ -2265,7 +2265,7 @@ Details follow:
|
||||
```swift
|
||||
struct Place { ... }
|
||||
try dbQueue.read { db in
|
||||
let rows = try Row.fetchAll(db, rawSQL: "SELECT * FROM place")
|
||||
let rows = try Row.fetchAll(db, sql: "SELECT * FROM place")
|
||||
let places: [Place] = rows.map { row in
|
||||
return Place(
|
||||
id: row["id"],
|
||||
@@ -2283,7 +2283,7 @@ Details follow:
|
||||
```swift
|
||||
struct Place: FetchableRecord { ... }
|
||||
try dbQueue.read { db in
|
||||
let places = try Place.fetchAll(db, rawSQL: "SELECT * FROM place")
|
||||
let places = try Place.fetchAll(db, sql: "SELECT * FROM place")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -2389,9 +2389,9 @@ struct Player: Decodable, FetchableRecord {
|
||||
FetchableRecord allows adopting types to be fetched from SQL queries:
|
||||
|
||||
```swift
|
||||
try Place.fetchCursor(db, rawSQL: "SELECT ...", arguments:...) // A Cursor of Place
|
||||
try Place.fetchAll(db, rawSQL: "SELECT ...", arguments:...) // [Place]
|
||||
try Place.fetchOne(db, rawSQL: "SELECT ...", arguments:...) // Place?
|
||||
try Place.fetchCursor(db, sql: "SELECT ...", arguments:...) // A Cursor of Place
|
||||
try Place.fetchAll(db, sql: "SELECT ...", arguments:...) // [Place]
|
||||
try Place.fetchOne(db, sql: "SELECT ...", arguments:...) // Place?
|
||||
```
|
||||
|
||||
See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/3.6/Structs/StatementArguments.html) for more information about the query arguments.
|
||||
@@ -3117,8 +3117,8 @@ The [five different policies](https://www.sqlite.org/lang_conflict.html) are: ab
|
||||
|
||||
// Despite the unique index on email, both inserts succeed.
|
||||
// The second insert replaces the first row:
|
||||
try db.execute(rawSQL: "INSERT INTO player (email) VALUES (?)", arguments: ["arthur@example.com"])
|
||||
try db.execute(rawSQL: "INSERT INTO player (email) VALUES (?)", arguments: ["arthur@example.com"])
|
||||
try db.execute(sql: "INSERT INTO player (email) VALUES (?)", arguments: ["arthur@example.com"])
|
||||
try db.execute(sql: "INSERT INTO player (email) VALUES (?)", arguments: ["arthur@example.com"])
|
||||
```
|
||||
|
||||
- In each modification query:
|
||||
@@ -3134,8 +3134,8 @@ The [five different policies](https://www.sqlite.org/lang_conflict.html) are: ab
|
||||
}
|
||||
|
||||
// Again, despite the unique index on email, both inserts succeed.
|
||||
try db.execute(rawSQL: "INSERT OR REPLACE INTO player (email) VALUES (?)", arguments: ["arthur@example.com"])
|
||||
try db.execute(rawSQL: "INSERT OR REPLACE INTO player (email) VALUES (?)", arguments: ["arthur@example.com"])
|
||||
try db.execute(sql: "INSERT OR REPLACE INTO player (email) VALUES (?)", arguments: ["arthur@example.com"])
|
||||
try db.execute(sql: "INSERT OR REPLACE INTO player (email) VALUES (?)", arguments: ["arthur@example.com"])
|
||||
```
|
||||
|
||||
When you want to handle conflicts at the query level, specify a custom `persistenceConflictPolicy` in your type that adopts the PersistableRecord protocol. It will alter the INSERT and UPDATE queries run by the `insert`, `update` and `save` [persistence methods](#persistence-methods):
|
||||
@@ -3515,19 +3515,19 @@ This is the list of record methods, along with their required protocols. The [Re
|
||||
| **Fetch Record [Cursors](#cursors)** | | |
|
||||
| `Type.fetchCursor(db)` | [FetchableRecord] & [TableRecord] | |
|
||||
| `Type.fetchCursor(db, keys:...)` | [FetchableRecord] & [TableRecord] | <a href="#list-of-record-methods-1">¹</a> |
|
||||
| `Type.fetchCursor(db, rawSQL: sql)` | [FetchableRecord] | <a href="#list-of-record-methods-3">³</a> |
|
||||
| `Type.fetchCursor(db, sql: sql)` | [FetchableRecord] | <a href="#list-of-record-methods-3">³</a> |
|
||||
| `Type.fetchCursor(statement)` | [FetchableRecord] | <a href="#list-of-record-methods-4">⁴</a> |
|
||||
| `Type.filter(...).fetchCursor(db)` | [FetchableRecord] & [TableRecord] | <a href="#list-of-record-methods-2">²</a> |
|
||||
| **Fetch Record Arrays** | | |
|
||||
| `Type.fetchAll(db)` | [FetchableRecord] & [TableRecord] | |
|
||||
| `Type.fetchAll(db, keys:...)` | [FetchableRecord] & [TableRecord] | <a href="#list-of-record-methods-1">¹</a> |
|
||||
| `Type.fetchAll(db, rawSQL: sql)` | [FetchableRecord] | <a href="#list-of-record-methods-3">³</a> |
|
||||
| `Type.fetchAll(db, sql: sql)` | [FetchableRecord] | <a href="#list-of-record-methods-3">³</a> |
|
||||
| `Type.fetchAll(statement)` | [FetchableRecord] | <a href="#list-of-record-methods-4">⁴</a> |
|
||||
| `Type.filter(...).fetchAll(db)` | [FetchableRecord] & [TableRecord] | <a href="#list-of-record-methods-2">²</a> |
|
||||
| **Fetch Individual Records** | | |
|
||||
| `Type.fetchOne(db)` | [FetchableRecord] & [TableRecord] | |
|
||||
| `Type.fetchOne(db, key:...)` | [FetchableRecord] & [TableRecord] | <a href="#list-of-record-methods-1">¹</a> |
|
||||
| `Type.fetchOne(db, rawSQL: sql)` | [FetchableRecord] | <a href="#list-of-record-methods-3">³</a> |
|
||||
| `Type.fetchOne(db, sql: sql)` | [FetchableRecord] | <a href="#list-of-record-methods-3">³</a> |
|
||||
| `Type.fetchOne(statement)` | [FetchableRecord] | <a href="#list-of-record-methods-4">⁴</a> |
|
||||
| `Type.filter(...).fetchOne(db)` | [FetchableRecord] & [TableRecord] | <a href="#list-of-record-methods-2">²</a> |
|
||||
| **[Record Comparison]** | | |
|
||||
@@ -3558,7 +3558,7 @@ let count = try request.fetchCount(db) // Int
|
||||
<a name="list-of-record-methods-3">³</a> See [SQL queries](#fetch-queries):
|
||||
|
||||
```swift
|
||||
let player = try Player.fetchOne(db, rawSQL: "SELECT * FROM player WHERE id = ?", arguments: [1]) // Player?
|
||||
let player = try Player.fetchOne(db, sql: "SELECT * FROM player WHERE id = ?", arguments: [1]) // Player?
|
||||
```
|
||||
|
||||
<a name="list-of-record-methods-4">⁴</a> See [Prepared Statements](#prepared-statements):
|
||||
@@ -3597,20 +3597,20 @@ Please bear in mind that the query interface can not generate all possible SQL q
|
||||
```swift
|
||||
try dbQueue.write { db in
|
||||
// Update database schema (with SQL)
|
||||
try db.execute(rawSQL: "CREATE TABLE wine (...)")
|
||||
try db.execute(sql: "CREATE TABLE wine (...)")
|
||||
|
||||
// Fetch records (with SQL)
|
||||
let wines = try Wine.fetchAll(db,
|
||||
rawSQL: "SELECT * FROM wine WHERE origin = ? ORDER BY price",
|
||||
sql: "SELECT * FROM wine WHERE origin = ? ORDER BY price",
|
||||
arguments: ["Burgundy"])
|
||||
|
||||
// Count (with an SQL snippet)
|
||||
let count = try Wine
|
||||
.filter(rawSQL: "color = ?", arguments: [Color.red])
|
||||
.filter(sql: "color = ?", arguments: [Color.red])
|
||||
.fetchCount(db)
|
||||
|
||||
// Delete (with SQL)
|
||||
try db.execute(rawSQL: "DELETE FROM wine WHERE corked")
|
||||
try db.execute(sql: "DELETE FROM wine WHERE corked")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -3740,7 +3740,7 @@ For extra index options, see [Create Indexes](#create-indexes) below.
|
||||
// name TEXT CHECK (LENGTH(name) > 0)
|
||||
// score INTEGER CHECK (score > 0)
|
||||
t.column("name", .text).check { length($0) > 0 }
|
||||
t.column("score", .integer).check(rawSQL: "score > 0")
|
||||
t.column("score", .integer).check(sql: "score > 0")
|
||||
```
|
||||
|
||||
Other **table constraints** can involve several columns:
|
||||
@@ -3759,7 +3759,7 @@ Other **table constraints** can involve several columns:
|
||||
t.check(Column("a") + Column("b") < 10)
|
||||
|
||||
// CHECK (a + b < 10)
|
||||
t.check(rawSQL: "a + b < 10")
|
||||
t.check(sql: "a + b < 10")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -4028,9 +4028,9 @@ Raw SQL snippets are also accepted, with eventual [arguments](http://groue.githu
|
||||
```swift
|
||||
// SELECT DATE(creationDate), COUNT(*) FROM player WHERE name = 'Arthur' GROUP BY date(creationDate)
|
||||
Player
|
||||
.select(rawSQL: "DATE(creationDate), COUNT(*)")
|
||||
.filter(rawSQL: "name = ?", arguments: ["Arthur"])
|
||||
.group(rawSQL: "DATE(creationDate)")
|
||||
.select(sql: "DATE(creationDate), COUNT(*)")
|
||||
.filter(sql: "name = ?", arguments: ["Arthur"])
|
||||
.group(sql: "DATE(creationDate)")
|
||||
```
|
||||
|
||||
|
||||
@@ -4529,7 +4529,7 @@ try request.fetchCount(db) // Int
|
||||
|
||||
```swift
|
||||
// Custom SQL is always welcome
|
||||
try Player.fetchAll(db, rawSQL: "SELECT ...") // [Player]
|
||||
try Player.fetchAll(db, sql: "SELECT ...") // [Player]
|
||||
```
|
||||
|
||||
But you may prefer to bring some elegance back in, and build custom requests:
|
||||
@@ -4597,7 +4597,7 @@ let request = Player.all()
|
||||
extension Player {
|
||||
static func filter(color: Color) -> SQLRequest<Player> {
|
||||
return SQLRequest<Player>(
|
||||
rawSQL: "SELECT * FROM player WHERE color = ?"
|
||||
sql: "SELECT * FROM player WHERE color = ?"
|
||||
arguments: [color])
|
||||
}
|
||||
}
|
||||
@@ -4646,7 +4646,7 @@ For example:
|
||||
|
||||
```swift
|
||||
let playerRequest = SQLRequest<Player>(
|
||||
rawSQL: "SELECT * FROM player WHERE color = ?"
|
||||
sql: "SELECT * FROM player WHERE color = ?"
|
||||
arguments: [color])
|
||||
try request.fetchAll(db) // [Player]
|
||||
```
|
||||
@@ -4763,7 +4763,7 @@ migrator.registerMigrationWithDeferredForeignKeyCheck("AddNotNullCheckOnName") {
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("name", .text).notNull()
|
||||
}
|
||||
try db.execute(rawSQL: "INSERT INTO new_player SELECT * FROM player")
|
||||
try db.execute(sql: "INSERT INTO new_player SELECT * FROM player")
|
||||
try db.drop(table: "player")
|
||||
try db.rename(table: "new_player", to: "player")
|
||||
}
|
||||
@@ -4787,7 +4787,7 @@ try db.create(virtualTable: "book", using: FTS4()) { t in // or FTS3(), or FTS5(
|
||||
// Populate full-text table with records or SQL
|
||||
try Book(...).insert(db)
|
||||
try db.execute(
|
||||
rawSQL: "INSERT INTO book (author, title, body) VALUES (?, ?, ?)",
|
||||
sql: "INSERT INTO book (author, title, body) VALUES (?, ?, ?)",
|
||||
arguments: [...])
|
||||
|
||||
// Build search patterns
|
||||
@@ -4796,7 +4796,7 @@ let pattern = FTS3Pattern(matchingPhrase: "Moby-Dick")
|
||||
// Search with the query interface or SQL
|
||||
let books = try Book.matching(pattern).fetchAll(db)
|
||||
let books = try Book.fetchAll(db,
|
||||
rawSQL: "SELECT * FROM book WHERE book MATCH ?",
|
||||
sql: "SELECT * FROM book WHERE book MATCH ?",
|
||||
arguments: [pattern])
|
||||
```
|
||||
|
||||
@@ -5058,7 +5058,7 @@ FTS3Pattern are regular [values](#values). You can use them as query [arguments]
|
||||
|
||||
```swift
|
||||
let documents = try Document.fetchAll(db,
|
||||
rawSQL: "SELECT * FROM document WHERE content MATCH ?",
|
||||
sql: "SELECT * FROM document WHERE content MATCH ?",
|
||||
arguments: [pattern])
|
||||
```
|
||||
|
||||
@@ -5294,7 +5294,7 @@ FTS5Pattern are regular [values](#values). You can use them as query [arguments]
|
||||
|
||||
```swift
|
||||
let documents = try Document.fetchAll(db,
|
||||
rawSQL: "SELECT * FROM document WHERE document MATCH ?",
|
||||
sql: "SELECT * FROM document WHERE document MATCH ?",
|
||||
arguments: [pattern])
|
||||
```
|
||||
|
||||
@@ -5312,7 +5312,7 @@ let documents = try Document.matching(pattern).fetchAll(db)
|
||||
```swift
|
||||
// SQL
|
||||
let documents = try Document.fetchAll(db,
|
||||
rawSQL: "SELECT * FROM document WHERE document MATCH ? ORDER BY rank",
|
||||
sql: "SELECT * FROM document WHERE document MATCH ? ORDER BY rank",
|
||||
arguments: [pattern])
|
||||
|
||||
// Query Interface
|
||||
@@ -5417,7 +5417,7 @@ let sql = """
|
||||
ON book_ft.rowid = book.rowid
|
||||
AND book_ft MATCH ?
|
||||
"""
|
||||
let books = Book.fetchAll(db, rawSQL: sql, arguments: [pattern])
|
||||
let books = Book.fetchAll(db, sql: sql, arguments: [pattern])
|
||||
```
|
||||
|
||||
|
||||
@@ -5549,7 +5549,7 @@ We merge those two adapters in a single [ScopeAdapter](#scopeadapter) that will
|
||||
And now we can fetch, and start consuming our rows. You already know [row cursors](#fetching-rows):
|
||||
|
||||
```swift
|
||||
let rows = try Row.fetchCursor(db, rawSQL: sql, adapter: adapter)
|
||||
let rows = try Row.fetchCursor(db, sql: sql, adapter: adapter)
|
||||
while let row = try rows.next() {
|
||||
```
|
||||
|
||||
@@ -5675,7 +5675,7 @@ Now is the time to build adapters (taking in account the customized selection of
|
||||
And finally, we can fetch player infos:
|
||||
|
||||
```swift
|
||||
return try PlayerInfo.fetchAll(db, rawSQL: sql, adapter: adapter)
|
||||
return try PlayerInfo.fetchAll(db, sql: sql, adapter: adapter)
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -5742,7 +5742,7 @@ extension PlayerInfo {
|
||||
LEFT JOIN round ON ...
|
||||
GROUP BY ...
|
||||
"""
|
||||
return SQLRequest<PlayerInfo>(rawSQL: sql).adapted { db in
|
||||
return SQLRequest<PlayerInfo>(sql: sql).adapted { db in
|
||||
let adapters = try splittingRowAdapters(columnCounts: [
|
||||
Player.numberOfSelectedColumns(db),
|
||||
Team.numberOfSelectedColumns(db)])
|
||||
@@ -5813,7 +5813,7 @@ extension PlayerInfo {
|
||||
LEFT JOIN round ON ...
|
||||
GROUP BY ...
|
||||
"""
|
||||
return SQLRequest<PlayerInfo>(rawSQL: sql).adapted { db in
|
||||
return SQLRequest<PlayerInfo>(sql: sql).adapted { db in
|
||||
let adapters = try splittingRowAdapters(columnCounts: [
|
||||
Player.numberOfSelectedColumns(db),
|
||||
Team.numberOfSelectedColumns(db)])
|
||||
@@ -6074,7 +6074,7 @@ Those observations match the `fetchCount`, `fetchOne`, and `fetchAll` request me
|
||||
}
|
||||
|
||||
// Observe all player names
|
||||
let request = SQLRequest<String>(rawSQL: "SELECT name FROM player")
|
||||
let request = SQLRequest<String>(sql: "SELECT name FROM player")
|
||||
let observer = ValueObservation
|
||||
.trackingAll(request)
|
||||
.start(in: dbQueue) { names: [String] in
|
||||
@@ -6629,7 +6629,7 @@ let controller = FetchedRecordsController(
|
||||
// Using SQL, and eventual arguments:
|
||||
let controller = FetchedRecordsController<Player>(
|
||||
dbQueue,
|
||||
rawSQL: "SELECT * FROM player ORDER BY name WHERE countryCode = ?",
|
||||
sql: "SELECT * FROM player ORDER BY name WHERE countryCode = ?",
|
||||
arguments: ["FR"])
|
||||
```
|
||||
|
||||
@@ -6638,7 +6638,7 @@ The fetch request can involve several database tables. The fetched records contr
|
||||
```swift
|
||||
let controller = FetchedRecordsController<Author>(
|
||||
dbQueue,
|
||||
rawSQL: """
|
||||
sql: """
|
||||
SELECT author.name, COUNT(book.id) AS bookCount
|
||||
FROM author
|
||||
LEFT JOIN book ON book.authorId = author.id
|
||||
@@ -6766,7 +6766,7 @@ You can change a fetched records controller's fetch request or SQL query.
|
||||
|
||||
```swift
|
||||
controller.setRequest(Player.order(Column("name")))
|
||||
controller.setRequest(rawSQL: "SELECT ...", arguments: ...)
|
||||
controller.setRequest(sql: "SELECT ...", arguments: ...)
|
||||
```
|
||||
|
||||
The [notification callbacks](#the-changes-notifications) are notified of eventual changes if the new request fetches a different set of records.
|
||||
@@ -6988,18 +6988,18 @@ Notified changes are not actually written to disk until the [transaction](#trans
|
||||
|
||||
```swift
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT ...") // 1. didChange
|
||||
try db.execute(rawSQL: "UPDATE ...") // 2. didChange
|
||||
try db.execute(sql: "INSERT ...") // 1. didChange
|
||||
try db.execute(sql: "UPDATE ...") // 2. didChange
|
||||
} // 3. willCommit, 4. didCommit
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT ...") // 1. didChange
|
||||
try db.execute(rawSQL: "UPDATE ...") // 2. didChange
|
||||
try db.execute(sql: "INSERT ...") // 1. didChange
|
||||
try db.execute(sql: "UPDATE ...") // 2. didChange
|
||||
return .rollback // 3. didRollback
|
||||
}
|
||||
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT ...") // 1. didChange
|
||||
try db.execute(sql: "INSERT ...") // 1. didChange
|
||||
throw SomeError()
|
||||
} // 2. didRollback
|
||||
```
|
||||
@@ -7008,8 +7008,8 @@ Database statements that are executed outside of any transaction do not drop off
|
||||
|
||||
```swift
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "INSERT ...") // 1. didChange, 2. willCommit, 3. didCommit
|
||||
try db.execute(rawSQL: "UPDATE ...") // 4. didChange, 5. willCommit, 6. didCommit
|
||||
try db.execute(sql: "INSERT ...") // 1. didChange, 2. willCommit, 3. didCommit
|
||||
try db.execute(sql: "UPDATE ...") // 4. didChange, 5. willCommit, 6. didCommit
|
||||
}
|
||||
```
|
||||
|
||||
@@ -7017,16 +7017,16 @@ Changes that are on hold because of a [savepoint](https://www.sqlite.org/lang_sa
|
||||
|
||||
```swift
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT ...") // 1. didChange
|
||||
try db.execute(sql: "INSERT ...") // 1. didChange
|
||||
|
||||
try db.execute(rawSQL: "SAVEPOINT foo")
|
||||
try db.execute(rawSQL: "UPDATE ...") // delayed
|
||||
try db.execute(rawSQL: "UPDATE ...") // delayed
|
||||
try db.execute(rawSQL: "RELEASE SAVEPOINT foo") // 2. didChange, 3. didChange
|
||||
try db.execute(sql: "SAVEPOINT foo")
|
||||
try db.execute(sql: "UPDATE ...") // delayed
|
||||
try db.execute(sql: "UPDATE ...") // delayed
|
||||
try db.execute(sql: "RELEASE SAVEPOINT foo") // 2. didChange, 3. didChange
|
||||
|
||||
try db.execute(rawSQL: "SAVEPOINT foo")
|
||||
try db.execute(rawSQL: "UPDATE ...") // not notified
|
||||
try db.execute(rawSQL: "ROLLBACK TO SAVEPOINT foo")
|
||||
try db.execute(sql: "SAVEPOINT foo")
|
||||
try db.execute(sql: "UPDATE ...") // not notified
|
||||
try db.execute(sql: "ROLLBACK TO SAVEPOINT foo")
|
||||
|
||||
return .commit // 4. willCommit, 5. didCommit
|
||||
}
|
||||
@@ -7286,9 +7286,9 @@ configuration.passphrase = "secret"
|
||||
let encryptedDBQueue = try DatabaseQueue(path: "/path/to/encrypted.db", configuration: config)
|
||||
|
||||
try clearDBQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"])
|
||||
try db.execute(rawSQL: "SELECT sqlcipher_export('encrypted')")
|
||||
try db.execute(rawSQL: "DETACH DATABASE encrypted")
|
||||
try db.execute(sql: "ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"])
|
||||
try db.execute(sql: "SELECT sqlcipher_export('encrypted')")
|
||||
try db.execute(sql: "DETACH DATABASE encrypted")
|
||||
}
|
||||
|
||||
// Now the copy is done, and the clear-text database can be deleted.
|
||||
@@ -7327,7 +7327,7 @@ Here is an example of code that is vulnerable to SQL injection:
|
||||
let id = 1
|
||||
let name = textField.text
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "UPDATE students SET name = '\(name)' WHERE id = \(id)")
|
||||
try db.execute(sql: "UPDATE students SET name = '\(name)' WHERE id = \(id)")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -7346,12 +7346,12 @@ let name = textField.text
|
||||
try dbQueue.write { db in
|
||||
// Good
|
||||
try db.execute(
|
||||
rawSQL: "UPDATE students SET name = ? WHERE id = ?",
|
||||
sql: "UPDATE students SET name = ? WHERE id = ?",
|
||||
arguments: [name, id])
|
||||
|
||||
// Just as good
|
||||
try db.execute(
|
||||
rawSQL: "UPDATE students SET name = :name WHERE id = :id",
|
||||
sql: "UPDATE students SET name = :name WHERE id = :id",
|
||||
arguments: ["name": name, "id": id])
|
||||
}
|
||||
```
|
||||
@@ -7390,7 +7390,7 @@ Considering that a local database is not some JSON loaded from a remote server,
|
||||
```swift
|
||||
do {
|
||||
try db.execute(
|
||||
rawSQL: "INSERT INTO pet (masterId, name) VALUES (?, ?)",
|
||||
sql: "INSERT INTO pet (masterId, name) VALUES (?, ?)",
|
||||
arguments: [1, "Bobby"])
|
||||
} catch let error as DatabaseError {
|
||||
// The SQLite error code: 19 (SQLITE_CONSTRAINT)
|
||||
@@ -7540,7 +7540,7 @@ let sql = "SELECT ..."
|
||||
|
||||
// Some untrusted arguments for the query
|
||||
let arguments: [String: Any] = ...
|
||||
let rows = try Row.fetchCursor(db, rawSQL: sql, arguments: StatementArguments(arguments))
|
||||
let rows = try Row.fetchCursor(db, sql: sql, arguments: StatementArguments(arguments))
|
||||
|
||||
while let row = try rows.next() {
|
||||
// Some untrusted database value:
|
||||
@@ -7610,7 +7610,7 @@ The `UPPER` and `LOWER` built-in SQLite functions are not unicode-aware:
|
||||
|
||||
```swift
|
||||
// "JéRôME"
|
||||
try String.fetchOne(db, rawSQL: "SELECT UPPER('Jérôme')")
|
||||
try String.fetchOne(db, sql: "SELECT UPPER('Jérôme')")
|
||||
```
|
||||
|
||||
GRDB extends SQLite with [SQL functions](#custom-sql-functions-and-aggregates) that call the Swift built-in string functions `capitalized`, `lowercased`, `uppercased`, `localizedCapitalized`, `localizedLowercased` and `localizedUppercased`:
|
||||
@@ -7618,7 +7618,7 @@ GRDB extends SQLite with [SQL functions](#custom-sql-functions-and-aggregates) t
|
||||
```swift
|
||||
// "JÉRÔME"
|
||||
let uppercased = DatabaseFunction.uppercase
|
||||
try String.fetchOne(db, rawSQL: "SELECT \(uppercased.name)('Jérôme')")
|
||||
try String.fetchOne(db, sql: "SELECT \(uppercased.name)('Jérôme')")
|
||||
```
|
||||
|
||||
Those unicode-aware string functions are also readily available in the [query interface](#sql-functions):
|
||||
@@ -7664,7 +7664,7 @@ If you can't or don't want to define the comparison behavior of a column (see wa
|
||||
```swift
|
||||
let collation = DatabaseCollation.localizedCaseInsensitiveCompare
|
||||
let players = try Player.fetchAll(db,
|
||||
rawSQL: "SELECT * FROM player ORDER BY name COLLATE \(collation.name))")
|
||||
sql: "SELECT * FROM player ORDER BY name COLLATE \(collation.name))")
|
||||
let players = try Player.order(nameColumn.collating(collation)).fetchAll(db)
|
||||
```
|
||||
|
||||
@@ -8315,7 +8315,7 @@ let sql = """
|
||||
LEFT JOIN book ON book.authorId = author.id
|
||||
GROUP BY author.id
|
||||
"""
|
||||
let authors = try Author.fetchAll(db, rawSQL: sql)
|
||||
let authors = try Author.fetchAll(db, sql: sql)
|
||||
```
|
||||
|
||||
In the example above, consider extending your Author with an extra bookCount property, or define and use a different type.
|
||||
|
||||
@@ -51,7 +51,7 @@ class DatabaseQueueCrashTests: GRDBCrashTestCase {
|
||||
assertCrash("Database was not used on the correct thread: execute your statements inside DatabaseQueue.inDatabase() or DatabaseQueue.inTransaction(). If you get this error while iterating the result of a fetch() method, consider using the array returned by fetchAll() instead.") {
|
||||
var rows: DatabaseSequence<Row>?
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT)")
|
||||
rows = try Row.fetch(db, "SELECT * FROM persons")
|
||||
}
|
||||
_ = rows!.makeIterator()
|
||||
@@ -62,7 +62,7 @@ class DatabaseQueueCrashTests: GRDBCrashTestCase {
|
||||
assertCrash("Database was not used on the correct thread: execute your statements inside DatabaseQueue.inDatabase() or DatabaseQueue.inTransaction(). If you get this error while iterating the result of a fetch() method, consider using the array returned by fetchAll() instead.") {
|
||||
var iterator: DatabaseIterator<Row>?
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT)")
|
||||
iterator = try Row.fetch(db, "SELECT * FROM persons").makeIterator()
|
||||
}
|
||||
_ = iterator!.next()
|
||||
@@ -79,7 +79,7 @@ class DatabaseQueueCrashTests: GRDBCrashTestCase {
|
||||
let dbQueue2 = try! makeDatabaseQueue(path: dbQueuepath, configuration: dbConfiguration)
|
||||
|
||||
try! dbQueue1.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
let queue = NSOperationQueue()
|
||||
|
||||
@@ -29,9 +29,9 @@ class DatabaseValueConvertibleCrashTests: GRDBCrashTestCase {
|
||||
func testCrashFetchDatabaseValueConvertibleFromStatement() {
|
||||
assertCrash("could not convert NULL to IntConvertible.") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
try db.execute(sql: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let statement = try db.makeSelectStatement("SELECT int FROM ints ORDER BY int")
|
||||
let sequence = IntConvertible.fetch(statement)
|
||||
@@ -43,9 +43,9 @@ class DatabaseValueConvertibleCrashTests: GRDBCrashTestCase {
|
||||
func testCrashFetchAllDatabaseValueConvertibleFromStatement() {
|
||||
assertCrash("could not convert NULL to IntConvertible.") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
try db.execute(sql: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let statement = try db.makeSelectStatement("SELECT int FROM ints ORDER BY int")
|
||||
_ = IntConvertible.fetchAll(statement)
|
||||
@@ -56,9 +56,9 @@ class DatabaseValueConvertibleCrashTests: GRDBCrashTestCase {
|
||||
func testCrashFetchDatabaseValueConvertibleFromDatabase() {
|
||||
assertCrash("could not convert NULL to IntConvertible.") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
try db.execute(sql: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let sequence = IntConvertible.fetch(db, "SELECT int FROM ints ORDER BY int")
|
||||
for _ in sequence { }
|
||||
@@ -69,11 +69,11 @@ class DatabaseValueConvertibleCrashTests: GRDBCrashTestCase {
|
||||
func testCrashFetchAllDatabaseValueConvertibleFromDatabase() {
|
||||
assertCrash("could not convert NULL to IntConvertible.") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
try db.execute(sql: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
_ = IntConvertible.fetchAll(db, rawSQL: "SELECT int FROM ints ORDER BY int")
|
||||
_ = IntConvertible.fetchAll(db, sql: "SELECT int FROM ints ORDER BY int")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordWithEmptyPersistentDictionaryCanNotBeInserted() {
|
||||
assertCrash("RecordWithEmptyPersistentDictionary.persistentDictionary: invalid empty dictionary") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try RecordWithEmptyPersistentDictionary().insert(db)
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordWithEmptyPersistentDictionaryCanNotBeUpdated() {
|
||||
assertCrash("RecordWithEmptyPersistentDictionary.persistentDictionary: invalid empty dictionary") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try RecordWithEmptyPersistentDictionary().update(db)
|
||||
}
|
||||
}
|
||||
@@ -207,7 +207,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordWithEmptyPersistentDictionaryCanNotBeSaved() {
|
||||
assertCrash("RecordWithEmptyPersistentDictionary.persistentDictionary: invalid empty dictionary") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try RecordWithEmptyPersistentDictionary().save(db)
|
||||
}
|
||||
}
|
||||
@@ -216,7 +216,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordWithEmptyPersistentDictionaryCanNotBeDeleted() {
|
||||
assertCrash("RecordWithEmptyPersistentDictionary.persistentDictionary: invalid empty dictionary") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try RecordWithEmptyPersistentDictionary().delete(db)
|
||||
}
|
||||
}
|
||||
@@ -225,7 +225,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordWithEmptyPersistentDictionaryCanNotBeTestedForExistence() {
|
||||
assertCrash("RecordWithEmptyPersistentDictionary.persistentDictionary: invalid empty dictionary") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
RecordWithEmptyPersistentDictionary().exists(db)
|
||||
}
|
||||
}
|
||||
@@ -238,7 +238,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordWithNilPrimaryKeyCanNotBeUpdated() {
|
||||
assertCrash("invalid primary key in <RecordWithNilPrimaryKey id:nil>") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try RecordWithNilPrimaryKey().update(db)
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordWithNilPrimaryKeyCanNotBeDeleted() {
|
||||
assertCrash("invalid primary key in <RecordWithNilPrimaryKey id:nil>") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try RecordWithNilPrimaryKey().delete(db)
|
||||
}
|
||||
}
|
||||
@@ -256,7 +256,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordWithNilPrimaryKeyCanNotBeTestedForExistence() {
|
||||
assertCrash("invalid primary key in <RecordWithNilPrimaryKey id:nil>") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
RecordWithNilPrimaryKey().exists(db)
|
||||
}
|
||||
}
|
||||
@@ -269,7 +269,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordForTableWithoutPrimaryKeyCanNotBeFetchedByID() {
|
||||
assertCrash("expected single column primary key in table: records") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE records (name TEXT)")
|
||||
_ = RecordForTableWithoutPrimaryKey.fetchOne(db, key: 1)
|
||||
}
|
||||
}
|
||||
@@ -278,7 +278,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordForTableWithoutPrimaryKeyCanNotBeUpdated() {
|
||||
assertCrash("invalid primary key in <RecordForTableWithoutPrimaryKey name:\"foo\">") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE records (name TEXT)")
|
||||
try RecordForTableWithoutPrimaryKey().update(db)
|
||||
}
|
||||
}
|
||||
@@ -287,7 +287,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordForTableWithoutPrimaryKeyCanNotBeDeleted() {
|
||||
assertCrash("invalid primary key in <RecordForTableWithoutPrimaryKey name:\"foo\">") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE records (name TEXT)")
|
||||
try RecordForTableWithoutPrimaryKey().delete(db)
|
||||
}
|
||||
}
|
||||
@@ -296,7 +296,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordForTableWithoutPrimaryKeyCanNotBeTestedForExistence() {
|
||||
assertCrash("invalid primary key in <RecordForTableWithoutPrimaryKey name:\"foo\">") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE records (name TEXT)")
|
||||
RecordForTableWithoutPrimaryKey().exists(db)
|
||||
}
|
||||
}
|
||||
@@ -309,7 +309,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordForTableWithMultipleColumnsPrimaryKeyCanNotBeFetchedByID() {
|
||||
assertCrash("expected single column primary key in table: records") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (a TEXT, b TEXT, PRIMARY KEY(a,b))")
|
||||
try db.execute(sql: "CREATE TABLE records (a TEXT, b TEXT, PRIMARY KEY(a,b))")
|
||||
_ = RecordForTableWithMultipleColumnsPrimaryKey.fetchOne(db, key: 1)
|
||||
}
|
||||
}
|
||||
@@ -322,7 +322,7 @@ class RecordCrashTests: GRDBCrashTestCase {
|
||||
func testRecordWithRowIDPrimaryKeyNotExposedInPersistentDictionaryCanNotBeInserted() {
|
||||
assertCrash("invalid primary key in <RecordWithRowIDPrimaryKeyNotExposedInPersistentDictionary name:\"foo\">") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE records (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE records (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try RecordWithRowIDPrimaryKeyNotExposedInPersistentDictionary().update(db)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ class StatementColumnConvertibleCrashTests: GRDBCrashTestCase {
|
||||
func testCrashFetchStatementColumnConvertibleFromStatement() {
|
||||
assertCrash("could not convert NULL to Int.") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
try db.execute(sql: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let statement = try db.makeSelectStatement("SELECT int FROM ints ORDER BY int")
|
||||
let sequence = try Int.fetch(statement)
|
||||
@@ -26,9 +26,9 @@ class StatementColumnConvertibleCrashTests: GRDBCrashTestCase {
|
||||
func testCrashFetchAllStatementColumnConvertibleFromStatement() {
|
||||
assertCrash("could not convert NULL to Int.") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
try db.execute(sql: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let statement = try db.makeSelectStatement("SELECT int FROM ints ORDER BY int")
|
||||
_ = try Int.fetchAll(statement)
|
||||
@@ -39,9 +39,9 @@ class StatementColumnConvertibleCrashTests: GRDBCrashTestCase {
|
||||
func testCrashFetchStatementColumnConvertibleFromDatabase() {
|
||||
assertCrash("could not convert NULL to Int.") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
try db.execute(sql: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
let sequence = try Int.fetch(db, "SELECT int FROM ints ORDER BY int")
|
||||
for _ in sequence { }
|
||||
@@ -52,11 +52,11 @@ class StatementColumnConvertibleCrashTests: GRDBCrashTestCase {
|
||||
func testCrashFetchAllStatementColumnConvertibleFromDatabase() {
|
||||
assertCrash("could not convert NULL to Int.") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(rawSQL: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
try db.execute(sql: "CREATE TABLE ints (int Int)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO ints (int) VALUES (NULL)")
|
||||
|
||||
_ = try Int.fetchAll(db, rawSQL: "SELECT int FROM ints ORDER BY int")
|
||||
_ = try Int.fetchAll(db, sql: "SELECT int FROM ints ORDER BY int")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,15 @@ class StatementCrashTests: GRDBCrashTestCase {
|
||||
func testInvalidStatementArguments() {
|
||||
assertCrash("SQLite error 1 with statement `INSERT INTO persons (name, age) VALUES (:name, :age)`: missing statement argument(s): age") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try! db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur"])
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try! db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur"])
|
||||
}
|
||||
}
|
||||
|
||||
assertCrash("SQLite error 21 with statement `INSERT INTO persons (name, age) VALUES ('Arthur', ?);`: wrong number of statement arguments: 0") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: """
|
||||
INSERT INTO persons (name, age) VALUES ('Arthur', ?);
|
||||
INSERT INTO persons (name, age) VALUES ('Barbara', ?);
|
||||
""")
|
||||
@@ -29,8 +29,8 @@ class StatementCrashTests: GRDBCrashTestCase {
|
||||
|
||||
assertCrash("SQLite error 21 with statement `INSERT INTO persons (name, age) VALUES ('Barbara', ?);`: wrong number of statement arguments: 0") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: """
|
||||
INSERT INTO persons (name, age) VALUES ('Arthur', ?);
|
||||
INSERT INTO persons (name, age) VALUES ('Barbara', ?);
|
||||
""", arguments: [41])
|
||||
@@ -39,8 +39,8 @@ class StatementCrashTests: GRDBCrashTestCase {
|
||||
|
||||
assertCrash("SQLite error 21 with statement `INSERT INTO persons (name, age) VALUES ('Arthur', :age1);`: missing statement argument(s): age1") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: """
|
||||
INSERT INTO persons (name, age) VALUES ('Arthur', :age1);
|
||||
INSERT INTO persons (name, age) VALUES ('Barbara', :age2);
|
||||
""")
|
||||
@@ -49,8 +49,8 @@ class StatementCrashTests: GRDBCrashTestCase {
|
||||
|
||||
assertCrash("SQLite error 21 with statement `INSERT INTO persons (name, age) VALUES ('Barbara', :age2);`: missing statement argument(s): age2") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: """
|
||||
INSERT INTO persons (name, age) VALUES ('Arthur', :age1);
|
||||
INSERT INTO persons (name, age) VALUES ('Barbara', :age2);
|
||||
""", arguments: ["age1": 41])
|
||||
@@ -59,8 +59,8 @@ class StatementCrashTests: GRDBCrashTestCase {
|
||||
|
||||
assertCrash("SQLite error 21: wrong number of statement arguments: 3") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: """
|
||||
INSERT INTO persons (name, age) VALUES ('Arthur', :age1);
|
||||
INSERT INTO persons (name, age) VALUES ('Arthur', :age2);
|
||||
""", arguments: [41, 32, 17])
|
||||
@@ -69,8 +69,8 @@ class StatementCrashTests: GRDBCrashTestCase {
|
||||
|
||||
assertCrash("SQLite error 21: wrong number of statement arguments: 3") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: """
|
||||
INSERT INTO persons (name, age) VALUES ('Arthur', ?);
|
||||
INSERT INTO persons (name, age) VALUES ('Arthur', ?);
|
||||
""", arguments: [41, 32, 17])
|
||||
|
||||
@@ -88,7 +88,7 @@ class AssociationAggregateTests: GRDBTestCase {
|
||||
let tableAlias = TableAlias(name: "custom")
|
||||
let request = Team
|
||||
.annotated(with: Team.players.count)
|
||||
.joining(required: Team.players.aliased(tableAlias).filter(rawSQL: "custom.score < ?", arguments: [500]))
|
||||
.joining(required: Team.players.aliased(tableAlias).filter(sql: "custom.score < ?", arguments: [500]))
|
||||
|
||||
try assertEqualSQL(db, request, """
|
||||
SELECT "team".*, COUNT(DISTINCT "custom"."rowid") AS "playerCount" \
|
||||
|
||||
@@ -154,7 +154,7 @@ class AssociationBelongsToSQLDerivationTests: GRDBTestCase {
|
||||
let bAlias = TableAlias(name: "customB")
|
||||
let request = A.including(required: A.b
|
||||
.aliased(bAlias)
|
||||
.filter(rawSQL: "customB.name = ?", arguments: ["foo"]))
|
||||
.filter(sql: "customB.name = ?", arguments: ["foo"]))
|
||||
try assertEqualSQL(db, request, """
|
||||
SELECT "a".*, "customB".* \
|
||||
FROM "a" \
|
||||
|
||||
@@ -77,7 +77,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
func testChainOfTwoIncludingIncluding() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
do {
|
||||
let request = A.including(required: A.defaultB.including(required: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
let request = A.including(required: A.defaultB.including(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
@@ -95,7 +95,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
XCTAssertEqual(rows[1].scopes["b"]!.scopes["c"]!, ["id":2, "bid":1, "did":nil, "name":"c2"])
|
||||
}
|
||||
do {
|
||||
let request = A.including(required: A.defaultB.including(optional: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
let request = A.including(required: A.defaultB.including(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 3)
|
||||
@@ -120,11 +120,11 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
// TODO: chainOptionalRequired
|
||||
// let request = A.including(optional: A.defaultB.including(required: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
// let request = A.including(optional: A.defaultB.including(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
}
|
||||
do {
|
||||
let request = A.including(optional: A.defaultB.including(optional: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
let request = A.including(optional: A.defaultB.including(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 4)
|
||||
@@ -154,7 +154,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
XCTAssertEqual(rows[3].scopes["b"]!.scopes["c"]!, ["id":nil, "bid":nil, "did":nil, "name":nil])
|
||||
}
|
||||
do {
|
||||
let request = B.including(required: B.defaultC.including(required: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
let request = B.including(required: B.defaultC.including(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
@@ -166,7 +166,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
XCTAssertEqual(rows[0].scopes["c"]!.scopes["d"]!, ["id":1, "name":"d1"])
|
||||
}
|
||||
do {
|
||||
let request = B.including(required: B.defaultC.including(optional: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
let request = B.including(required: B.defaultC.including(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
@@ -185,11 +185,11 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
// TODO: chainOptionalRequired
|
||||
// let request = B.including(optional: B.defaultC.including(required: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
// let request = B.including(optional: B.defaultC.including(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
}
|
||||
do {
|
||||
let request = B.including(optional: B.defaultC.including(optional: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
let request = B.including(optional: B.defaultC.including(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 3)
|
||||
@@ -217,7 +217,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
func testChainOfTwoIncludingJoining() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
do {
|
||||
let request = A.including(required: A.defaultB.joining(required: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
let request = A.including(required: A.defaultB.joining(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
@@ -233,7 +233,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
XCTAssertTrue(rows[1].scopes["b"]!.scopes.names.isEmpty)
|
||||
}
|
||||
do {
|
||||
let request = A.including(required: A.defaultB.joining(optional: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
let request = A.including(required: A.defaultB.joining(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 3)
|
||||
@@ -255,11 +255,11 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
// TODO: chainOptionalRequired
|
||||
// let request = A.including(optional: A.defaultB.joining(required: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
// let request = A.including(optional: A.defaultB.joining(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
}
|
||||
do {
|
||||
let request = A.including(optional: A.defaultB.joining(optional: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
let request = A.including(optional: A.defaultB.joining(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 4)
|
||||
@@ -285,7 +285,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
XCTAssertTrue(rows[3].scopes["b"]!.scopes.names.isEmpty)
|
||||
}
|
||||
do {
|
||||
let request = B.including(required: B.defaultC.joining(required: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
let request = B.including(required: B.defaultC.joining(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
@@ -296,7 +296,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
XCTAssertTrue(rows[0].scopes["c"]!.scopes.names.isEmpty)
|
||||
}
|
||||
do {
|
||||
let request = B.including(required: B.defaultC.joining(optional: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
let request = B.including(required: B.defaultC.joining(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
@@ -313,11 +313,11 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
// TODO: chainOptionalRequired
|
||||
// let request = B.including(optional: B.defaultC.joining(required: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
// let request = B.including(optional: B.defaultC.joining(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
}
|
||||
do {
|
||||
let request = B.including(optional: B.defaultC.joining(optional: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
let request = B.including(optional: B.defaultC.joining(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 3)
|
||||
@@ -342,7 +342,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
func testChainOfTwoJoiningIncluding() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
do {
|
||||
let request = A.joining(required: A.defaultB.including(required: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
let request = A.joining(required: A.defaultB.including(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
@@ -360,7 +360,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
XCTAssertEqual(rows[1].scopes["b"]!.scopes["c"]!, ["id":2, "bid":1, "did":nil, "name":"c2"])
|
||||
}
|
||||
do {
|
||||
let request = A.joining(required: A.defaultB.including(optional: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
let request = A.joining(required: A.defaultB.including(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 3)
|
||||
@@ -385,11 +385,11 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
// TODO: chainOptionalRequired
|
||||
// let request = A.joining(optional: A.defaultB.including(required: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
// let request = A.joining(optional: A.defaultB.including(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
}
|
||||
do {
|
||||
let request = A.joining(optional: A.defaultB.including(optional: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
let request = A.joining(optional: A.defaultB.including(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 4)
|
||||
@@ -419,7 +419,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
XCTAssertEqual(rows[3].scopes["b"]!.scopes["c"]!, ["id":nil, "bid":nil, "did":nil, "name":nil])
|
||||
}
|
||||
do {
|
||||
let request = B.joining(required: B.defaultC.including(required: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
let request = B.joining(required: B.defaultC.including(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
@@ -431,7 +431,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
XCTAssertEqual(rows[0].scopes["c"]!.scopes["d"]!, ["id":1, "name":"d1"])
|
||||
}
|
||||
do {
|
||||
let request = B.joining(required: B.defaultC.including(optional: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
let request = B.joining(required: B.defaultC.including(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
@@ -450,11 +450,11 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
// TODO: chainOptionalRequired
|
||||
// let request = B.joining(optional: B.defaultC.including(required: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
// let request = B.joining(optional: B.defaultC.including(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
}
|
||||
do {
|
||||
let request = B.joining(optional: B.defaultC.including(optional: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
let request = B.joining(optional: B.defaultC.including(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 3)
|
||||
@@ -482,7 +482,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
func testChainOfTwoJoiningJoining() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
do {
|
||||
let request = A.joining(required: A.defaultB.joining(required: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
let request = A.joining(required: A.defaultB.joining(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
@@ -494,7 +494,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
XCTAssertTrue(rows[1].scopes.names.isEmpty)
|
||||
}
|
||||
do {
|
||||
let request = A.joining(required: A.defaultB.joining(optional: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
let request = A.joining(required: A.defaultB.joining(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 3)
|
||||
@@ -510,11 +510,11 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
// TODO: chainOptionalRequired
|
||||
// let request = A.joining(optional: A.defaultB.joining(required: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
// let request = A.joining(optional: A.defaultB.joining(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
}
|
||||
do {
|
||||
let request = A.joining(optional: A.defaultB.joining(optional: B.defaultC)).order(rawSQL: "a.id, b.id, c.id")
|
||||
let request = A.joining(optional: A.defaultB.joining(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 4)
|
||||
@@ -532,7 +532,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
XCTAssertTrue(rows[3].scopes.names.isEmpty)
|
||||
}
|
||||
do {
|
||||
let request = B.joining(required: B.defaultC.joining(required: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
let request = B.joining(required: B.defaultC.joining(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
@@ -541,7 +541,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
XCTAssertTrue(rows[0].scopes.names.isEmpty)
|
||||
}
|
||||
do {
|
||||
let request = B.joining(required: B.defaultC.joining(optional: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
let request = B.joining(required: B.defaultC.joining(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
@@ -554,11 +554,11 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
// TODO: chainOptionalRequired
|
||||
// let request = B.joining(optional: B.defaultC.joining(required: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
// let request = B.joining(optional: B.defaultC.joining(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
}
|
||||
do {
|
||||
let request = B.joining(optional: B.defaultC.joining(optional: C.defaultD)).order(rawSQL: "b.id, c.id, d.id")
|
||||
let request = B.joining(optional: B.defaultC.joining(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 3)
|
||||
@@ -576,7 +576,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
|
||||
func testChainOfThreeIncludingIncludingIncluding() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let request = A.including(required: A.defaultB.including(required: B.defaultC.including(required: C.defaultD))).order(rawSQL: "a.id, b.id, c.id, d.id")
|
||||
let request = A.including(required: A.defaultB.including(required: B.defaultC.including(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
@@ -592,7 +592,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
|
||||
func testChainOfThreeIncludingIncludingJoining() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let request = A.including(required: A.defaultB.including(required: B.defaultC.joining(required: C.defaultD))).order(rawSQL: "a.id, b.id, c.id, d.id")
|
||||
let request = A.including(required: A.defaultB.including(required: B.defaultC.joining(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
@@ -607,7 +607,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
|
||||
func testChainOfThreeIncludingJoiningIncluding() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let request = A.including(required: A.defaultB.joining(required: B.defaultC.including(required: C.defaultD))).order(rawSQL: "a.id, b.id, c.id, d.id")
|
||||
let request = A.including(required: A.defaultB.joining(required: B.defaultC.including(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
@@ -623,7 +623,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
|
||||
func testChainOfThreeIncludingJoiningJoining() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let request = A.including(required: A.defaultB.joining(required: B.defaultC.joining(required: C.defaultD))).order(rawSQL: "a.id, b.id, c.id, d.id")
|
||||
let request = A.including(required: A.defaultB.joining(required: B.defaultC.joining(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
@@ -636,7 +636,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
|
||||
func testChainOfThreeJoiningIncludingIncluding() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let request = A.joining(required: A.defaultB.including(required: B.defaultC.including(required: C.defaultD))).order(rawSQL: "a.id, b.id, c.id, d.id")
|
||||
let request = A.joining(required: A.defaultB.including(required: B.defaultC.including(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
@@ -652,7 +652,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
|
||||
func testChainOfThreeJoiningIncludingJoining() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let request = A.joining(required: A.defaultB.including(required: B.defaultC.joining(required: C.defaultD))).order(rawSQL: "a.id, b.id, c.id, d.id")
|
||||
let request = A.joining(required: A.defaultB.including(required: B.defaultC.joining(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
@@ -667,7 +667,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
|
||||
func testChainOfThreeJoiningJoiningIncluding() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let request = A.joining(required: A.defaultB.joining(required: B.defaultC.including(required: C.defaultD))).order(rawSQL: "a.id, b.id, c.id, d.id")
|
||||
let request = A.joining(required: A.defaultB.joining(required: B.defaultC.including(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
@@ -683,7 +683,7 @@ class AssociationChainRowScopesTests: GRDBTestCase {
|
||||
|
||||
func testChainOfThreeJoiningJoiningJoining() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let request = A.joining(required: A.defaultB.joining(required: B.defaultC.joining(required: C.defaultD))).order(rawSQL: "a.id, b.id, c.id, d.id")
|
||||
let request = A.joining(required: A.defaultB.joining(required: B.defaultC.joining(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
|
||||
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
|
||||
@@ -154,7 +154,7 @@ class AssociationHasOneSQLDerivationTests: GRDBTestCase {
|
||||
let bAlias = TableAlias(name: "customB")
|
||||
let request = A.including(required: A.b
|
||||
.aliased(bAlias)
|
||||
.filter(rawSQL: "customB.name = ?", arguments: ["foo"]))
|
||||
.filter(sql: "customB.name = ?", arguments: ["foo"]))
|
||||
try assertEqualSQL(db, request, """
|
||||
SELECT "a".*, "customB".* \
|
||||
FROM "a" \
|
||||
|
||||
@@ -86,7 +86,7 @@ class AssociationParallelDecodableRecordTests: GRDBTestCase {
|
||||
let request = A
|
||||
.including(required: AWithRequiredBD.b)
|
||||
.including(required: AWithRequiredBD.d)
|
||||
.order(rawSQL: "a.id, b.id, d.id")
|
||||
.order(sql: "a.id, b.id, d.id")
|
||||
.asRequest(of: AWithRequiredBD.self)
|
||||
let records = try dbQueue.inDatabase { try request.fetchAll($0) }
|
||||
|
||||
@@ -116,7 +116,7 @@ class AssociationParallelDecodableRecordTests: GRDBTestCase {
|
||||
let request = A
|
||||
.including(optional: AWithOptionalBD.b)
|
||||
.including(optional: AWithOptionalBD.d)
|
||||
.order(rawSQL: "a.id, b.id, d.id")
|
||||
.order(sql: "a.id, b.id, d.id")
|
||||
.asRequest(of: AWithOptionalBD.self)
|
||||
let records = try dbQueue.inDatabase { try request.fetchAll($0) }
|
||||
|
||||
@@ -177,7 +177,7 @@ class AssociationParallelDecodableRecordTests: GRDBTestCase {
|
||||
let request = A
|
||||
.joining(required: A.b)
|
||||
.joining(required: A.d)
|
||||
.order(rawSQL: "a.id, b.id, d.id")
|
||||
.order(sql: "a.id, b.id, d.id")
|
||||
let records = try dbQueue.inDatabase { try request.fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(records.count, 2)
|
||||
@@ -198,7 +198,7 @@ class AssociationParallelDecodableRecordTests: GRDBTestCase {
|
||||
let request = A
|
||||
.joining(optional: A.b)
|
||||
.joining(optional: A.d)
|
||||
.order(rawSQL: "a.id, b.id, d.id")
|
||||
.order(sql: "a.id, b.id, d.id")
|
||||
let records = try dbQueue.inDatabase { try request.fetchAll($0) }
|
||||
|
||||
XCTAssertEqual(records.count, 6)
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -55,11 +55,11 @@ class AssociationRowScopeSearchTests: GRDBTestCase {
|
||||
t.column("id", .integer).primaryKey()
|
||||
t.column("bid", .integer).references("b")
|
||||
}
|
||||
try db.execute(rawSQL: "INSERT INTO a (id) VALUES (1)")
|
||||
try db.execute(rawSQL: "INSERT INTO b (id, aid) VALUES (2, 1)")
|
||||
try db.execute(rawSQL: "INSERT INTO c (id, aid, bid) VALUES (3, NULL, 2)")
|
||||
try db.execute(rawSQL: "INSERT INTO c (id, aid, bid) VALUES (4, 1, NULL)")
|
||||
try db.execute(rawSQL: "INSERT INTO d (id, bid) VALUES (5, 2)")
|
||||
try db.execute(sql: "INSERT INTO a (id) VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO b (id, aid) VALUES (2, 1)")
|
||||
try db.execute(sql: "INSERT INTO c (id, aid, bid) VALUES (3, NULL, 2)")
|
||||
try db.execute(sql: "INSERT INTO c (id, aid, bid) VALUES (4, 1, NULL)")
|
||||
try db.execute(sql: "INSERT INTO d (id, bid) VALUES (5, 2)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,13 +13,13 @@ class CGFloatTests: GRDBTestCase {
|
||||
func testCGFLoat() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE points (x DOUBLE, y DOUBLE)")
|
||||
try db.execute(sql: "CREATE TABLE points (x DOUBLE, y DOUBLE)")
|
||||
|
||||
let x: CGFloat = 1
|
||||
let y: CGFloat? = nil
|
||||
try db.execute(rawSQL: "INSERT INTO points VALUES (?,?)", arguments: [x, y])
|
||||
try db.execute(sql: "INSERT INTO points VALUES (?,?)", arguments: [x, y])
|
||||
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT * FROM points")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT * FROM points")!
|
||||
let fetchedX: CGFloat = row["x"]
|
||||
let fetchedY: CGFloat? = row["y"]
|
||||
XCTAssertEqual(x, fetchedX)
|
||||
|
||||
@@ -17,7 +17,7 @@ class ColumnInfoTests: GRDBTestCase {
|
||||
func testColumnInfo() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE t (
|
||||
a INT,
|
||||
b TEXT,
|
||||
|
||||
@@ -22,7 +22,7 @@ class DataMemoryTests: GRDBTestCase {
|
||||
// https://forums.swift.org/t/swift-5-how-to-test-data-bytesnocopydeallocator/20299/2?u=gwendal.roue
|
||||
let data = Data(repeating: 0xaa, count: 15)
|
||||
|
||||
let rows = try Row.fetchCursor(db, rawSQL: "SELECT ?", arguments: [data])
|
||||
let rows = try Row.fetchCursor(db, sql: "SELECT ?", arguments: [data])
|
||||
while let row = try rows.next() {
|
||||
let blobPointer = sqlite3_column_blob(row.sqliteStatement, 0)
|
||||
|
||||
@@ -45,7 +45,7 @@ class DataMemoryTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT ?", arguments: [data])!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT ?", arguments: [data])!
|
||||
let dbValue = row.first!.1 // TODO: think about exposing a (column:,databaseValue:) tuple
|
||||
switch dbValue.storage {
|
||||
case .blob(let data):
|
||||
|
||||
@@ -62,8 +62,8 @@ class DatabaseAfterNextTransactionCommitTests: GRDBTestCase {
|
||||
|
||||
XCTAssertNotNil(deallocationWitness)
|
||||
XCTAssertEqual(transactionCount, 0)
|
||||
try db.execute(rawSQL: startSQL)
|
||||
try db.execute(rawSQL: endSQL)
|
||||
try db.execute(sql: startSQL)
|
||||
try db.execute(sql: endSQL)
|
||||
switch expectedCompletion {
|
||||
case .commit:
|
||||
XCTAssertEqual(transactionCount, 1, "\(startSQL); \(endSQL)")
|
||||
@@ -73,7 +73,7 @@ class DatabaseAfterNextTransactionCommitTests: GRDBTestCase {
|
||||
XCTAssertNil(deallocationWitness)
|
||||
|
||||
try db.inTransaction {
|
||||
try db.execute(rawSQL: "DROP TABLE IF EXISTS t; CREATE TABLE t(a); ")
|
||||
try db.execute(sql: "DROP TABLE IF EXISTS t; CREATE TABLE t(a); ")
|
||||
return .commit
|
||||
}
|
||||
switch expectedCompletion {
|
||||
@@ -91,7 +91,7 @@ class DatabaseAfterNextTransactionCommitTests: GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.writeWithoutTransaction { db in
|
||||
var transactionCount = 0
|
||||
try db.execute(rawSQL: startSQL)
|
||||
try db.execute(sql: startSQL)
|
||||
|
||||
weak var deallocationWitness: Witness? = nil
|
||||
do {
|
||||
@@ -106,7 +106,7 @@ class DatabaseAfterNextTransactionCommitTests: GRDBTestCase {
|
||||
|
||||
XCTAssertNotNil(deallocationWitness)
|
||||
XCTAssertEqual(transactionCount, 0)
|
||||
try db.execute(rawSQL: endSQL)
|
||||
try db.execute(sql: endSQL)
|
||||
switch expectedCompletion {
|
||||
case .commit:
|
||||
XCTAssertEqual(transactionCount, 1, "\(startSQL); \(endSQL)")
|
||||
@@ -116,7 +116,7 @@ class DatabaseAfterNextTransactionCommitTests: GRDBTestCase {
|
||||
XCTAssertNil(deallocationWitness)
|
||||
|
||||
try db.inTransaction {
|
||||
try db.execute(rawSQL: "DROP TABLE IF EXISTS t; CREATE TABLE t(a); ")
|
||||
try db.execute(sql: "DROP TABLE IF EXISTS t; CREATE TABLE t(a); ")
|
||||
return .commit
|
||||
}
|
||||
switch expectedCompletion {
|
||||
|
||||
@@ -34,7 +34,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try DatabaseValue.fetchOne(db, rawSQL: "SELECT f()")!.isNull)
|
||||
XCTAssertTrue(try DatabaseValue.fetchOne(db, sql: "SELECT f()")!.isNull)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int64.fetchOne(db, rawSQL: "SELECT f()")!, Int64(1))
|
||||
XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f()")!, Int64(1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Double.fetchOne(db, rawSQL: "SELECT f()")!, 1e100)
|
||||
XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f()")!, 1e100)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT f()")!, "foo")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f()")!, "foo")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Data.fetchOne(db, rawSQL: "SELECT f()")!, "foo".data(using: .utf8))
|
||||
XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f()")!, "foo".data(using: .utf8))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, rawSQL: "SELECT f()") != nil)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f()") != nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,12 +129,12 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try Bool.fetchOne(db, rawSQL: "SELECT f(NULL)")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, rawSQL: "SELECT f(1)")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, rawSQL: "SELECT f(1.1)")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, rawSQL: "SELECT f('foo')")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, rawSQL: "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, rawSQL: "SELECT f(?)", arguments: [Data()])!)
|
||||
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)")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f('foo')")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(?)", arguments: [Data()])!)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,9 +152,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try Int64.fetchOne(db, rawSQL: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try Int64.fetchOne(db, rawSQL: "SELECT f(1)")!, 1)
|
||||
XCTAssertEqual(try Int64.fetchOne(db, rawSQL: "SELECT f(1.1)")!, 1)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,9 +172,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try Double.fetchOne(db, rawSQL: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try Double.fetchOne(db, rawSQL: "SELECT f(1)")!, 1.0)
|
||||
XCTAssertEqual(try Double.fetchOne(db, rawSQL: "SELECT f(1.1)")!, 1.1)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,8 +192,8 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try String.fetchOne(db, rawSQL: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT f('foo')")!, "foo")
|
||||
XCTAssertTrue(try String.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f('foo')")!, "foo")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,9 +211,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try Data.fetchOne(db, rawSQL: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try Data.fetchOne(db, rawSQL: "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!, "foo".data(using: .utf8))
|
||||
XCTAssertEqual(try Data.fetchOne(db, rawSQL: "SELECT f(?)", arguments: [Data()])!, Data())
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,8 +231,8 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, rawSQL: "SELECT f(NULL)") == nil)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, rawSQL: "SELECT f('CustomValueType')") != nil)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f('CustomValueType')") != nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,9 +249,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 0, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT f()")!, "foo")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f()")!, "foo")
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f(1)")
|
||||
try db.execute(sql: "SELECT f(1)")
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -276,11 +276,11 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT upper(?)", arguments: ["Roué"])!, "ROUé")
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT f(?)", arguments: ["Roué"])!, "ROUÉ")
|
||||
XCTAssertTrue(try String.fetchOne(db, rawSQL: "SELECT f(NULL)") == nil)
|
||||
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)
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -306,9 +306,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 2, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT f(1, 2)")!, 3)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1, 2)")!, 3)
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -333,9 +333,9 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT f()")!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT f(1)")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT f(1, 1)")!, 2)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -378,7 +378,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode.rawValue, 123)
|
||||
@@ -401,7 +401,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode.rawValue, 123)
|
||||
@@ -424,7 +424,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -449,7 +449,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -470,7 +470,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode.rawValue, 123)
|
||||
@@ -491,7 +491,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode.rawValue, 123)
|
||||
@@ -512,7 +512,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -541,7 +541,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT f(a) FROM (SELECT 1 AS a UNION ALL SELECT 2 UNION ALL SELECT 3)")!, 6)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(a) FROM (SELECT 1 AS a UNION ALL SELECT 2 UNION ALL SELECT 3)")!, 6)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -561,7 +561,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
let fn = DatabaseFunction("f", argumentCount: 1, aggregate: Aggregate.self)
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT f(a), f(b) FROM (SELECT 1 AS a, 2 AS b UNION ALL SELECT 2, 4 UNION ALL SELECT 3, 6)")!
|
||||
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)
|
||||
}
|
||||
@@ -596,7 +596,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(allocationCount, 0)
|
||||
XCTAssertEqual(aliveCount, 0)
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTAssertEqual(allocationCount, 1)
|
||||
XCTAssertEqual(aliveCount, 0)
|
||||
}
|
||||
@@ -631,7 +631,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(allocationCount, 0)
|
||||
XCTAssertEqual(aliveCount, 0)
|
||||
_ = try? db.execute(rawSQL: "SELECT f()")
|
||||
_ = try? db.execute(sql: "SELECT f()")
|
||||
XCTAssertEqual(allocationCount, 1)
|
||||
XCTAssertEqual(aliveCount, 0)
|
||||
}
|
||||
@@ -665,7 +665,7 @@ class DatabaseAggregateTests: GRDBTestCase {
|
||||
dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(allocationCount, 0)
|
||||
XCTAssertEqual(aliveCount, 0)
|
||||
_ = try? db.execute(rawSQL: "SELECT f()")
|
||||
_ = try? db.execute(sql: "SELECT f()")
|
||||
XCTAssertEqual(allocationCount, 1)
|
||||
XCTAssertEqual(aliveCount, 0)
|
||||
}
|
||||
|
||||
@@ -12,37 +12,37 @@ class DatabaseCollationTests: GRDBTestCase {
|
||||
func testDefaultCollations() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE strings (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (1, '1')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (2, '2')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (3, '10')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (4, 'a')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (5, 'à')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (6, 'A')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (7, 'Z')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (8, 'z')")
|
||||
try db.execute(sql: "CREATE TABLE strings (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (1, '1')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (2, '2')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (3, '10')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (4, 'a')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (5, 'à')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (6, 'A')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (7, 'Z')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (8, 'z')")
|
||||
|
||||
// Swift 4.2 and Swift 4.1 don't sort strings in the same way
|
||||
if "z" < "à" {
|
||||
XCTAssertEqual(
|
||||
try Int.fetchAll(db, rawSQL: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.unicodeCompare.name), id"),
|
||||
try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.unicodeCompare.name), id"),
|
||||
[1,3,2,6,7,4,8,5])
|
||||
} else {
|
||||
XCTAssertEqual(
|
||||
try Int.fetchAll(db, rawSQL: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.unicodeCompare.name), id"),
|
||||
try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.unicodeCompare.name), id"),
|
||||
[1,3,2,6,7,4,5,8])
|
||||
}
|
||||
XCTAssertEqual(
|
||||
try Int.fetchAll(db, rawSQL: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.caseInsensitiveCompare.name), id"),
|
||||
try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.caseInsensitiveCompare.name), id"),
|
||||
[1,3,2,4,6,5,7,8])
|
||||
XCTAssertEqual(
|
||||
try Int.fetchAll(db, rawSQL: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.localizedCaseInsensitiveCompare.name), id"),
|
||||
try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.localizedCaseInsensitiveCompare.name), id"),
|
||||
[1,3,2,4,6,5,7,8])
|
||||
XCTAssertEqual(
|
||||
try Int.fetchAll(db, rawSQL: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.localizedCompare.name), id"),
|
||||
try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.localizedCompare.name), id"),
|
||||
[1,3,2,4,6,5,8,7])
|
||||
XCTAssertEqual(
|
||||
try Int.fetchAll(db, rawSQL: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.localizedStandardCompare.name), id"),
|
||||
try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY name COLLATE \(DatabaseCollation.localizedStandardCompare.name), id"),
|
||||
[1,2,3,4,6,5,8,7])
|
||||
}
|
||||
}
|
||||
@@ -63,18 +63,18 @@ class DatabaseCollationTests: GRDBTestCase {
|
||||
dbQueue.add(collation: collation)
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE strings (id INTEGER PRIMARY KEY, name TEXT COLLATE LOCALIZED_STANDARD)")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (1, 'a')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (2, 'aa')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (3, 'aaa')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (4, 'b')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (5, 'bb')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (6, 'bbb')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (7, 'c')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (8, 'cc')")
|
||||
try db.execute(rawSQL: "INSERT INTO strings VALUES (9, 'ccc')")
|
||||
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')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (3, 'aaa')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (4, 'b')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (5, 'bb')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (6, 'bbb')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (7, 'c')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (8, 'cc')")
|
||||
try db.execute(sql: "INSERT INTO strings VALUES (9, 'ccc')")
|
||||
|
||||
let ids = try Int.fetchAll(db, rawSQL: "SELECT id FROM strings ORDER BY NAME")
|
||||
let ids = try Int.fetchAll(db, sql: "SELECT id FROM strings ORDER BY NAME")
|
||||
XCTAssertEqual(ids, [1,4,7,2,5,8,3,6,9])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,18 +14,18 @@ class DatabaseCursorTests: GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
let cursor = try Int.fetchCursor(db, rawSQL: "SELECT 1 WHERE 0")
|
||||
let cursor = try Int.fetchCursor(db, sql: "SELECT 1 WHERE 0")
|
||||
XCTAssert(try cursor.next() == nil) // end
|
||||
XCTAssert(try cursor.next() == nil) // past the end
|
||||
}
|
||||
do {
|
||||
let cursor = try Int.fetchCursor(db, rawSQL: "SELECT 1")
|
||||
let cursor = try Int.fetchCursor(db, sql: "SELECT 1")
|
||||
XCTAssertEqual(try cursor.next()!, 1)
|
||||
XCTAssert(try cursor.next() == nil) // end
|
||||
XCTAssert(try cursor.next() == nil) // past the end
|
||||
}
|
||||
do {
|
||||
let cursor = try Int.fetchCursor(db, rawSQL: "SELECT 1 UNION ALL SELECT 2")
|
||||
let cursor = try Int.fetchCursor(db, sql: "SELECT 1 UNION ALL SELECT 2")
|
||||
XCTAssertEqual(try cursor.next()!, 1)
|
||||
XCTAssertEqual(try cursor.next()!, 2)
|
||||
XCTAssert(try cursor.next() == nil) // end
|
||||
@@ -40,7 +40,7 @@ class DatabaseCursorTests: GRDBTestCase {
|
||||
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 cursor = try Int.fetchCursor(db, rawSQL: "SELECT throw()")
|
||||
let cursor = try Int.fetchCursor(db, sql: "SELECT throw()")
|
||||
do {
|
||||
_ = try cursor.next()
|
||||
XCTFail()
|
||||
@@ -59,7 +59,7 @@ class DatabaseCursorTests: GRDBTestCase {
|
||||
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
|
||||
let cursor = try Int.fetchCursor(db, rawSQL: "SELECT throw()")
|
||||
let cursor = try Int.fetchCursor(db, sql: "SELECT throw()")
|
||||
do {
|
||||
_ = try cursor.next()
|
||||
XCTFail()
|
||||
|
||||
@@ -69,7 +69,7 @@ class DatabaseDateDecodingStrategyTests: GRDBTestCase {
|
||||
databaseValue: DatabaseValueConvertible?,
|
||||
with test: (Date?) -> Void) throws
|
||||
{
|
||||
let request = SQLRequest<Void>(rawSQL: "SELECT ? AS date", arguments: [databaseValue])
|
||||
let request = SQLRequest<Void>(sql: "SELECT ? AS date", arguments: [databaseValue])
|
||||
do {
|
||||
// test decoding straight from SQLite
|
||||
let record = try T.fetchOne(db, request)!
|
||||
|
||||
@@ -24,10 +24,10 @@ class DatabaseErrorTests: GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
do {
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(rawSQL: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)")
|
||||
sqlQueries.removeAll()
|
||||
try db.execute(rawSQL: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"])
|
||||
try db.execute(sql: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"])
|
||||
XCTFail()
|
||||
return .commit
|
||||
}
|
||||
@@ -55,10 +55,10 @@ class DatabaseErrorTests: GRDBTestCase {
|
||||
do {
|
||||
try db.inSavepoint {
|
||||
XCTAssertTrue(db.isInsideTransaction)
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(rawSQL: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)")
|
||||
sqlQueries.removeAll()
|
||||
try db.execute(rawSQL: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"])
|
||||
try db.execute(sql: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"])
|
||||
XCTFail()
|
||||
return .commit
|
||||
}
|
||||
@@ -82,14 +82,14 @@ class DatabaseErrorTests: GRDBTestCase {
|
||||
func testDatabaseErrorThrownByUpdateStatementContainSQLAndArguments() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(rawSQL: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)")
|
||||
}
|
||||
|
||||
// db.execute(sql, arguments)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"])
|
||||
try db.execute(sql: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [1, "Bobby"])
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError {
|
||||
// SQLITE_CONSTRAINT_FOREIGNKEY was added in SQLite 3.7.16 http://www.sqlite.org/changes.html#version_3_7_16
|
||||
@@ -142,7 +142,7 @@ class DatabaseErrorTests: GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, age INT);
|
||||
CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT);
|
||||
INSERT INTO pets (masterId, name) VALUES (1, 'Bobby')
|
||||
@@ -166,7 +166,7 @@ class DatabaseErrorTests: GRDBTestCase {
|
||||
try db.create(table: "parents") { $0.column("id", .integer).primaryKey() }
|
||||
try db.create(table: "children") { $0.column("parentId", .integer).references("parents") }
|
||||
do {
|
||||
try db.execute(rawSQL: "INSERT INTO children (parentId) VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO children (parentId) VALUES (1)")
|
||||
} catch let error as DatabaseError {
|
||||
// SQLITE_CONSTRAINT_FOREIGNKEY was added in SQLite 3.7.16 http://www.sqlite.org/changes.html#version_3_7_16
|
||||
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
|
||||
@@ -182,7 +182,7 @@ class DatabaseErrorTests: GRDBTestCase {
|
||||
try db.create(table: "parents") { $0.column("id", .integer).primaryKey() }
|
||||
try db.create(table: "children") { $0.column("parentId", .integer).references("parents") }
|
||||
do {
|
||||
try db.execute(rawSQL: "INSERT INTO children (parentId) VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO children (parentId) VALUES (1)")
|
||||
} catch let error as NSError {
|
||||
XCTAssertEqual(DatabaseError.errorDomain, "GRDB.DatabaseError")
|
||||
XCTAssertEqual(error.domain, DatabaseError.errorDomain)
|
||||
|
||||
@@ -31,25 +31,25 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
// See Database.setupDefaultFunctions()
|
||||
|
||||
let capitalize = DatabaseFunction.capitalize
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT \(capitalize.name)('jérÔME')"), "Jérôme")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT \(capitalize.name)('jérÔME')"), "Jérôme")
|
||||
|
||||
let lowercase = DatabaseFunction.lowercase
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT \(lowercase.name)('jérÔME')"), "jérôme")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT \(lowercase.name)('jérÔME')"), "jérôme")
|
||||
|
||||
let uppercase = DatabaseFunction.uppercase
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT \(uppercase.name)('jérÔME')"), "JÉRÔME")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT \(uppercase.name)('jérÔME')"), "JÉRÔME")
|
||||
|
||||
if #available(iOS 9.0, OSX 10.11, *) {
|
||||
// Locale-dependent tests. Are they fragile?
|
||||
|
||||
let localizedCapitalize = DatabaseFunction.localizedCapitalize
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT \(localizedCapitalize.name)('jérÔME')"), "Jérôme")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT \(localizedCapitalize.name)('jérÔME')"), "Jérôme")
|
||||
|
||||
let localizedLowercase = DatabaseFunction.localizedLowercase
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT \(localizedLowercase.name)('jérÔME')"), "jérôme")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT \(localizedLowercase.name)('jérÔME')"), "jérôme")
|
||||
|
||||
let localizedUppercase = DatabaseFunction.localizedUppercase
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT \(localizedUppercase.name)('jérÔME')"), "JÉRÔME")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT \(localizedUppercase.name)('jérÔME')"), "JÉRÔME")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try DatabaseValue.fetchOne(db, rawSQL: "SELECT f()")!.isNull)
|
||||
XCTAssertTrue(try DatabaseValue.fetchOne(db, sql: "SELECT f()")!.isNull)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int64.fetchOne(db, rawSQL: "SELECT f()")!, Int64(1))
|
||||
XCTAssertEqual(try Int64.fetchOne(db, sql: "SELECT f()")!, Int64(1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Double.fetchOne(db, rawSQL: "SELECT f()")!, 1e100)
|
||||
XCTAssertEqual(try Double.fetchOne(db, sql: "SELECT f()")!, 1e100)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT f()")!, "foo")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f()")!, "foo")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Data.fetchOne(db, rawSQL: "SELECT f()")!, "foo".data(using: .utf8))
|
||||
XCTAssertEqual(try Data.fetchOne(db, sql: "SELECT f()")!, "foo".data(using: .utf8))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, rawSQL: "SELECT f()") != nil)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f()") != nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,12 +131,12 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try Bool.fetchOne(db, rawSQL: "SELECT f(NULL)")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, rawSQL: "SELECT f(1)")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, rawSQL: "SELECT f(1.1)")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, rawSQL: "SELECT f('foo')")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, rawSQL: "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, rawSQL: "SELECT f(?)", arguments: [Data()])!)
|
||||
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)")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f('foo')")!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!)
|
||||
XCTAssertFalse(try Bool.fetchOne(db, sql: "SELECT f(?)", arguments: [Data()])!)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,9 +147,9 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try Int64.fetchOne(db, rawSQL: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try Int64.fetchOne(db, rawSQL: "SELECT f(1)")!, 1)
|
||||
XCTAssertEqual(try Int64.fetchOne(db, rawSQL: "SELECT f(1.1)")!, 1)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,9 +160,9 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try Double.fetchOne(db, rawSQL: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try Double.fetchOne(db, rawSQL: "SELECT f(1)")!, 1.0)
|
||||
XCTAssertEqual(try Double.fetchOne(db, rawSQL: "SELECT f(1.1)")!, 1.1)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,8 +173,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try String.fetchOne(db, rawSQL: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT f('foo')")!, "foo")
|
||||
XCTAssertTrue(try String.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f('foo')")!, "foo")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,9 +185,9 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try Data.fetchOne(db, rawSQL: "SELECT f(NULL)") == nil)
|
||||
XCTAssertEqual(try Data.fetchOne(db, rawSQL: "SELECT f(?)", arguments: ["foo".data(using: .utf8)])!, "foo".data(using: .utf8))
|
||||
XCTAssertEqual(try Data.fetchOne(db, rawSQL: "SELECT f(?)", arguments: [Data()])!, Data())
|
||||
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,8 +198,8 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, rawSQL: "SELECT f(NULL)") == nil)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, rawSQL: "SELECT f('CustomValueType')") != nil)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f(NULL)") == nil)
|
||||
XCTAssertTrue(try CustomValueType.fetchOne(db, sql: "SELECT f('CustomValueType')") != nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,9 +212,9 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT f()")!, "foo")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT f()")!, "foo")
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f(1)")
|
||||
try db.execute(sql: "SELECT f(1)")
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -232,11 +232,11 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT upper(?)", arguments: ["Roué"])!, "ROUé")
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT f(?)", arguments: ["Roué"])!, "ROUÉ")
|
||||
XCTAssertTrue(try String.fetchOne(db, rawSQL: "SELECT f(NULL)") == nil)
|
||||
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)
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -255,9 +255,9 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT f(1, 2)")!, 3)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f(1, 2)")!, 3)
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -275,9 +275,9 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT f()")!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT f(1)")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT f(1, 1)")!, 2)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -308,7 +308,7 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode.rawValue, 123)
|
||||
@@ -325,7 +325,7 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode.rawValue, 123)
|
||||
@@ -342,7 +342,7 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "SELECT f()")
|
||||
try db.execute(sql: "SELECT f()")
|
||||
XCTFail("Expected DatabaseError")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -364,7 +364,7 @@ class DatabaseFunctionTests: GRDBTestCase {
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
x = 321
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT f()")!, 321)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT f()")!, 321)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ class DatabaseLogErrorTests: GRDBTestCase {
|
||||
func testErrorLog() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.inDatabase { db in
|
||||
_ = try? db.execute(rawSQL: "Abracadabra")
|
||||
_ = try? db.execute(sql: "Abracadabra")
|
||||
}
|
||||
XCTAssertEqual(lastResultCode!, ResultCode.SQLITE_ERROR)
|
||||
// Don't check for exact error message because it depends on SQLite version
|
||||
|
||||
@@ -14,14 +14,14 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPersons") { db in
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE persons (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT)
|
||||
""")
|
||||
}
|
||||
migrator.registerMigration("createPets") { db in
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE pets (
|
||||
id INTEGER PRIMARY KEY,
|
||||
masterID INTEGER NOT NULL
|
||||
@@ -38,7 +38,7 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
}
|
||||
|
||||
migrator.registerMigration("destroyPersons") { db in
|
||||
try db.execute(rawSQL: "DROP TABLE pets")
|
||||
try db.execute(sql: "DROP TABLE pets")
|
||||
}
|
||||
|
||||
try migrator.migrate(dbQueue)
|
||||
@@ -53,14 +53,14 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPersons") { db in
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE persons (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT)
|
||||
""")
|
||||
}
|
||||
migrator.registerMigration("createPets") { db in
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE pets (
|
||||
id INTEGER PRIMARY KEY,
|
||||
masterID INTEGER NOT NULL
|
||||
@@ -77,7 +77,7 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
}
|
||||
|
||||
migrator.registerMigration("destroyPersons") { db in
|
||||
try db.execute(rawSQL: "DROP TABLE pets")
|
||||
try db.execute(sql: "DROP TABLE pets")
|
||||
}
|
||||
|
||||
try migrator.migrate(dbPool)
|
||||
@@ -92,13 +92,13 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("a") { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE a (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE a (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
migrator.registerMigration("b") { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE b (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE b (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
migrator.registerMigration("c") { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE c (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE c (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
// one step
|
||||
@@ -137,15 +137,15 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
func testMigrationFailureTriggersRollback() throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPersons") { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try db.execute(rawSQL: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)")
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name) VALUES ('Arthur')")
|
||||
try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)")
|
||||
try db.execute(sql: "INSERT INTO persons (name) VALUES ('Arthur')")
|
||||
}
|
||||
migrator.registerMigration("foreignKeyError") { db in
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name) VALUES ('Barbara')")
|
||||
try db.execute(sql: "INSERT INTO persons (name) VALUES ('Barbara')")
|
||||
do {
|
||||
// triggers immediate foreign key error:
|
||||
try db.execute(rawSQL: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [123, "Bobby"])
|
||||
try db.execute(sql: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [123, "Bobby"])
|
||||
XCTFail("Expected error")
|
||||
} catch {
|
||||
throw error
|
||||
@@ -169,7 +169,7 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
XCTAssertEqual(error.description.lowercased(), "sqlite error 19 with statement `insert into pets (masterid, name) values (?, ?)` arguments [123, \"bobby\"]: foreign key constraint failed")
|
||||
|
||||
let names = try dbQueue.inDatabase { db in
|
||||
try String.fetchAll(db, rawSQL: "SELECT name FROM persons")
|
||||
try String.fetchAll(db, sql: "SELECT name FROM persons")
|
||||
}
|
||||
XCTAssertEqual(names, ["Arthur"])
|
||||
}
|
||||
@@ -183,25 +183,25 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
#endif
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPersons") { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, tmp TEXT)")
|
||||
try db.execute(rawSQL: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)")
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name) VALUES ('Arthur')")
|
||||
try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, tmp TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE pets (masterId INTEGER NOT NULL REFERENCES persons(id), name TEXT)")
|
||||
try db.execute(sql: "INSERT INTO persons (name) VALUES ('Arthur')")
|
||||
let personId = db.lastInsertedRowID
|
||||
try db.execute(rawSQL: "INSERT INTO pets (masterId, name) VALUES (?, 'Bobby')", arguments:[personId])
|
||||
try db.execute(sql: "INSERT INTO pets (masterId, name) VALUES (?, 'Bobby')", arguments:[personId])
|
||||
}
|
||||
migrator.registerMigrationWithDeferredForeignKeyCheck("removePersonTmpColumn") { db in
|
||||
// Test the technique described at https://www.sqlite.org/lang_altertable.html#otheralter
|
||||
try db.execute(rawSQL: "CREATE TABLE new_persons (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try db.execute(rawSQL: "INSERT INTO new_persons SELECT id, name FROM persons")
|
||||
try db.execute(rawSQL: "DROP TABLE persons")
|
||||
try db.execute(rawSQL: "ALTER TABLE new_persons RENAME TO persons")
|
||||
try db.execute(sql: "CREATE TABLE new_persons (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try db.execute(sql: "INSERT INTO new_persons SELECT id, name FROM persons")
|
||||
try db.execute(sql: "DROP TABLE persons")
|
||||
try db.execute(sql: "ALTER TABLE new_persons RENAME TO persons")
|
||||
}
|
||||
migrator.registerMigrationWithDeferredForeignKeyCheck("foreignKeyError") { db in
|
||||
// Make sure foreign keys are checked at the end.
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name) VALUES ('Barbara')")
|
||||
try db.execute(sql: "INSERT INTO persons (name) VALUES ('Barbara')")
|
||||
do {
|
||||
// triggers foreign key error, but not now.
|
||||
try db.execute(rawSQL: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [123, "Bobby"])
|
||||
try db.execute(sql: "INSERT INTO pets (masterId, name) VALUES (?, ?)", arguments: [123, "Bobby"])
|
||||
} catch {
|
||||
XCTFail("Error not expected at this point")
|
||||
}
|
||||
@@ -222,7 +222,7 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
// Arthur inserted (migration 1), Barbara (migration 3) not inserted.
|
||||
var rows = try Row.fetchAll(db, rawSQL: "SELECT * FROM persons")
|
||||
var rows = try Row.fetchAll(db, sql: "SELECT * FROM persons")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
var row = rows.first!
|
||||
XCTAssertEqual(row["name"] as String, "Arthur")
|
||||
@@ -231,7 +231,7 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
XCTAssertEqual(Array(row.columnNames), ["id", "name"])
|
||||
|
||||
// Bobby inserted (migration 1), not deleted by migration 2.
|
||||
rows = try Row.fetchAll(db, rawSQL: "SELECT * FROM pets")
|
||||
rows = try Row.fetchAll(db, sql: "SELECT * FROM pets")
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
row = rows.first!
|
||||
XCTAssertEqual(row["name"] as String, "Bobby")
|
||||
@@ -259,7 +259,7 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
}
|
||||
}
|
||||
migrator2.registerMigration("2") { db in
|
||||
try db.execute(rawSQL: "INSERT INTO player (id, name, score) VALUES (NULL, 'Arthur', 1000)")
|
||||
try db.execute(sql: "INSERT INTO player (id, name, score) VALUES (NULL, 'Arthur', 1000)")
|
||||
}
|
||||
|
||||
// Apply 1st migrator
|
||||
@@ -288,7 +288,7 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
|
||||
var witness = 1
|
||||
migrator.registerMigration("1") { db in
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE t1(id INTEGER PRIMARY KEY);
|
||||
INSERT INTO t1(id) VALUES (?)
|
||||
""", arguments: [witness])
|
||||
@@ -299,16 +299,16 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
|
||||
// 1st migration
|
||||
try migrator.migrate(dbQueue)
|
||||
try XCTAssertEqual(dbQueue.read { try Int.fetchOne($0, rawSQL: "SELECT id FROM t1") }, 1)
|
||||
try XCTAssertEqual(dbQueue.read { try Int.fetchOne($0, sql: "SELECT id FROM t1") }, 1)
|
||||
|
||||
// 2nd migration does not erase database
|
||||
migrator.registerMigration("2") { db in
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE t2(id INTEGER PRIMARY KEY);
|
||||
""")
|
||||
}
|
||||
try migrator.migrate(dbQueue)
|
||||
try XCTAssertEqual(dbQueue.read { try Int.fetchOne($0, rawSQL: "SELECT id FROM t1") }, 1)
|
||||
try XCTAssertEqual(dbQueue.read { try Int.fetchOne($0, sql: "SELECT id FROM t1") }, 1)
|
||||
try XCTAssertTrue(dbQueue.read { try $0.tableExists("t2") })
|
||||
}
|
||||
}
|
||||
@@ -14,19 +14,19 @@ class DatabasePoolBackupTests: GRDBTestCase {
|
||||
let destination = try makeDatabasePool(filename: "destination.sqlite")
|
||||
|
||||
try source.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 1)
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1)
|
||||
}
|
||||
|
||||
try source.backup(to: destination)
|
||||
|
||||
try destination.read { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1)
|
||||
}
|
||||
|
||||
try source.write { db in
|
||||
try db.execute(rawSQL: "DROP TABLE items")
|
||||
try db.execute(sql: "DROP TABLE items")
|
||||
}
|
||||
|
||||
try source.backup(to: destination)
|
||||
@@ -43,9 +43,9 @@ class DatabasePoolBackupTests: GRDBTestCase {
|
||||
// let destination = try makeDatabasePool(filename: "destination.sqlite")
|
||||
//
|
||||
// try source.write { db in
|
||||
// try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
// try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
// XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 1)
|
||||
// try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
// try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
// XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1)
|
||||
// }
|
||||
//
|
||||
// let s1 = DispatchSemaphore(value: 0)
|
||||
@@ -53,7 +53,7 @@ class DatabasePoolBackupTests: GRDBTestCase {
|
||||
// DispatchQueue.global().async {
|
||||
// _ = s1.wait(timeout: .distantFuture)
|
||||
// try! source.writeInTransaction(.immediate) { db in
|
||||
// try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
// try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
// s2.signal()
|
||||
// return .commit
|
||||
// }
|
||||
@@ -67,18 +67,18 @@ class DatabasePoolBackupTests: GRDBTestCase {
|
||||
// },
|
||||
// afterBackupStep: {
|
||||
// try! source.write { db in
|
||||
// try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
// try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// try source.read { db in
|
||||
// XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 3)
|
||||
// XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 3)
|
||||
// }
|
||||
// try destination.read { db in
|
||||
// // TODO: understand why the fix for https://github.com/groue/GRDB.swift/issues/102
|
||||
// // had this value change from 2 to 1.
|
||||
// // TODO: Worse, this test is fragile. I've seen not 1 but 2 once.
|
||||
// XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 1)
|
||||
// XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -18,14 +18,14 @@ class DatabasePoolCollationTests: GRDBTestCase {
|
||||
dbPool.add(collation: collation1)
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (text TEXT COLLATE collation1)")
|
||||
try db.execute(rawSQL: "INSERT INTO items (text) VALUES ('a')")
|
||||
try db.execute(rawSQL: "INSERT INTO items (text) VALUES ('b')")
|
||||
try db.execute(rawSQL: "INSERT INTO items (text) VALUES ('c')")
|
||||
try db.execute(sql: "CREATE TABLE items (text TEXT COLLATE collation1)")
|
||||
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')")
|
||||
}
|
||||
try dbPool.read { db in
|
||||
XCTAssertEqual(try String.fetchAll(db, rawSQL: "SELECT text FROM items ORDER BY text"), ["a", "b", "c"])
|
||||
XCTAssertEqual(try String.fetchAll(db, rawSQL: "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"), ["a", "b", "c"])
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1"), ["a", "b", "c"])
|
||||
}
|
||||
|
||||
let collation2 = DatabaseCollation("collation2") { (string1, string2) in
|
||||
@@ -34,7 +34,7 @@ class DatabasePoolCollationTests: GRDBTestCase {
|
||||
dbPool.add(collation: collation2)
|
||||
|
||||
try dbPool.read { db in
|
||||
XCTAssertEqual(try String.fetchAll(db, rawSQL: "SELECT text FROM items ORDER BY text COLLATE collation2"), ["c", "b", "a"])
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation2"), ["c", "b", "a"])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,10 +33,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
do {
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.writeWithoutTransaction { db in
|
||||
let journalMode = try String.fetchOne(db, rawSQL: "PRAGMA journal_mode = wal")
|
||||
let journalMode = try String.fetchOne(db, sql: "PRAGMA journal_mode = wal")
|
||||
XCTAssertEqual(journalMode, "wal")
|
||||
try db.create(table: "moves") { $0.column("value", .integer) }
|
||||
try db.execute(rawSQL: "INSERT INTO moves VALUES (0)")
|
||||
try db.execute(sql: "INSERT INTO moves VALUES (0)")
|
||||
}
|
||||
}
|
||||
let s0 = DispatchSemaphore(value: 0)
|
||||
@@ -44,14 +44,14 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
let dbQueue = try! self.makeDatabaseQueue(filename: "test.sqlite")
|
||||
s0.signal() // Avoid "database is locked" error: don't open the two databases at the same time
|
||||
try! dbQueue.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "BEGIN DEFERRED TRANSACTION")
|
||||
try db.execute(sql: "BEGIN DEFERRED TRANSACTION")
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT SUM(value) AS balance FROM moves"), 1) // Non-zero balance
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT SUM(value) AS balance FROM moves"), 1) // Non-zero balance
|
||||
s3.signal()
|
||||
_ = s4.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT SUM(value) AS balance FROM moves"), 1) // Non-zero balance
|
||||
try db.execute(rawSQL: "END")
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT SUM(value) AS balance FROM moves"), 1) // Non-zero balance
|
||||
try db.execute(sql: "END")
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
@@ -59,10 +59,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
let dbQueue = try! self.makeDatabaseQueue(filename: "test.sqlite")
|
||||
try! dbQueue.writeWithoutTransaction { db in
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "INSERT INTO moves VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO moves VALUES (1)")
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "INSERT INTO moves VALUES (-1)")
|
||||
try db.execute(sql: "INSERT INTO moves VALUES (-1)")
|
||||
s4.signal()
|
||||
}
|
||||
}
|
||||
@@ -95,10 +95,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
do {
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.writeWithoutTransaction { db in
|
||||
let journalMode = try String.fetchOne(db, rawSQL: "PRAGMA journal_mode = wal")
|
||||
let journalMode = try String.fetchOne(db, sql: "PRAGMA journal_mode = wal")
|
||||
XCTAssertEqual(journalMode, "wal")
|
||||
try db.create(table: "moves") { $0.column("value", .integer) }
|
||||
try db.execute(rawSQL: "INSERT INTO moves VALUES (0)")
|
||||
try db.execute(sql: "INSERT INTO moves VALUES (0)")
|
||||
}
|
||||
}
|
||||
let s0 = DispatchSemaphore(value: 0)
|
||||
@@ -107,29 +107,29 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
s0.signal() // Avoid "database is locked" error: don't open the two databases at the same time
|
||||
try! dbQueue.writeWithoutTransaction { db in
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "BEGIN DEFERRED TRANSACTION")
|
||||
try db.execute(sql: "BEGIN DEFERRED TRANSACTION")
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance
|
||||
s4.signal()
|
||||
_ = s5.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance
|
||||
try db.execute(rawSQL: "END")
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance
|
||||
try db.execute(sql: "END")
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
_ = s0.wait(timeout: .distantFuture) // Avoid "database is locked" error: don't open the two databases at the same time
|
||||
let dbQueue = try! self.makeDatabaseQueue(filename: "test.sqlite")
|
||||
try! dbQueue.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "BEGIN DEFERRED TRANSACTION")
|
||||
try db.execute(sql: "BEGIN DEFERRED TRANSACTION")
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "INSERT INTO moves VALUES (1)")
|
||||
try db.execute(sql: "INSERT INTO moves VALUES (1)")
|
||||
s3.signal()
|
||||
_ = s4.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "INSERT INTO moves VALUES (-1)")
|
||||
try db.execute(sql: "INSERT INTO moves VALUES (-1)")
|
||||
s5.signal()
|
||||
try db.execute(rawSQL: "END")
|
||||
try db.execute(sql: "END")
|
||||
}
|
||||
}
|
||||
let blocks = [block1, block2]
|
||||
@@ -160,10 +160,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
do {
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.writeWithoutTransaction { db in
|
||||
let journalMode = try String.fetchOne(db, rawSQL: "PRAGMA journal_mode = wal")
|
||||
let journalMode = try String.fetchOne(db, sql: "PRAGMA journal_mode = wal")
|
||||
XCTAssertEqual(journalMode, "wal")
|
||||
try db.create(table: "moves") { $0.column("value", .integer) }
|
||||
try db.execute(rawSQL: "INSERT INTO moves VALUES (0)")
|
||||
try db.execute(sql: "INSERT INTO moves VALUES (0)")
|
||||
}
|
||||
}
|
||||
let s0 = DispatchSemaphore(value: 0)
|
||||
@@ -171,14 +171,14 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
let dbQueue = try! self.makeDatabaseQueue(filename: "test.sqlite")
|
||||
s0.signal() // Avoid "database is locked" error: don't open the two databases at the same time
|
||||
try! dbQueue.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "BEGIN DEFERRED TRANSACTION")
|
||||
try db.execute(sql: "BEGIN DEFERRED TRANSACTION")
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance
|
||||
s3.signal()
|
||||
_ = s4.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance
|
||||
try db.execute(rawSQL: "END")
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT SUM(value) AS balance FROM moves"), 0) // Zero balance
|
||||
try db.execute(sql: "END")
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
@@ -186,13 +186,13 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
let dbQueue = try! self.makeDatabaseQueue(filename: "test.sqlite")
|
||||
try! dbQueue.writeWithoutTransaction { db in
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "BEGIN DEFERRED TRANSACTION")
|
||||
try db.execute(rawSQL: "INSERT INTO moves VALUES (1)")
|
||||
try db.execute(sql: "BEGIN DEFERRED TRANSACTION")
|
||||
try db.execute(sql: "INSERT INTO moves VALUES (1)")
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "INSERT INTO moves VALUES (-1)")
|
||||
try db.execute(sql: "INSERT INTO moves VALUES (-1)")
|
||||
s4.signal()
|
||||
try db.execute(rawSQL: "END")
|
||||
try db.execute(sql: "END")
|
||||
}
|
||||
}
|
||||
let blocks = [block1, block2]
|
||||
@@ -204,11 +204,11 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
func testWrappedReadWrite() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
let id = try dbPool.read { db in
|
||||
try Int.fetchOne(db, rawSQL: "SELECT id FROM items")!
|
||||
try Int.fetchOne(db, sql: "SELECT id FROM items")!
|
||||
}
|
||||
XCTAssertEqual(id, 1)
|
||||
}
|
||||
@@ -217,14 +217,14 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
do {
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
}
|
||||
do {
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite")
|
||||
let id = try dbPool.read { db in
|
||||
try Int.fetchOne(db, rawSQL: "SELECT id FROM items")!
|
||||
try Int.fetchOne(db, sql: "SELECT id FROM items")!
|
||||
}
|
||||
XCTAssertEqual(id, 1)
|
||||
}
|
||||
@@ -235,7 +235,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
try dbPool.write { db in
|
||||
XCTAssertTrue(db.isInsideTransaction)
|
||||
do {
|
||||
try db.execute(rawSQL: "BEGIN DEFERRED TRANSACTION")
|
||||
try db.execute(sql: "BEGIN DEFERRED TRANSACTION")
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -260,7 +260,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
try dbPool.read { db in
|
||||
XCTAssertTrue(db.isInsideTransaction)
|
||||
do {
|
||||
try db.execute(rawSQL: "BEGIN DEFERRED TRANSACTION")
|
||||
try db.execute(sql: "BEGIN DEFERRED TRANSACTION")
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.resultCode, .SQLITE_ERROR)
|
||||
@@ -283,8 +283,8 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
|
||||
let block1 = { () in
|
||||
try! dbPool.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "PRAGMA locking_mode=EXCLUSIVE")
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "PRAGMA locking_mode=EXCLUSIVE")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
s1.signal()
|
||||
}
|
||||
}
|
||||
@@ -311,9 +311,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
func testConcurrentRead() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
for _ in 0..<3 {
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
|
||||
let block1 = { () in
|
||||
try! dbPool.read { db in
|
||||
let cursor = try Row.fetchCursor(db, rawSQL: "SELECT * FROM items")
|
||||
let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items")
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
@@ -344,7 +344,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
}
|
||||
let block2 = { () in
|
||||
try! dbPool.read { db in
|
||||
let cursor = try Row.fetchCursor(db, rawSQL: "SELECT * FROM items")
|
||||
let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items")
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
@@ -362,9 +362,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
func testReadMethodIsolationOfStatement() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
for _ in 0..<2 {
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
|
||||
let block1 = { () in
|
||||
try! dbPool.read { db in
|
||||
let cursor = try Row.fetchCursor(db, rawSQL: "SELECT * FROM items")
|
||||
let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items")
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
@@ -396,7 +396,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
defer { s2.signal() }
|
||||
try dbPool.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "DELETE FROM items")
|
||||
try db.execute(sql: "DELETE FROM items")
|
||||
}
|
||||
} catch {
|
||||
XCTFail("error: \(error)")
|
||||
@@ -411,9 +411,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
func testReadMethodIsolationOfStatementWithCheckpoint() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
for _ in 0..<2 {
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
|
||||
let block1 = { () in
|
||||
try! dbPool.read { db in
|
||||
let cursor = try Row.fetchCursor(db, rawSQL: "SELECT * FROM items")
|
||||
let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items")
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
@@ -446,7 +446,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
defer { s2.signal() }
|
||||
try dbPool.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "DELETE FROM items")
|
||||
try db.execute(sql: "DELETE FROM items")
|
||||
}
|
||||
try dbPool.checkpoint()
|
||||
} catch {
|
||||
@@ -462,7 +462,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
func testReadBlockIsolationStartingWithRead() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
// Block 1 Block 2
|
||||
@@ -485,20 +485,20 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
try! dbPool.read { db in
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 1) // Not a bug. The writer did not start a transaction.
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1) // Not a bug. The writer did not start a transaction.
|
||||
s3.signal()
|
||||
_ = s4.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1)
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
do {
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try dbPool.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
s4.signal()
|
||||
}
|
||||
} catch {
|
||||
@@ -514,7 +514,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
func testReadBlockIsolationStartingWithSelect() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
// Block 1 Block 2
|
||||
@@ -531,10 +531,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
|
||||
let block1 = { () in
|
||||
try! dbPool.read { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0)
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
@@ -542,7 +542,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
defer { s2.signal() }
|
||||
try dbPool.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
try dbPool.checkpoint()
|
||||
} catch {
|
||||
@@ -558,7 +558,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
func testReadBlockIsolationStartingWithWrite() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
// Block 1 Block 2
|
||||
@@ -583,10 +583,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
let block1 = { () in
|
||||
do {
|
||||
try dbPool.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
s3.signal()
|
||||
_ = s4.wait(timeout: .distantFuture)
|
||||
}
|
||||
@@ -598,13 +598,13 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
let block2 = { () in
|
||||
try! dbPool.read { db in
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1)
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1)
|
||||
s4.signal()
|
||||
_ = s5.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1)
|
||||
}
|
||||
}
|
||||
let blocks = [block1, block2]
|
||||
@@ -616,7 +616,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
func testReadBlockIsolationStartingWithWriteTransaction() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
// Block 1 Block 2
|
||||
@@ -643,10 +643,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
let block1 = { () in
|
||||
do {
|
||||
try dbPool.writeInTransaction(.immediate) { db in
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
s3.signal()
|
||||
_ = s4.wait(timeout: .distantFuture)
|
||||
return .commit
|
||||
@@ -659,13 +659,13 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
let block2 = { () in
|
||||
try! dbPool.read { db in
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0)
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0)
|
||||
s4.signal()
|
||||
_ = s5.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0)
|
||||
}
|
||||
}
|
||||
let blocks = [block1, block2]
|
||||
@@ -677,9 +677,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
func testUnsafeReadMethodIsolationOfStatement() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
for _ in 0..<2 {
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -699,13 +699,13 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
|
||||
let block1 = { () in
|
||||
try! dbPool.unsafeRead { db in
|
||||
let cursor = try Row.fetchCursor(db, rawSQL: "SELECT * FROM items")
|
||||
let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items")
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
XCTAssertTrue(try cursor.next() == nil)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0)
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
@@ -713,7 +713,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
defer { s2.signal() }
|
||||
try dbPool.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "DELETE FROM items")
|
||||
try db.execute(sql: "DELETE FROM items")
|
||||
}
|
||||
} catch {
|
||||
XCTFail("error: \(error)")
|
||||
@@ -728,9 +728,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
func testUnsafeReadMethodIsolationOfStatementWithCheckpoint() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
for _ in 0..<2 {
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -750,7 +750,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
|
||||
let block1 = { () in
|
||||
try! dbPool.unsafeRead { db in
|
||||
let cursor = try Row.fetchCursor(db, rawSQL: "SELECT * FROM items")
|
||||
let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items")
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
@@ -763,7 +763,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
defer { s2.signal() }
|
||||
try dbPool.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "DELETE FROM items")
|
||||
try db.execute(sql: "DELETE FROM items")
|
||||
}
|
||||
try dbPool.checkpoint()
|
||||
} catch {
|
||||
@@ -779,7 +779,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
func testUnsafeReadMethodIsolationOfBlock() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
// Block 1 Block 2
|
||||
@@ -796,10 +796,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
|
||||
let block1 = { () in
|
||||
try! dbPool.unsafeRead { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 0)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1)
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
@@ -807,7 +807,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
defer { s2.signal() }
|
||||
try dbPool.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
try dbPool.checkpoint()
|
||||
} catch {
|
||||
@@ -826,7 +826,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
dbPool.concurrentRead { db in
|
||||
XCTAssertTrue(db.isInsideTransaction)
|
||||
do {
|
||||
try db.execute(rawSQL: "BEGIN DEFERRED TRANSACTION")
|
||||
try db.execute(sql: "BEGIN DEFERRED TRANSACTION")
|
||||
XCTFail("Expected error")
|
||||
} catch {
|
||||
}
|
||||
@@ -858,9 +858,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
let future: Future<Int> = try dbPool.writeWithoutTransaction { db in
|
||||
let future: Future<Int> = dbPool.concurrentRead { db in
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
return try! Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM persons")!
|
||||
return try! Int.fetchOne(db, sql: "SELECT COUNT(*) FROM persons")!
|
||||
}
|
||||
try db.execute(rawSQL: "INSERT INTO persons DEFAULT VALUES")
|
||||
try db.execute(sql: "INSERT INTO persons DEFAULT VALUES")
|
||||
s1.signal()
|
||||
return future
|
||||
}
|
||||
@@ -870,8 +870,8 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
func testConcurrentReadError() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "PRAGMA locking_mode=EXCLUSIVE")
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "PRAGMA locking_mode=EXCLUSIVE")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
let future = dbPool.concurrentRead { db in
|
||||
fatalError("Should not run")
|
||||
}
|
||||
@@ -896,7 +896,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.create(table: "t") { $0.column("id", .integer).primaryKey() }
|
||||
try db.execute(rawSQL: "INSERT INTO t DEFAULT VALUES")
|
||||
try db.execute(sql: "INSERT INTO t DEFAULT VALUES")
|
||||
}
|
||||
|
||||
try dbQueue.writeWithoutTransaction { db in
|
||||
@@ -904,17 +904,17 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
try dbQueue.writeWithoutTransaction { db in
|
||||
try XCTAssertEqual(Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM t")!, 1)
|
||||
try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 1)
|
||||
}
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t DEFAULT VALUES")
|
||||
try db.execute(sql: "INSERT INTO t DEFAULT VALUES")
|
||||
}
|
||||
|
||||
try dbQueue.writeWithoutTransaction { db in
|
||||
try XCTAssertEqual(Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM t")!, 1)
|
||||
try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 1)
|
||||
try db.rollback()
|
||||
try XCTAssertEqual(Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM t")!, 2)
|
||||
try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -932,10 +932,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE VIRTUAL TABLE search USING fts3(title)")
|
||||
try db.execute(sql: "CREATE VIRTUAL TABLE search USING fts3(title)")
|
||||
}
|
||||
try dbPool.read { db in
|
||||
_ = try Row.fetchAll(db, rawSQL: "SELECT * FROM search")
|
||||
_ = try Row.fetchAll(db, sql: "SELECT * FROM search")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ class DatabasePoolFunctionTests: GRDBTestCase {
|
||||
dbPool.add(function: function1)
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (text TEXT)")
|
||||
try db.execute(rawSQL: "INSERT INTO items (text) VALUES (function1('a'))")
|
||||
try db.execute(sql: "CREATE TABLE items (text TEXT)")
|
||||
try db.execute(sql: "INSERT INTO items (text) VALUES (function1('a'))")
|
||||
}
|
||||
try dbPool.read { db in
|
||||
XCTAssertEqual(try String.fetchOne(db, rawSQL: "SELECT function1(text) FROM items")!, "a")
|
||||
XCTAssertEqual(try String.fetchOne(db, sql: "SELECT function1(text) FROM items")!, "a")
|
||||
}
|
||||
|
||||
let function2 = DatabaseFunction("function2", argumentCount: 1, pure: true) { (dbValues: [DatabaseValue]) in
|
||||
@@ -32,7 +32,7 @@ class DatabasePoolFunctionTests: GRDBTestCase {
|
||||
dbPool.add(function: function2)
|
||||
|
||||
try dbPool.read { db in
|
||||
XCTAssertTrue(try String.fetchOne(db, rawSQL: "SELECT function2(text) FROM items") == "foo")
|
||||
XCTAssertTrue(try String.fetchOne(db, sql: "SELECT function2(text) FROM items") == "foo")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,9 @@ class DatabasePoolReadOnlyTests: GRDBTestCase {
|
||||
do {
|
||||
let dbQueue = try makeDatabaseQueue(filename: databaseFileName)
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
for _ in 0..<3 {
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class DatabasePoolReadOnlyTests: GRDBTestCase {
|
||||
|
||||
// Make sure the database is not in WAL mode
|
||||
let mode = try dbPool.read { db in
|
||||
try String.fetchOne(db, rawSQL: "PRAGMA journal_mode")!
|
||||
try String.fetchOne(db, sql: "PRAGMA journal_mode")!
|
||||
}
|
||||
XCTAssertNotEqual(mode.lowercased(), "wal")
|
||||
|
||||
@@ -47,7 +47,7 @@ class DatabasePoolReadOnlyTests: GRDBTestCase {
|
||||
|
||||
let block1 = { () in
|
||||
try! dbPool.read { db in
|
||||
let cursor = try Row.fetchCursor(db, rawSQL: "SELECT * FROM items")
|
||||
let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items")
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
@@ -58,7 +58,7 @@ class DatabasePoolReadOnlyTests: GRDBTestCase {
|
||||
}
|
||||
let block2 = { () in
|
||||
try! dbPool.read { db in
|
||||
let cursor = try Row.fetchCursor(db, rawSQL: "SELECT * FROM items")
|
||||
let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items")
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
|
||||
@@ -34,7 +34,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
let dbPool = try makeDatabasePool()
|
||||
// Writer connection
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
// Reader connection
|
||||
try dbPool.read { _ in }
|
||||
@@ -67,9 +67,9 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
for _ in 0..<2 {
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
|
||||
let block1 = { () in
|
||||
try! dbPool.read { db in
|
||||
let cursor = try Row.fetchCursor(db, rawSQL: "SELECT * FROM items")
|
||||
let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items")
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
@@ -101,7 +101,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
let block2 = { () in
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try! dbPool.read { db in
|
||||
let cursor = try Row.fetchCursor(db, rawSQL: "SELECT * FROM items")
|
||||
let cursor = try Row.fetchCursor(db, sql: "SELECT * FROM items")
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
s2.signal()
|
||||
XCTAssertTrue(try cursor.next() != nil)
|
||||
@@ -155,7 +155,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
let (block1, block2) = { () -> (() -> (), () -> ()) in
|
||||
var dbPool: DatabasePool? = try! self.makeDatabasePool()
|
||||
try! dbPool!.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
let block1 = { () in
|
||||
@@ -168,7 +168,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
try! dbPool.read { db in
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items"), 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items"), 0)
|
||||
}
|
||||
} else {
|
||||
XCTFail("expect non nil dbPool")
|
||||
|
||||
@@ -13,8 +13,8 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY, email TEXT UNIQUE, foo INT, bar DOUBLE)")
|
||||
try db.execute(rawSQL: "CREATE INDEX foobar ON items(foo, bar)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY, email TEXT UNIQUE, foo INT, bar DOUBLE)")
|
||||
try db.execute(sql: "CREATE INDEX foobar ON items(foo, bar)")
|
||||
}
|
||||
|
||||
try dbPool.write { db in
|
||||
@@ -57,7 +57,7 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase {
|
||||
|
||||
try dbPool.write { db in
|
||||
// Empty cache after schema change
|
||||
try db.execute(rawSQL: "DROP TABLE items")
|
||||
try db.execute(sql: "DROP TABLE items")
|
||||
|
||||
// Assert that the writer cache is empty
|
||||
XCTAssertTrue(db.schemaCache.primaryKey("items") == nil)
|
||||
@@ -94,8 +94,8 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase {
|
||||
// correct thread.
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (1)")
|
||||
}
|
||||
|
||||
// Block 1 Block 2
|
||||
@@ -148,14 +148,14 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase {
|
||||
|
||||
let block1 = { () in
|
||||
try! dbPool.writeWithoutTransaction { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE foo(id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE foo(id INTEGER PRIMARY KEY)")
|
||||
// warm cache
|
||||
_ = try db.primaryKey("foo")
|
||||
// cache contains the primary key
|
||||
XCTAssertNotNil(db.schemaCache.primaryKey("foo"))
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "DROP TABLE foo")
|
||||
try db.execute(sql: "DROP TABLE foo")
|
||||
// cache does not contain the primary key
|
||||
XCTAssertNil(db.schemaCache.primaryKey("foo"))
|
||||
s3.signal()
|
||||
@@ -192,8 +192,8 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY, email TEXT UNIQUE, foo INT, bar DOUBLE)")
|
||||
try db.execute(rawSQL: "CREATE INDEX foobar ON items(foo, bar)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY, email TEXT UNIQUE, foo INT, bar DOUBLE)")
|
||||
try db.execute(sql: "CREATE INDEX foobar ON items(foo, bar)")
|
||||
}
|
||||
|
||||
try dbPool.unsafeRead { db in
|
||||
|
||||
@@ -14,19 +14,19 @@ class DatabaseQueueBackupTests: GRDBTestCase {
|
||||
let destination = try makeDatabaseQueue(filename: "destination.sqlite")
|
||||
|
||||
try source.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 1)
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1)
|
||||
}
|
||||
|
||||
try source.backup(to: destination)
|
||||
|
||||
try destination.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")!, 1)
|
||||
}
|
||||
|
||||
try source.inDatabase { db in
|
||||
try db.execute(rawSQL: "DROP TABLE items")
|
||||
try db.execute(sql: "DROP TABLE items")
|
||||
}
|
||||
|
||||
try source.backup(to: destination)
|
||||
|
||||
@@ -29,11 +29,11 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
func testWrappedReadWrite() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(rawSQL: "INSERT INTO items (id) VALUES (NULL)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
let id = try dbQueue.inDatabase { db in
|
||||
try Int.fetchOne(db, rawSQL: "SELECT id FROM items")!
|
||||
try Int.fetchOne(db, sql: "SELECT id FROM items")!
|
||||
}
|
||||
XCTAssertEqual(id, 1)
|
||||
}
|
||||
@@ -45,7 +45,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
// same empty database: make sure the database is not empty before
|
||||
// running this test
|
||||
try dbQueue1.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
try db.execute(sql: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
}
|
||||
#endif
|
||||
let dbQueue2 = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
@@ -63,7 +63,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
// COMMIT
|
||||
|
||||
try dbQueue1.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
@@ -75,7 +75,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
try dbQueue1.inTransaction(.deferred) { db in
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "INSERT INTO stuffs (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO stuffs (id) VALUES (NULL)")
|
||||
s3.signal()
|
||||
_ = s4.wait(timeout: .distantFuture)
|
||||
return .commit
|
||||
@@ -94,7 +94,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
try dbQueue2.inTransaction(.deferred) { db in
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
try db.execute(rawSQL: "INSERT INTO stuffs (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO stuffs (id) VALUES (NULL)")
|
||||
return .commit
|
||||
}
|
||||
}
|
||||
@@ -236,7 +236,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
// same empty database: make sure the database is not empty before
|
||||
// running this test
|
||||
try dbQueue1.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
try db.execute(sql: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
}
|
||||
#endif
|
||||
let dbQueue2 = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
@@ -299,7 +299,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
// same empty database: make sure the database is not empty before
|
||||
// running this test
|
||||
try dbQueue1.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
try db.execute(sql: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
}
|
||||
#endif
|
||||
let dbQueue2 = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
@@ -317,7 +317,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
// SELECT * FROM stuffs <--- 1 result
|
||||
|
||||
try dbQueue1.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
@@ -327,7 +327,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
try dbQueue1.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO stuffs (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO stuffs (id) VALUES (NULL)")
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
return .commit
|
||||
@@ -345,10 +345,10 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
queue.async(group: group) {
|
||||
try! dbQueue2.writeWithoutTransaction { db in
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
rows1 = try Row.fetchAll(db, rawSQL: "SELECT * FROM stuffs")
|
||||
rows1 = try Row.fetchAll(db, sql: "SELECT * FROM stuffs")
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
rows2 = try Row.fetchAll(db, rawSQL: "SELECT * FROM stuffs")
|
||||
rows2 = try Row.fetchAll(db, sql: "SELECT * FROM stuffs")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
// same empty database: make sure the database is not empty before
|
||||
// running this test
|
||||
try dbQueue1.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
try db.execute(sql: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
|
||||
}
|
||||
#endif
|
||||
let dbQueue2 = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
@@ -398,7 +398,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
try dbQueue1.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
@@ -408,7 +408,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
try dbQueue1.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO stuffs (id) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO stuffs (id) VALUES (NULL)")
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
return .commit
|
||||
@@ -424,7 +424,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
do {
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try dbQueue2.inTransaction(.deferred) { db in
|
||||
_ = try Row.fetchAll(db, rawSQL: "SELECT * FROM stuffs")
|
||||
_ = try Row.fetchAll(db, sql: "SELECT * FROM stuffs")
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
return .commit
|
||||
|
||||
@@ -12,9 +12,9 @@ class DatabaseQueueInMemoryTests : GRDBTestCase
|
||||
func testInMemoryDatabase() throws {
|
||||
let dbQueue = DatabaseQueue()
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE foo (bar TEXT)")
|
||||
try db.execute(rawSQL: "INSERT INTO foo (bar) VALUES ('baz')")
|
||||
let baz = try String.fetchOne(db, rawSQL: "SELECT bar FROM foo")!
|
||||
try db.execute(sql: "CREATE TABLE foo (bar TEXT)")
|
||||
try db.execute(sql: "INSERT INTO foo (bar) VALUES ('baz')")
|
||||
let baz = try String.fetchOne(db, sql: "SELECT bar FROM foo")!
|
||||
XCTAssertEqual(baz, "baz")
|
||||
return .rollback
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class DatabaseQueueReleaseMemoryTests: GRDBTestCase {
|
||||
let (block1, block2) = { () -> (() -> (), () -> ()) in
|
||||
var dbQueue: DatabaseQueue? = try! self.makeDatabaseQueue()
|
||||
try! dbQueue!.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
let block1 = { () in
|
||||
@@ -83,7 +83,7 @@ class DatabaseQueueReleaseMemoryTests: GRDBTestCase {
|
||||
try! dbQueue.write { db in
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM items"), 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items"), 0)
|
||||
}
|
||||
} else {
|
||||
XCTFail("expect non nil dbQueue")
|
||||
|
||||
@@ -13,7 +13,7 @@ class DatabaseQueueSchemaCacheTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
dbQueue.inDatabase { db in
|
||||
@@ -32,7 +32,7 @@ class DatabaseQueueSchemaCacheTests : GRDBTestCase {
|
||||
|
||||
try dbQueue.inDatabase { db in
|
||||
// Empty cache after schema change
|
||||
try db.execute(rawSQL: "DROP TABLE items")
|
||||
try db.execute(sql: "DROP TABLE items")
|
||||
|
||||
// Assert that cache is empty
|
||||
XCTAssertTrue(db.schemaCache.primaryKey("items") == nil)
|
||||
|
||||
@@ -46,12 +46,12 @@ class DatabaseQueueTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(function: fn)
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT succ(1)"), 2) // 2
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT succ(1)"), 2) // 2
|
||||
}
|
||||
dbQueue.remove(function: fn)
|
||||
do {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "SELECT succ(1)")
|
||||
try db.execute(sql: "SELECT succ(1)")
|
||||
XCTFail("Expected Error")
|
||||
}
|
||||
XCTFail("Expected Error")
|
||||
@@ -73,12 +73,12 @@ class DatabaseQueueTests: GRDBTestCase {
|
||||
}
|
||||
dbQueue.add(collation: collation)
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE files (name TEXT COLLATE TEST_COLLATION_FOO)")
|
||||
try db.execute(sql: "CREATE TABLE files (name TEXT COLLATE TEST_COLLATION_FOO)")
|
||||
}
|
||||
dbQueue.remove(collation: collation)
|
||||
do {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE files_fail (name TEXT COLLATE TEST_COLLATION_FOO)")
|
||||
try db.execute(sql: "CREATE TABLE files_fail (name TEXT COLLATE TEST_COLLATION_FOO)")
|
||||
XCTFail("Expected Error")
|
||||
}
|
||||
XCTFail("Expected Error")
|
||||
|
||||
@@ -25,7 +25,7 @@ class DatabaseReaderTests : GRDBTestCase {
|
||||
}
|
||||
}
|
||||
do {
|
||||
try dbQueue.read { try $0.execute(rawSQL: "INSERT INTO table1 DEFAULT VALUES") }
|
||||
try dbQueue.read { try $0.execute(sql: "INSERT INTO table1 DEFAULT VALUES") }
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError where error.resultCode == .SQLITE_READONLY {
|
||||
}
|
||||
@@ -39,7 +39,7 @@ class DatabaseReaderTests : GRDBTestCase {
|
||||
}
|
||||
}
|
||||
do {
|
||||
try dbPool.read { try $0.execute(rawSQL: "INSERT INTO table1 DEFAULT VALUES") }
|
||||
try dbPool.read { try $0.execute(sql: "INSERT INTO table1 DEFAULT VALUES") }
|
||||
XCTFail()
|
||||
} catch let error as DatabaseError where error.resultCode == .SQLITE_READONLY {
|
||||
}
|
||||
|
||||
@@ -16,16 +16,16 @@ class DatabaseRegionObservationTests: GRDBTestCase {
|
||||
func testDatabaseRegionObservationVariadic() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.write {
|
||||
try $0.execute(rawSQL: "CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
||||
try $0.execute(rawSQL: "CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
||||
try $0.execute(sql: "CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
||||
try $0.execute(sql: "CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
||||
}
|
||||
|
||||
let notificationExpectation = expectation(description: "notification")
|
||||
notificationExpectation.assertForOverFulfill = true
|
||||
notificationExpectation.expectedFulfillmentCount = 3
|
||||
|
||||
let request1 = SQLRequest<Row>(rawSQL: "SELECT * FROM t1 ORDER BY id")
|
||||
let request2 = SQLRequest<Row>(rawSQL: "SELECT * FROM t2 ORDER BY id")
|
||||
let request1 = SQLRequest<Row>(sql: "SELECT * FROM t1 ORDER BY id")
|
||||
let request2 = SQLRequest<Row>(sql: "SELECT * FROM t2 ORDER BY id")
|
||||
|
||||
var observation = DatabaseRegionObservation(tracking: request1, request2)
|
||||
observation.extent = .databaseLifetime
|
||||
@@ -37,14 +37,14 @@ class DatabaseRegionObservationTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t1 (id, name) VALUES (1, 'foo')")
|
||||
try db.execute(sql: "INSERT INTO t1 (id, name) VALUES (1, 'foo')")
|
||||
}
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t2 (id, name) VALUES (1, 'foo')")
|
||||
try db.execute(sql: "INSERT INTO t2 (id, name) VALUES (1, 'foo')")
|
||||
}
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t1 (id, name) VALUES (2, 'foo')")
|
||||
try db.execute(rawSQL: "INSERT INTO t2 (id, name) VALUES (2, 'foo')")
|
||||
try db.execute(sql: "INSERT INTO t1 (id, name) VALUES (2, 'foo')")
|
||||
try db.execute(sql: "INSERT INTO t2 (id, name) VALUES (2, 'foo')")
|
||||
}
|
||||
waitForExpectations(timeout: 1, handler: nil)
|
||||
|
||||
@@ -54,16 +54,16 @@ class DatabaseRegionObservationTests: GRDBTestCase {
|
||||
func testDatabaseRegionObservationArray() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.write {
|
||||
try $0.execute(rawSQL: "CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
||||
try $0.execute(rawSQL: "CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
||||
try $0.execute(sql: "CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
||||
try $0.execute(sql: "CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
||||
}
|
||||
|
||||
let notificationExpectation = expectation(description: "notification")
|
||||
notificationExpectation.assertForOverFulfill = true
|
||||
notificationExpectation.expectedFulfillmentCount = 3
|
||||
|
||||
let request1 = SQLRequest<Row>(rawSQL: "SELECT * FROM t1 ORDER BY id")
|
||||
let request2 = SQLRequest<Row>(rawSQL: "SELECT * FROM t2 ORDER BY id")
|
||||
let request1 = SQLRequest<Row>(sql: "SELECT * FROM t1 ORDER BY id")
|
||||
let request2 = SQLRequest<Row>(sql: "SELECT * FROM t2 ORDER BY id")
|
||||
|
||||
var observation = DatabaseRegionObservation(tracking: [request1, request2])
|
||||
observation.extent = .databaseLifetime
|
||||
@@ -75,14 +75,14 @@ class DatabaseRegionObservationTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t1 (id, name) VALUES (1, 'foo')")
|
||||
try db.execute(sql: "INSERT INTO t1 (id, name) VALUES (1, 'foo')")
|
||||
}
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t2 (id, name) VALUES (1, 'foo')")
|
||||
try db.execute(sql: "INSERT INTO t2 (id, name) VALUES (1, 'foo')")
|
||||
}
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t1 (id, name) VALUES (2, 'foo')")
|
||||
try db.execute(rawSQL: "INSERT INTO t2 (id, name) VALUES (2, 'foo')")
|
||||
try db.execute(sql: "INSERT INTO t1 (id, name) VALUES (2, 'foo')")
|
||||
try db.execute(sql: "INSERT INTO t2 (id, name) VALUES (2, 'foo')")
|
||||
}
|
||||
waitForExpectations(timeout: 1, handler: nil)
|
||||
|
||||
@@ -91,13 +91,13 @@ class DatabaseRegionObservationTests: GRDBTestCase {
|
||||
|
||||
func testDatabaseRegionDefaultExtent() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.write { try $0.execute(rawSQL: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") }
|
||||
try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") }
|
||||
|
||||
let notificationExpectation = expectation(description: "notification")
|
||||
notificationExpectation.assertForOverFulfill = true
|
||||
notificationExpectation.expectedFulfillmentCount = 2
|
||||
|
||||
let observation = DatabaseRegionObservation(tracking: SQLRequest<Row>(rawSQL: "SELECT * FROM t ORDER BY id"))
|
||||
let observation = DatabaseRegionObservation(tracking: SQLRequest<Row>(sql: "SELECT * FROM t ORDER BY id"))
|
||||
|
||||
var count = 0
|
||||
do {
|
||||
@@ -108,16 +108,16 @@ class DatabaseRegionObservationTests: GRDBTestCase {
|
||||
|
||||
try withExtendedLifetime(observer) {
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t (id, name) VALUES (1, 'foo')")
|
||||
try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')")
|
||||
}
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t (id, name) VALUES (2, 'bar')")
|
||||
try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')")
|
||||
}
|
||||
}
|
||||
}
|
||||
// not notified
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t (id, name) VALUES (3, 'baz')")
|
||||
try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')")
|
||||
}
|
||||
waitForExpectations(timeout: 1, handler: nil)
|
||||
|
||||
@@ -126,13 +126,13 @@ class DatabaseRegionObservationTests: GRDBTestCase {
|
||||
|
||||
func testDatabaseRegionExtentNextTransaction() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.write { try $0.execute(rawSQL: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") }
|
||||
try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") }
|
||||
|
||||
let notificationExpectation = expectation(description: "notification")
|
||||
notificationExpectation.assertForOverFulfill = true
|
||||
notificationExpectation.expectedFulfillmentCount = 1
|
||||
|
||||
var observation = DatabaseRegionObservation(tracking: SQLRequest<Row>(rawSQL: "SELECT * FROM t ORDER BY id"))
|
||||
var observation = DatabaseRegionObservation(tracking: SQLRequest<Row>(sql: "SELECT * FROM t ORDER BY id"))
|
||||
observation.extent = .nextTransaction
|
||||
|
||||
var count = 0
|
||||
@@ -142,11 +142,11 @@ class DatabaseRegionObservationTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t (id, name) VALUES (1, 'foo')")
|
||||
try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')")
|
||||
}
|
||||
// not notified
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t (id, name) VALUES (2, 'bar')")
|
||||
try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')")
|
||||
}
|
||||
waitForExpectations(timeout: 1, handler: nil)
|
||||
|
||||
|
||||
@@ -258,8 +258,8 @@ class DatabaseRegionTests : GRDBTestCase {
|
||||
func testSelectStatement() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE foo (id INTEGER, name TEXT)")
|
||||
try db.execute(rawSQL: "CREATE TABLE bar (id INTEGER, fooId INTEGER)")
|
||||
try db.execute(sql: "CREATE TABLE foo (id INTEGER, name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE bar (id INTEGER, fooId INTEGER)")
|
||||
|
||||
do {
|
||||
let statement = try db.makeSelectStatement("SELECT foo.name FROM FOO JOIN BAR ON fooId = foo.id")
|
||||
@@ -286,7 +286,7 @@ class DatabaseRegionTests : GRDBTestCase {
|
||||
func testRegionRowIds() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE foo (id INTEGER PRIMARY KEY, a TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE foo (id INTEGER PRIMARY KEY, a TEXT)")
|
||||
struct Record: TableRecord {
|
||||
static let databaseTableName = "foo"
|
||||
}
|
||||
@@ -413,9 +413,9 @@ class DatabaseRegionTests : GRDBTestCase {
|
||||
func testDatabaseRegionOfJoinedRequests() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE a (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try db.execute(rawSQL: "CREATE TABLE b (id INTEGER PRIMARY KEY, name TEXT, aid INTEGER REFERENCES a(id))")
|
||||
try db.execute(rawSQL: "CREATE TABLE c (id INTEGER PRIMARY KEY, name TEXT, aid INTEGER REFERENCES a(id))")
|
||||
try db.execute(sql: "CREATE TABLE a (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE b (id INTEGER PRIMARY KEY, name TEXT, aid INTEGER REFERENCES a(id))")
|
||||
try db.execute(sql: "CREATE TABLE c (id INTEGER PRIMARY KEY, name TEXT, aid INTEGER REFERENCES a(id))")
|
||||
struct A: TableRecord {
|
||||
static let databaseTableName = "a"
|
||||
static let b = hasOne(B.self)
|
||||
@@ -448,7 +448,7 @@ class DatabaseRegionTests : GRDBTestCase {
|
||||
func testDatabaseRegionOfDerivedRequests() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE foo (id INTEGER PRIMARY KEY, a TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE foo (id INTEGER PRIMARY KEY, a TEXT)")
|
||||
struct Record: TableRecord {
|
||||
static let databaseTableName = "foo"
|
||||
}
|
||||
@@ -475,7 +475,7 @@ class DatabaseRegionTests : GRDBTestCase {
|
||||
func testUpdateStatement() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE foo (id INTEGER, bar TEXT, baz TEXT, qux TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE foo (id INTEGER, bar TEXT, baz TEXT, qux TEXT)")
|
||||
let statement = try db.makeUpdateStatement("UPDATE foo SET bar = 'bar', baz = 'baz' WHERE id = 1")
|
||||
XCTAssertFalse(statement.invalidatesDatabaseSchemaCache)
|
||||
XCTAssertEqual(statement.databaseEventKinds.count, 1)
|
||||
@@ -502,7 +502,7 @@ class DatabaseRegionTests : GRDBTestCase {
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE foo (name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE foo (name TEXT)")
|
||||
do {
|
||||
let statement = try db.makeSelectStatement("SELECT rowid FROM FOO")
|
||||
let expectedRegion = DatabaseRegion(table: "foo", columns: ["ROWID"])
|
||||
@@ -537,7 +537,7 @@ class DatabaseRegionTests : GRDBTestCase {
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE foo (name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE foo (name TEXT)")
|
||||
do {
|
||||
let statement = try db.makeUpdateStatement("UPDATE foo SET rowid = 1")
|
||||
XCTAssertEqual(statement.databaseEventKinds.count, 1)
|
||||
@@ -574,7 +574,7 @@ class DatabaseRegionTests : GRDBTestCase {
|
||||
func testInsertStatement() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE foo (id INTEGER, bar TEXT, baz TEXT, qux TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE foo (id INTEGER, bar TEXT, baz TEXT, qux TEXT)")
|
||||
let statement = try db.makeUpdateStatement("INSERT INTO foo (id, bar) VALUES (1, 'bar')")
|
||||
XCTAssertFalse(statement.invalidatesDatabaseSchemaCache)
|
||||
XCTAssertEqual(statement.databaseEventKinds.count, 1)
|
||||
@@ -589,7 +589,7 @@ class DatabaseRegionTests : GRDBTestCase {
|
||||
func testDeleteStatement() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE foo (id INTEGER, bar TEXT, baz TEXT, qux TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE foo (id INTEGER, bar TEXT, baz TEXT, qux TEXT)")
|
||||
let statement = try db.makeUpdateStatement("DELETE FROM foo")
|
||||
XCTAssertFalse(statement.invalidatesDatabaseSchemaCache)
|
||||
XCTAssertEqual(statement.databaseEventKinds.count, 1)
|
||||
|
||||
@@ -8,12 +8,12 @@ import XCTest
|
||||
#endif
|
||||
|
||||
func insertItem(_ db: Database, name: String) throws {
|
||||
try db.execute(rawSQL: "INSERT INTO items (name) VALUES (?)", arguments: [name])
|
||||
try db.execute(sql: "INSERT INTO items (name) VALUES (?)", arguments: [name])
|
||||
}
|
||||
|
||||
func fetchAllItemNames(_ dbReader: DatabaseReader) throws -> [String] {
|
||||
return try dbReader.read { db in
|
||||
try String.fetchAll(db, rawSQL: "SELECT * FROM items ORDER BY name")
|
||||
try String.fetchAll(db, sql: "SELECT * FROM items ORDER BY name")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class DatabaseSavepointTests: GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: DatabaseWriter) throws {
|
||||
try dbWriter.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE items (name TEXT)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,24 +67,24 @@ class DatabaseSavepointTests: GRDBTestCase {
|
||||
}
|
||||
XCTAssertFalse(db.isInsideTransaction)
|
||||
|
||||
try db.execute(rawSQL: "BEGIN DEFERRED TRANSACTION")
|
||||
try db.execute(sql: "BEGIN DEFERRED TRANSACTION")
|
||||
XCTAssertTrue(db.isInsideTransaction)
|
||||
try db.execute(rawSQL: "COMMIT") // does not trigger sqlite3_commit_hook, because transaction was not open yet.
|
||||
try db.execute(sql: "COMMIT") // does not trigger sqlite3_commit_hook, because transaction was not open yet.
|
||||
XCTAssertFalse(db.isInsideTransaction)
|
||||
|
||||
try db.execute(rawSQL: "BEGIN DEFERRED TRANSACTION")
|
||||
try db.execute(sql: "BEGIN DEFERRED TRANSACTION")
|
||||
XCTAssertTrue(db.isInsideTransaction)
|
||||
try db.execute(rawSQL: "ROLLBACK") // does trigger sqlite3_rollback_hook
|
||||
try db.execute(sql: "ROLLBACK") // does trigger sqlite3_rollback_hook
|
||||
XCTAssertFalse(db.isInsideTransaction)
|
||||
|
||||
try db.execute(rawSQL: "BEGIN IMMEDIATE TRANSACTION")
|
||||
try db.execute(sql: "BEGIN IMMEDIATE TRANSACTION")
|
||||
XCTAssertTrue(db.isInsideTransaction)
|
||||
try db.execute(rawSQL: "COMMIT") // does trigger sqlite3_commit_hook
|
||||
try db.execute(sql: "COMMIT") // does trigger sqlite3_commit_hook
|
||||
XCTAssertFalse(db.isInsideTransaction)
|
||||
|
||||
try db.execute(rawSQL: "BEGIN IMMEDIATE TRANSACTION")
|
||||
try db.execute(sql: "BEGIN IMMEDIATE TRANSACTION")
|
||||
XCTAssertTrue(db.isInsideTransaction)
|
||||
try db.execute(rawSQL: "ROLLBACK")
|
||||
try db.execute(sql: "ROLLBACK")
|
||||
XCTAssertFalse(db.isInsideTransaction)
|
||||
}
|
||||
}
|
||||
@@ -95,13 +95,13 @@ class DatabaseSavepointTests: GRDBTestCase {
|
||||
try db.create(table: "test") { t in
|
||||
t.column("value", .integer).unique()
|
||||
}
|
||||
try db.execute(rawSQL: "BEGIN TRANSACTION")
|
||||
try db.execute(sql: "BEGIN TRANSACTION")
|
||||
XCTAssertTrue(db.isInsideTransaction)
|
||||
try db.execute(rawSQL: "INSERT INTO test (value) VALUES (?)", arguments: [1])
|
||||
try db.execute(sql: "INSERT INTO test (value) VALUES (?)", arguments: [1])
|
||||
XCTAssertTrue(db.isInsideTransaction)
|
||||
XCTAssertThrowsError(try db.execute(rawSQL: "INSERT OR ROLLBACK INTO test (value) VALUES (?)", arguments: [1]))
|
||||
XCTAssertThrowsError(try db.execute(sql: "INSERT OR ROLLBACK INTO test (value) VALUES (?)", arguments: [1]))
|
||||
XCTAssertFalse(db.isInsideTransaction)
|
||||
XCTAssertThrowsError(try db.execute(rawSQL: "COMMIT"))
|
||||
XCTAssertThrowsError(try db.execute(sql: "COMMIT"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ class DatabaseSavepointTests: GRDBTestCase {
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 5)
|
||||
#endif
|
||||
try dbQueue.inDatabase { db in try db.execute(rawSQL: "DELETE FROM items") }
|
||||
try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") }
|
||||
observer.reset()
|
||||
|
||||
sqlQueries.removeAll()
|
||||
@@ -242,7 +242,7 @@ class DatabaseSavepointTests: GRDBTestCase {
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 2)
|
||||
#endif
|
||||
try dbQueue.inDatabase { db in try db.execute(rawSQL: "DELETE FROM items") }
|
||||
try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") }
|
||||
observer.reset()
|
||||
|
||||
sqlQueries.removeAll()
|
||||
@@ -280,7 +280,7 @@ class DatabaseSavepointTests: GRDBTestCase {
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 4)
|
||||
#endif
|
||||
try dbQueue.inDatabase { db in try db.execute(rawSQL: "DELETE FROM items") }
|
||||
try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") }
|
||||
observer.reset()
|
||||
|
||||
sqlQueries.removeAll()
|
||||
@@ -318,7 +318,7 @@ class DatabaseSavepointTests: GRDBTestCase {
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 2)
|
||||
#endif
|
||||
try dbQueue.inDatabase { db in try db.execute(rawSQL: "DELETE FROM items") }
|
||||
try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") }
|
||||
observer.reset()
|
||||
}
|
||||
|
||||
@@ -421,7 +421,7 @@ class DatabaseSavepointTests: GRDBTestCase {
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 5)
|
||||
#endif
|
||||
try dbQueue.inDatabase { db in try db.execute(rawSQL: "DELETE FROM items") }
|
||||
try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") }
|
||||
observer.reset()
|
||||
|
||||
sqlQueries.removeAll()
|
||||
@@ -458,7 +458,7 @@ class DatabaseSavepointTests: GRDBTestCase {
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 5)
|
||||
#endif
|
||||
try dbQueue.inDatabase { db in try db.execute(rawSQL: "DELETE FROM items") }
|
||||
try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") }
|
||||
observer.reset()
|
||||
|
||||
sqlQueries.removeAll()
|
||||
@@ -496,7 +496,7 @@ class DatabaseSavepointTests: GRDBTestCase {
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 4)
|
||||
#endif
|
||||
try dbQueue.inDatabase { db in try db.execute(rawSQL: "DELETE FROM items") }
|
||||
try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") }
|
||||
observer.reset()
|
||||
|
||||
sqlQueries.removeAll()
|
||||
@@ -534,7 +534,7 @@ class DatabaseSavepointTests: GRDBTestCase {
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
XCTAssertEqual(observer.allRecordedPreUpdateEvents.count, 4)
|
||||
#endif
|
||||
try dbQueue.inDatabase { db in try db.execute(rawSQL: "DELETE FROM items") }
|
||||
try dbQueue.inDatabase { db in try db.execute(sql: "DELETE FROM items") }
|
||||
observer.reset()
|
||||
}
|
||||
|
||||
|
||||
@@ -27,15 +27,15 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.writeWithoutTransaction { db in
|
||||
try db.create(table: "t") { $0.column("id", .integer).primaryKey() }
|
||||
try db.execute(rawSQL: "INSERT INTO t DEFAULT VALUES")
|
||||
try db.execute(sql: "INSERT INTO t DEFAULT VALUES")
|
||||
let snapshot = try dbPool.makeSnapshot()
|
||||
try snapshot.read { db in
|
||||
try XCTAssertEqual(Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM t")!, 1)
|
||||
try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 1)
|
||||
}
|
||||
try db.execute(rawSQL: "INSERT INTO t DEFAULT VALUES")
|
||||
try XCTAssertEqual(Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM t")!, 2)
|
||||
try db.execute(sql: "INSERT INTO t DEFAULT VALUES")
|
||||
try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 2)
|
||||
try snapshot.read { db in
|
||||
try XCTAssertEqual(Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM t")!, 1)
|
||||
try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,19 +44,19 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.create(table: "t") { $0.column("id", .integer).primaryKey() }
|
||||
try db.execute(rawSQL: "INSERT INTO t DEFAULT VALUES")
|
||||
try db.execute(sql: "INSERT INTO t DEFAULT VALUES")
|
||||
}
|
||||
|
||||
let snapshot = try dbPool.makeSnapshot()
|
||||
try snapshot.read { db in
|
||||
try XCTAssertEqual(Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM t")!, 1)
|
||||
try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 1)
|
||||
}
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO t DEFAULT VALUES")
|
||||
try XCTAssertEqual(Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM t")!, 2)
|
||||
try db.execute(sql: "INSERT INTO t DEFAULT VALUES")
|
||||
try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 2)
|
||||
}
|
||||
try snapshot.read { db in
|
||||
try XCTAssertEqual(Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM t")!, 1)
|
||||
try XCTAssertEqual(Int.fetchOne(db, sql: "SELECT COUNT(*) FROM t")!, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
|
||||
let snapshot = try dbPool.makeSnapshot()
|
||||
try snapshot.read { db in
|
||||
try XCTAssertEqual(String.fetchOne(db, rawSQL: "SELECT foo()")!, "foo")
|
||||
try XCTAssertEqual(String.fetchOne(db, sql: "SELECT foo()")!, "foo")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
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, rawSQL: "SELECT foo()")!, "foo")
|
||||
try XCTAssertEqual(String.fetchOne(db, sql: "SELECT foo()")!, "foo")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,25 +89,25 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
dbPool.add(collation: collation)
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (text TEXT)")
|
||||
try db.execute(rawSQL: "INSERT INTO items (text) VALUES ('a')")
|
||||
try db.execute(rawSQL: "INSERT INTO items (text) VALUES ('b')")
|
||||
try db.execute(rawSQL: "INSERT INTO items (text) VALUES ('c')")
|
||||
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()
|
||||
try snapshot.read { db in
|
||||
XCTAssertEqual(try String.fetchAll(db, rawSQL: "SELECT text FROM items ORDER BY text COLLATE reverse"), ["c", "b", "a"])
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE reverse"), ["c", "b", "a"])
|
||||
}
|
||||
}
|
||||
|
||||
func testSnapshotCollations() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE items (text TEXT)")
|
||||
try db.execute(rawSQL: "INSERT INTO items (text) VALUES ('a')")
|
||||
try db.execute(rawSQL: "INSERT INTO items (text) VALUES ('b')")
|
||||
try db.execute(rawSQL: "INSERT INTO items (text) VALUES ('c')")
|
||||
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()
|
||||
@@ -116,7 +116,7 @@ class DatabaseSnapshotTests: GRDBTestCase {
|
||||
}
|
||||
snapshot.add(collation: collation)
|
||||
try snapshot.read { db in
|
||||
XCTAssertEqual(try String.fetchAll(db, rawSQL: "SELECT text FROM items ORDER BY text COLLATE reverse"), ["c", "b", "a"])
|
||||
XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE reverse"), ["c", "b", "a"])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class DatabaseTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertFalse(try db.tableExists("persons"))
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE persons (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT,
|
||||
@@ -27,7 +27,7 @@ class DatabaseTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertFalse(try db.tableExists("persons"))
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TEMPORARY TABLE persons (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT,
|
||||
@@ -42,7 +42,7 @@ class DatabaseTests : GRDBTestCase {
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertFalse(try db.tableExists("persons"))
|
||||
XCTAssertFalse(try db.tableExists("pets"))
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, age INT);
|
||||
CREATE TABLE pets (id INTEGER PRIMARY KEY, name TEXT, age INT);
|
||||
""")
|
||||
@@ -54,13 +54,13 @@ class DatabaseTests : GRDBTestCase {
|
||||
func testUpdateStatement() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
|
||||
// The tested function:
|
||||
let statement = try db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES ('Arthur', 41)")
|
||||
try statement.execute()
|
||||
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT * FROM persons")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")!
|
||||
XCTAssertEqual(row[0] as String, "Arthur")
|
||||
XCTAssertEqual(row[1] as Int, 41)
|
||||
}
|
||||
@@ -69,12 +69,12 @@ class DatabaseTests : GRDBTestCase {
|
||||
func testUpdateStatementWithArrayBinding() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
|
||||
let statement = try db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES (?, ?)")
|
||||
try statement.execute(arguments: ["Arthur", 41])
|
||||
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT * FROM persons")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")!
|
||||
XCTAssertEqual(row[0] as String, "Arthur")
|
||||
XCTAssertEqual(row[1] as Int, 41)
|
||||
}
|
||||
@@ -83,12 +83,12 @@ class DatabaseTests : GRDBTestCase {
|
||||
func testUpdateStatementWithDictionaryBinding() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
|
||||
let statement = try db.makeUpdateStatement("INSERT INTO persons (name, age) VALUES (:name, :age)")
|
||||
try statement.execute(arguments: ["name": "Arthur", "age": 41])
|
||||
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT * FROM persons")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")!
|
||||
XCTAssertEqual(row[0] as String, "Arthur")
|
||||
XCTAssertEqual(row[1] as Int, 41)
|
||||
}
|
||||
@@ -97,12 +97,12 @@ class DatabaseTests : GRDBTestCase {
|
||||
func testDatabaseExecute() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
|
||||
// The tested function:
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES ('Arthur', 41)")
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES ('Arthur', 41)")
|
||||
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT * FROM persons")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")!
|
||||
XCTAssertEqual(row[0] as String, "Arthur")
|
||||
XCTAssertEqual(row[1] as Int, 41)
|
||||
}
|
||||
@@ -115,19 +115,19 @@ class DatabaseTests : GRDBTestCase {
|
||||
XCTAssertEqual(db.totalChangesCount, 0)
|
||||
XCTAssertEqual(db.lastInsertedRowID, 0)
|
||||
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name) VALUES ('Arthur')")
|
||||
try db.execute(sql: "INSERT INTO persons (name) VALUES ('Arthur')")
|
||||
XCTAssertEqual(db.changesCount, 1)
|
||||
XCTAssertEqual(db.totalChangesCount, 1)
|
||||
XCTAssertEqual(db.lastInsertedRowID, 1)
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name) VALUES (?)", arguments: ["Barbara"])
|
||||
try db.execute(sql: "INSERT INTO persons (name) VALUES (?)", arguments: ["Barbara"])
|
||||
XCTAssertEqual(db.changesCount, 1)
|
||||
XCTAssertEqual(db.totalChangesCount, 2)
|
||||
XCTAssertEqual(db.lastInsertedRowID, 2)
|
||||
|
||||
try db.execute(rawSQL: "DELETE FROM persons")
|
||||
try db.execute(sql: "DELETE FROM persons")
|
||||
XCTAssertEqual(db.changesCount, 2)
|
||||
XCTAssertEqual(db.totalChangesCount, 4)
|
||||
XCTAssertEqual(db.lastInsertedRowID, 2)
|
||||
@@ -137,12 +137,12 @@ class DatabaseTests : GRDBTestCase {
|
||||
func testDatabaseExecuteWithArrayBinding() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
|
||||
// The tested function:
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (?, ?)", arguments: ["Arthur", 41])
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES (?, ?)", arguments: ["Arthur", 41])
|
||||
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT * FROM persons")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")!
|
||||
XCTAssertEqual(row[0] as String, "Arthur")
|
||||
XCTAssertEqual(row[1] as Int, 41)
|
||||
}
|
||||
@@ -151,12 +151,12 @@ class DatabaseTests : GRDBTestCase {
|
||||
func testDatabaseExecuteWithDictionaryBinding() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
|
||||
// The tested function:
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41])
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41])
|
||||
|
||||
let row = try Row.fetchOne(db, rawSQL: "SELECT * FROM persons")!
|
||||
let row = try Row.fetchOne(db, sql: "SELECT * FROM persons")!
|
||||
XCTAssertEqual(row[0] as String, "Arthur")
|
||||
XCTAssertEqual(row[1] as Int, 41)
|
||||
}
|
||||
@@ -165,9 +165,9 @@ class DatabaseTests : GRDBTestCase {
|
||||
func testSelectStatement() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41])
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil])
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41])
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil])
|
||||
|
||||
let statement = try db.makeSelectStatement("SELECT * FROM persons")
|
||||
let rows = try Row.fetchAll(statement)
|
||||
@@ -178,9 +178,9 @@ class DatabaseTests : GRDBTestCase {
|
||||
func testSelectStatementWithArrayBinding() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41])
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil])
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41])
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil])
|
||||
|
||||
let statement = try db.makeSelectStatement("SELECT * FROM persons WHERE name = ?")
|
||||
let rows = try Row.fetchAll(statement, arguments: ["Arthur"])
|
||||
@@ -191,9 +191,9 @@ class DatabaseTests : GRDBTestCase {
|
||||
func testSelectStatementWithDictionaryBinding() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41])
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil])
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41])
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil])
|
||||
|
||||
let statement = try db.makeSelectStatement("SELECT * FROM persons WHERE name = :name")
|
||||
let rows = try Row.fetchAll(statement, arguments: ["name": "Arthur"])
|
||||
@@ -204,13 +204,13 @@ class DatabaseTests : GRDBTestCase {
|
||||
func testRowValueAtIndex() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41])
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil])
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41])
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil])
|
||||
|
||||
var names: [String?] = []
|
||||
var ages: [Int?] = []
|
||||
let rows = try Row.fetchCursor(db, rawSQL: "SELECT * FROM persons ORDER BY name")
|
||||
let rows = try Row.fetchCursor(db, sql: "SELECT * FROM persons ORDER BY name")
|
||||
while let row = try rows.next() {
|
||||
// The tested function:
|
||||
let name: String? = row[0]
|
||||
@@ -229,13 +229,13 @@ class DatabaseTests : GRDBTestCase {
|
||||
func testRowValueNamed() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41])
|
||||
try db.execute(rawSQL: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil])
|
||||
try db.execute(sql: "CREATE TABLE persons (name TEXT, age INT)")
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Arthur", "age": 41])
|
||||
try db.execute(sql: "INSERT INTO persons (name, age) VALUES (:name, :age)", arguments: ["name": "Barbara", "age": nil])
|
||||
|
||||
var names: [String?] = []
|
||||
var ages: [Int?] = []
|
||||
let rows = try Row.fetchCursor(db, rawSQL: "SELECT * FROM persons ORDER BY name")
|
||||
let rows = try Row.fetchCursor(db, sql: "SELECT * FROM persons ORDER BY name")
|
||||
while let row = try rows.next() {
|
||||
// The tested function:
|
||||
let name: String? = row["name"]
|
||||
@@ -258,7 +258,7 @@ class DatabaseTests : GRDBTestCase {
|
||||
database = db
|
||||
}
|
||||
try dbQueue.inDatabase { _ in
|
||||
try database!.execute(rawSQL: "CREATE TABLE persons (name TEXT)")
|
||||
try database!.execute(sql: "CREATE TABLE persons (name TEXT)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,15 +273,15 @@ class DatabaseTests : GRDBTestCase {
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE parent (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(rawSQL: "CREATE TABLE child (parentID INTEGER NOT NULL REFERENCES parent(id))")
|
||||
try db.execute(sql: "CREATE TABLE parent (id INTEGER PRIMARY KEY)")
|
||||
try db.execute(sql: "CREATE TABLE child (parentID INTEGER NOT NULL REFERENCES parent(id))")
|
||||
}
|
||||
|
||||
do {
|
||||
try dbQueue.inTransaction { db in
|
||||
do {
|
||||
try db.execute(rawSQL: "PRAGMA defer_foreign_keys = ON")
|
||||
try db.execute(rawSQL: "INSERT INTO child (parentID) VALUES (1)")
|
||||
try db.execute(sql: "PRAGMA defer_foreign_keys = ON")
|
||||
try db.execute(sql: "INSERT INTO child (parentID) VALUES (1)")
|
||||
} catch {
|
||||
XCTFail()
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ class DatabaseTimestampTests: GRDBTestCase {
|
||||
func testDatabaseTimestamp() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE dates (date DATETIME)")
|
||||
try db.execute(sql: "CREATE TABLE dates (date DATETIME)")
|
||||
let storedDate = Date()
|
||||
try db.execute(rawSQL: "INSERT INTO dates (date) VALUES (?)", arguments: [DatabaseTimestamp(storedDate)])
|
||||
let fetchedDate = try DatabaseTimestamp.fetchOne(db, rawSQL: "SELECT date FROM dates")!.date
|
||||
try db.execute(sql: "INSERT INTO dates (date) VALUES (?)", arguments: [DatabaseTimestamp(storedDate)])
|
||||
let fetchedDate = try DatabaseTimestamp.fetchOne(db, sql: "SELECT date FROM dates")!.date
|
||||
let delta = storedDate.timeIntervalSince(fetchedDate)
|
||||
XCTAssertTrue(abs(delta) < 0.1)
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
|
||||
do {
|
||||
// test T.fetchOne
|
||||
let sqliteConversion = try T.fetchOne(db, rawSQL: sql)
|
||||
let sqliteConversion = try T.fetchOne(db, sql: sql)
|
||||
XCTAssert(
|
||||
sqliteConversion == expectedSQLiteConversion,
|
||||
"unexpected SQLite conversion: \(stringRepresentation(sqliteConversion)) instead of \(stringRepresentation(expectedSQLiteConversion))",
|
||||
@@ -69,7 +69,7 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
|
||||
do {
|
||||
// test row[0] as T?
|
||||
let sqliteConversion = try Row.fetchCursor(db, rawSQL: sql).map { $0[0] as T? }.next()!
|
||||
let sqliteConversion = try Row.fetchCursor(db, sql: sql).map { $0[0] as T? }.next()!
|
||||
XCTAssert(
|
||||
sqliteConversion == expectedSQLiteConversion,
|
||||
"unexpected SQLite conversion: \(stringRepresentation(sqliteConversion)) instead of \(stringRepresentation(expectedSQLiteConversion))",
|
||||
@@ -78,7 +78,7 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
|
||||
do {
|
||||
// test row[0] as T
|
||||
let sqliteConversion = try Row.fetchCursor(db, rawSQL: sql).map { $0.hasNull(atIndex: 0) ? nil : ($0[0] as T) }.next()!
|
||||
let sqliteConversion = try Row.fetchCursor(db, sql: sql).map { $0.hasNull(atIndex: 0) ? nil : ($0[0] as T) }.next()!
|
||||
XCTAssert(
|
||||
sqliteConversion == expectedSQLiteConversion,
|
||||
"unexpected SQLite conversion: \(stringRepresentation(sqliteConversion)) instead of \(stringRepresentation(expectedSQLiteConversion))",
|
||||
@@ -87,7 +87,7 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
|
||||
do {
|
||||
// test T.fromDatabaseValue
|
||||
let dbValue = try DatabaseValue.fetchOne(db, rawSQL: sql)!
|
||||
let dbValue = try DatabaseValue.fetchOne(db, sql: sql)!
|
||||
let dbValueConversion = T.fromDatabaseValue(dbValue)
|
||||
XCTAssert(
|
||||
dbValueConversion == expectedDatabaseValueConversion,
|
||||
@@ -106,7 +106,7 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// We can only test failed decoding from database value, since
|
||||
// StatementColumnConvertible only supports optimistic decoding which
|
||||
// never fails.
|
||||
let dbValue = try DatabaseValue.fetchOne(db, rawSQL: sql)!
|
||||
let dbValue = try DatabaseValue.fetchOne(db, sql: sql)!
|
||||
XCTAssertNil(T.fromDatabaseValue(dbValue), file: file, line: line)
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
override func setup(_ dbWriter: DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPersons") { db in
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE `values` (
|
||||
integerAffinity INTEGER,
|
||||
textAffinity TEXT,
|
||||
@@ -140,9 +140,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Null is turned to null
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (textAffinity) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (NULL)")
|
||||
let sql = "SELECT textAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .null)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .null)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil)
|
||||
@@ -156,9 +156,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Int is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int])
|
||||
try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int])
|
||||
let sql = "SELECT textAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -172,9 +172,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Int64 is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int64])
|
||||
try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int64])
|
||||
let sql = "SELECT textAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -188,9 +188,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Int32 is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int32])
|
||||
try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0 as Int32])
|
||||
let sql = "SELECT textAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -204,9 +204,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Double is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0.0])
|
||||
try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [0.0])
|
||||
let sql = "SELECT textAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -221,9 +221,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Empty string is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [""])
|
||||
try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [""])
|
||||
let sql = "SELECT textAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -237,9 +237,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// "3.0e+5" is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: ["3.0e+5"])
|
||||
try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: ["3.0e+5"])
|
||||
let sql = "SELECT textAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:3, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 3, expectedDatabaseValueConversion: nil)
|
||||
@@ -253,9 +253,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// emojiString is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [emojiString])
|
||||
try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [emojiString])
|
||||
let sql = "SELECT textAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -269,9 +269,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// emojiData is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [emojiData])
|
||||
try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [emojiData])
|
||||
let sql = "SELECT textAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .blob)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -285,9 +285,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// nonUTF8Data is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [nonUTF8Data])
|
||||
try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [nonUTF8Data])
|
||||
let sql = "SELECT textAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .blob)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -302,9 +302,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// jpegData is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [jpegData])
|
||||
try db.execute(sql: "INSERT INTO `values` (textAffinity) VALUES (?)", arguments: [jpegData])
|
||||
let sql = "SELECT textAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .blob)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -370,9 +370,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Null is turned to null
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (NULL)")
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .null)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .null)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil)
|
||||
@@ -386,9 +386,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Int is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int])
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int])
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .real)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
@@ -402,9 +402,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Int64 is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int64])
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int64])
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .real)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
@@ -418,9 +418,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Int32 is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int32])
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [0 as Int32])
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .real)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
@@ -434,9 +434,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// 3.0e5 Double is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [3.0e5])
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [3.0e5])
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .real)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000)
|
||||
@@ -450,9 +450,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// 1.0e20 Double is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [1.0e20])
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [1.0e20])
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .real)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true)
|
||||
try assertFailedDecoding(db, sql, Int.self)
|
||||
try assertFailedDecoding(db, sql, Int32.self)
|
||||
@@ -466,9 +466,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Empty string is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [""])
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [""])
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -482,9 +482,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// "3.0e+5" is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["3.0e+5"])
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["3.0e+5"])
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .real)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000)
|
||||
@@ -498,9 +498,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// "1.0e+20" is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["1.0e+20"])
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: ["1.0e+20"])
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .real)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true)
|
||||
try assertFailedDecoding(db, sql, Int.self)
|
||||
try assertFailedDecoding(db, sql, Int32.self)
|
||||
@@ -514,9 +514,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// emojiString is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [emojiString])
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [emojiString])
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -530,9 +530,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// emojiData is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [emojiData])
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [emojiData])
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .blob)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -546,9 +546,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// nonUTF8Data is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [nonUTF8Data])
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [nonUTF8Data])
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .blob)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -563,9 +563,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// jpegData is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [jpegData])
|
||||
try db.execute(sql: "INSERT INTO `values` (realAffinity) VALUES (?)", arguments: [jpegData])
|
||||
let sql = "SELECT realAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .blob)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -591,9 +591,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Null is turned to null
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (noneAffinity) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (NULL)")
|
||||
let sql = "SELECT noneAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .null)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .null)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil)
|
||||
@@ -607,9 +607,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Int is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int])
|
||||
try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int])
|
||||
let sql = "SELECT noneAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .integer)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
@@ -623,9 +623,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Int64 is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int64])
|
||||
try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int64])
|
||||
let sql = "SELECT noneAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .integer)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
@@ -639,9 +639,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Int32 is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int32])
|
||||
try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0 as Int32])
|
||||
let sql = "SELECT noneAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .integer)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
@@ -655,9 +655,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Double is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0.0])
|
||||
try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [0.0])
|
||||
let sql = "SELECT noneAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .real)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
@@ -671,9 +671,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Empty string is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [""])
|
||||
try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [""])
|
||||
let sql = "SELECT noneAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -687,9 +687,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// "3.0e+5" is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: ["3.0e+5"])
|
||||
try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: ["3.0e+5"])
|
||||
let sql = "SELECT noneAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:3, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 3, expectedDatabaseValueConversion: nil)
|
||||
@@ -703,9 +703,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// emojiString is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [emojiString])
|
||||
try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [emojiString])
|
||||
let sql = "SELECT noneAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -719,9 +719,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// emojiData is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [emojiData])
|
||||
try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [emojiData])
|
||||
let sql = "SELECT noneAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .blob)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -735,9 +735,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// nonUTF8Data is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [nonUTF8Data])
|
||||
try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [nonUTF8Data])
|
||||
let sql = "SELECT noneAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .blob)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -752,9 +752,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// jpegData is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [jpegData])
|
||||
try db.execute(sql: "INSERT INTO `values` (noneAffinity) VALUES (?)", arguments: [jpegData])
|
||||
let sql = "SELECT noneAffinity FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .blob)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -794,9 +794,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Null is turned to null
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (NULL)")
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (NULL)")
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .null)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .null)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: nil, expectedDatabaseValueConversion: nil)
|
||||
@@ -810,9 +810,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Int is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int])
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int])
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .integer)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
@@ -826,9 +826,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Int64 is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int64])
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int64])
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .integer)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
@@ -842,9 +842,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Int32 is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int32])
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [0 as Int32])
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .integer)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: false)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: 0)
|
||||
@@ -858,9 +858,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// 3.0e5 Double is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [3.0e5])
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [3.0e5])
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .integer)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000)
|
||||
@@ -874,9 +874,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// 1.0e20 Double is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [1.0e20])
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [1.0e20])
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .real)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true)
|
||||
try assertFailedDecoding(db, sql, Int.self)
|
||||
try assertFailedDecoding(db, sql, Int32.self)
|
||||
@@ -890,9 +890,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// Empty string is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [""])
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [""])
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -906,9 +906,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// "3.0e+5" is turned to Integer
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["3.0e+5"])
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["3.0e+5"])
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .integer)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .integer)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 300000, expectedDatabaseValueConversion: 300000)
|
||||
@@ -922,9 +922,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// "1.0e+20" is turned to Real
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["1.0e+20"])
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: ["1.0e+20"])
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .real)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .real)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: true, expectedDatabaseValueConversion: true)
|
||||
try assertFailedDecoding(db, sql, Int.self)
|
||||
try assertFailedDecoding(db, sql, Int32.self)
|
||||
@@ -938,9 +938,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// emojiString is turned to Text
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [emojiString])
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [emojiString])
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .text)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .text)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -954,9 +954,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// emojiData is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [emojiData])
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [emojiData])
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .blob)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -970,9 +970,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// nonUTF8Data is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [nonUTF8Data])
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [nonUTF8Data])
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .blob)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
@@ -987,9 +987,9 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
// jpegData is turned to Blob
|
||||
|
||||
try dbQueue.inTransaction { db in
|
||||
try db.execute(rawSQL: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [jpegData])
|
||||
try db.execute(sql: "INSERT INTO `values` (\(columnName)) VALUES (?)", arguments: [jpegData])
|
||||
let sql = "SELECT \(columnName) FROM `values`"
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: sql)!.storageClass, .blob)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: sql)!.storageClass, .blob)
|
||||
try assertDecoding(db, sql, Bool.self, expectedSQLiteConversion: false, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int.self, expectedSQLiteConversion:0, expectedDatabaseValueConversion: nil)
|
||||
try assertDecoding(db, sql, Int32.self, expectedSQLiteConversion: 0, expectedDatabaseValueConversion: nil)
|
||||
|
||||
@@ -33,7 +33,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
|
||||
// Success from database
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let value = try Value.fetchOne(db, rawSQL: "SELECT 'foo'")!
|
||||
let value = try Value.fetchOne(db, sql: "SELECT 'foo'")!
|
||||
XCTAssertEqual(value.string, "foo")
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
|
||||
// Success from database
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let wrapper = try ValueWrapper.fetchOne(db, rawSQL: "SELECT 'foo'")!
|
||||
let wrapper = try ValueWrapper.fetchOne(db, sql: "SELECT 'foo'")!
|
||||
XCTAssertEqual(wrapper.value.string, "foo")
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
|
||||
// Success from database
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let wrapper = try ValueWrapper.fetchOne(db, rawSQL: "SELECT 'foo'")!
|
||||
let wrapper = try ValueWrapper.fetchOne(db, sql: "SELECT 'foo'")!
|
||||
XCTAssertEqual(wrapper.nested.string, "foo")
|
||||
}
|
||||
}
|
||||
@@ -154,7 +154,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let value = try Value.fetchOne(db, rawSQL: "SELECT 'foo'")!
|
||||
let value = try Value.fetchOne(db, sql: "SELECT 'foo'")!
|
||||
XCTAssertEqual(value.string, "foo (DatabaseValueConvertible)")
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase {
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let value = try Value.fetchOne(db, rawSQL: "SELECT 'foo'")!
|
||||
let value = try Value.fetchOne(db, sql: "SELECT 'foo'")!
|
||||
XCTAssertEqual(value, .foo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,21 +40,21 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
do {
|
||||
let sql = "SELECT 1 UNION ALL SELECT 2"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchCursor(db, rawSQL: sql))
|
||||
try test(Fetched.fetchCursor(db, sql: sql))
|
||||
try test(Fetched.fetchCursor(statement))
|
||||
try test(Fetched.fetchCursor(db, literal: SQLLiteral(rawSQL: sql)))
|
||||
try test(Fetched.fetchCursor(db, SQLRequest<Void>(rawSQL: sql)))
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql).fetchCursor(db))
|
||||
try test(Fetched.fetchCursor(db, literal: SQLLiteral(sql: sql)))
|
||||
try test(Fetched.fetchCursor(db, SQLRequest<Void>(sql: sql)))
|
||||
try test(SQLRequest<Fetched>(sql: sql).fetchCursor(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Fetched.fetchCursor(db, rawSQL: sql, adapter: adapter))
|
||||
try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter))
|
||||
try test(Fetched.fetchCursor(statement, adapter: adapter))
|
||||
try test(Fetched.fetchCursor(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter))
|
||||
try test(Fetched.fetchCursor(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql, adapter: adapter).fetchCursor(db))
|
||||
try test(Fetched.fetchCursor(db, literal: SQLLiteral(sql: sql), adapter: adapter))
|
||||
try test(Fetched.fetchCursor(db, SQLRequest<Void>(sql: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched>(sql: sql, adapter: adapter).fetchCursor(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,20 +99,20 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT throw()"
|
||||
try test(Fetched.fetchCursor(db, rawSQL: sql), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, sql: sql), sql: sql)
|
||||
try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, literal: SQLLiteral(rawSQL: sql)), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, SQLRequest<Void>(rawSQL: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql).fetchCursor(db), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, literal: SQLLiteral(sql: sql)), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, SQLRequest<Void>(sql: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql: sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Fetched.fetchCursor(db, rawSQL: sql, adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, literal: SQLLiteral(sql: sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, SQLRequest<Void>(sql: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql: sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,20 +133,20 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Fetched.fetchCursor(db, rawSQL: sql), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, sql: sql), sql: sql)
|
||||
try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, literal: SQLLiteral(rawSQL: sql)), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, SQLRequest<Void>(rawSQL: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql).fetchCursor(db), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, literal: SQLLiteral(sql: sql)), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, SQLRequest<Void>(sql: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql: sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Fetched.fetchCursor(db, rawSQL: sql, adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, literal: SQLLiteral(sql: sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchCursor(db, SQLRequest<Void>(sql: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql: sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,21 +160,21 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
do {
|
||||
let sql = "SELECT 1 UNION ALL SELECT 2"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchAll(db, rawSQL: sql))
|
||||
try test(Fetched.fetchAll(db, sql: sql))
|
||||
try test(Fetched.fetchAll(statement))
|
||||
try test(Fetched.fetchAll(db, literal: SQLLiteral(rawSQL: sql)))
|
||||
try test(Fetched.fetchAll(db, SQLRequest<Void>(rawSQL: sql)))
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql).fetchAll(db))
|
||||
try test(Fetched.fetchAll(db, literal: SQLLiteral(sql: sql)))
|
||||
try test(Fetched.fetchAll(db, SQLRequest<Void>(sql: sql)))
|
||||
try test(SQLRequest<Fetched>(sql: sql).fetchAll(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Fetched.fetchAll(db, rawSQL: sql, adapter: adapter))
|
||||
try test(Fetched.fetchAll(db, sql: sql, adapter: adapter))
|
||||
try test(Fetched.fetchAll(statement, adapter: adapter))
|
||||
try test(Fetched.fetchAll(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter))
|
||||
try test(Fetched.fetchAll(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql, adapter: adapter).fetchAll(db))
|
||||
try test(Fetched.fetchAll(db, literal: SQLLiteral(sql: sql), adapter: adapter))
|
||||
try test(Fetched.fetchAll(db, SQLRequest<Void>(sql: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched>(sql: sql, adapter: adapter).fetchAll(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,20 +209,20 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT throw()"
|
||||
try test(Fetched.fetchAll(db, rawSQL: sql), sql: sql)
|
||||
try test(Fetched.fetchAll(db, sql: sql), sql: sql)
|
||||
try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Fetched.fetchAll(db, literal: SQLLiteral(rawSQL: sql)), sql: sql)
|
||||
try test(Fetched.fetchAll(db, SQLRequest<Void>(rawSQL: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql).fetchAll(db), sql: sql)
|
||||
try test(Fetched.fetchAll(db, literal: SQLLiteral(sql: sql)), sql: sql)
|
||||
try test(Fetched.fetchAll(db, SQLRequest<Void>(sql: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql: sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Fetched.fetchAll(db, rawSQL: sql, adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchAll(db, sql: sql, adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchAll(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchAll(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
try test(Fetched.fetchAll(db, literal: SQLLiteral(sql: sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchAll(db, SQLRequest<Void>(sql: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql: sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -243,20 +243,20 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Fetched.fetchAll(db, rawSQL: sql), sql: sql)
|
||||
try test(Fetched.fetchAll(db, sql: sql), sql: sql)
|
||||
try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Fetched.fetchAll(db, literal: SQLLiteral(rawSQL: sql)), sql: sql)
|
||||
try test(Fetched.fetchAll(db, SQLRequest<Void>(rawSQL: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql).fetchAll(db), sql: sql)
|
||||
try test(Fetched.fetchAll(db, literal: SQLLiteral(sql: sql)), sql: sql)
|
||||
try test(Fetched.fetchAll(db, SQLRequest<Void>(sql: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql: sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Fetched.fetchAll(db, rawSQL: sql, adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchAll(db, sql: sql, adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchAll(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchAll(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
try test(Fetched.fetchAll(db, literal: SQLLiteral(sql: sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchAll(db, SQLRequest<Void>(sql: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql: sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -271,21 +271,21 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
do {
|
||||
let sql = "SELECT 1 WHERE 0"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchOne(db, rawSQL: sql))
|
||||
try test(Fetched.fetchOne(db, sql: sql))
|
||||
try test(Fetched.fetchOne(statement))
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(rawSQL: sql)))
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(rawSQL: sql)))
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql).fetchOne(db))
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(sql: sql)))
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(sql: sql)))
|
||||
try test(SQLRequest<Fetched>(sql: sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 WHERE 0"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Fetched.fetchOne(db, rawSQL: sql, adapter: adapter))
|
||||
try test(Fetched.fetchOne(db, sql: sql, adapter: adapter))
|
||||
try test(Fetched.fetchOne(statement, adapter: adapter))
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter))
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql, adapter: adapter).fetchOne(db))
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(sql: sql), adapter: adapter))
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(sql: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched>(sql: sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -295,21 +295,21 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
do {
|
||||
let sql = "SELECT NULL"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchOne(db, rawSQL: sql))
|
||||
try test(Fetched.fetchOne(db, sql: sql))
|
||||
try test(Fetched.fetchOne(statement))
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(rawSQL: sql)))
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(rawSQL: sql)))
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql).fetchOne(db))
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(sql: sql)))
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(sql: sql)))
|
||||
try test(SQLRequest<Fetched>(sql: sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, NULL"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Fetched.fetchOne(db, rawSQL: sql, adapter: adapter))
|
||||
try test(Fetched.fetchOne(db, sql: sql, adapter: adapter))
|
||||
try test(Fetched.fetchOne(statement, adapter: adapter))
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter))
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql, adapter: adapter).fetchOne(db))
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(sql: sql), adapter: adapter))
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(sql: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched>(sql: sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -319,21 +319,21 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
do {
|
||||
let sql = "SELECT 1"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchOne(db, rawSQL: sql))
|
||||
try test(Fetched.fetchOne(db, sql: sql))
|
||||
try test(Fetched.fetchOne(statement))
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(rawSQL: sql)))
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(rawSQL: sql)))
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql).fetchOne(db))
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(sql: sql)))
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(sql: sql)))
|
||||
try test(SQLRequest<Fetched>(sql: sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Fetched.fetchOne(db, rawSQL: sql, adapter: adapter))
|
||||
try test(Fetched.fetchOne(db, sql: sql, adapter: adapter))
|
||||
try test(Fetched.fetchOne(statement, adapter: adapter))
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter))
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql, adapter: adapter).fetchOne(db))
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(sql: sql), adapter: adapter))
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(sql: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched>(sql: sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -369,20 +369,20 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT throw()"
|
||||
try test(Fetched.fetchOne(db, rawSQL: sql), sql: sql)
|
||||
try test(Fetched.fetchOne(db, sql: sql), sql: sql)
|
||||
try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(rawSQL: sql)), sql: sql)
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(rawSQL: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql).fetchOne(db), sql: sql)
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(sql: sql)), sql: sql)
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(sql: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql: sql).fetchOne(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Fetched.fetchOne(db, rawSQL: sql, adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchOne(db, sql: sql, adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql, adapter: adapter).fetchOne(db), sql: sql)
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(sql: sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(sql: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql: sql, adapter: adapter).fetchOne(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -403,20 +403,20 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Fetched.fetchOne(db, rawSQL: sql), sql: sql)
|
||||
try test(Fetched.fetchOne(db, sql: sql), sql: sql)
|
||||
try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(rawSQL: sql)), sql: sql)
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(rawSQL: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql).fetchOne(db), sql: sql)
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(sql: sql)), sql: sql)
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(sql: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql: sql).fetchOne(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Fetched.fetchOne(db, rawSQL: sql, adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchOne(db, sql: sql, adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(rawSQL: sql, adapter: adapter).fetchOne(db), sql: sql)
|
||||
try test(Fetched.fetchOne(db, literal: SQLLiteral(sql: sql), adapter: adapter), sql: sql)
|
||||
try test(Fetched.fetchOne(db, SQLRequest<Void>(sql: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql: sql, adapter: adapter).fetchOne(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -435,21 +435,21 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
do {
|
||||
let sql = "SELECT 1 UNION ALL SELECT NULL"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, rawSQL: sql))
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql: sql))
|
||||
try test(Optional<Fetched>.fetchCursor(statement))
|
||||
try test(Optional<Fetched>.fetchCursor(db, literal: SQLLiteral(rawSQL: sql)))
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest<Void>(rawSQL: sql)))
|
||||
try test(SQLRequest<Fetched?>(rawSQL: sql).fetchCursor(db))
|
||||
try test(Optional<Fetched>.fetchCursor(db, literal: SQLLiteral(sql: sql)))
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest<Void>(sql: sql)))
|
||||
try test(SQLRequest<Fetched?>(sql: sql).fetchCursor(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchCursor(db, rawSQL: sql, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql: sql, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchCursor(statement, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchCursor(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched?>(rawSQL: sql, adapter: adapter).fetchCursor(db))
|
||||
try test(Optional<Fetched>.fetchCursor(db, literal: SQLLiteral(sql: sql), adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest<Void>(sql: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched?>(sql: sql, adapter: adapter).fetchCursor(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -494,20 +494,20 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT throw()"
|
||||
try test(Optional<Fetched>.fetchCursor(db, rawSQL: sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql: sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, literal: SQLLiteral(rawSQL: sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest<Void>(rawSQL: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(rawSQL: sql).fetchCursor(db), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, literal: SQLLiteral(sql: sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest<Void>(sql: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql: sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchCursor(db, rawSQL: sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql: sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(rawSQL: sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, literal: SQLLiteral(sql: sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest<Void>(sql: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql: sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -528,20 +528,20 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Optional<Fetched>.fetchCursor(db, rawSQL: sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql: sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, literal: SQLLiteral(rawSQL: sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest<Void>(rawSQL: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(rawSQL: sql).fetchCursor(db), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, literal: SQLLiteral(sql: sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest<Void>(sql: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql: sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchCursor(db, rawSQL: sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql: sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(rawSQL: sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, literal: SQLLiteral(sql: sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest<Void>(sql: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql: sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -557,21 +557,21 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
do {
|
||||
let sql = "SELECT 1 UNION ALL SELECT NULL"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, rawSQL: sql))
|
||||
try test(Optional<Fetched>.fetchAll(db, sql: sql))
|
||||
try test(Optional<Fetched>.fetchAll(statement))
|
||||
try test(Optional<Fetched>.fetchAll(db, literal: SQLLiteral(rawSQL: sql)))
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest<Void>(rawSQL: sql)))
|
||||
try test(SQLRequest<Fetched?>(rawSQL: sql).fetchAll(db))
|
||||
try test(Optional<Fetched>.fetchAll(db, literal: SQLLiteral(sql: sql)))
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest<Void>(sql: sql)))
|
||||
try test(SQLRequest<Fetched?>(sql: sql).fetchAll(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL"
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchAll(db, rawSQL: sql, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchAll(db, sql: sql, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchAll(statement, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchAll(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched?>(rawSQL: sql, adapter: adapter).fetchAll(db))
|
||||
try test(Optional<Fetched>.fetchAll(db, literal: SQLLiteral(sql: sql), adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest<Void>(sql: sql, adapter: adapter)))
|
||||
try test(SQLRequest<Fetched?>(sql: sql, adapter: adapter).fetchAll(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -606,20 +606,20 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT throw()"
|
||||
try test(Optional<Fetched>.fetchAll(db, rawSQL: sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, sql: sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, literal: SQLLiteral(rawSQL: sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest<Void>(rawSQL: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(rawSQL: sql).fetchAll(db), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, literal: SQLLiteral(sql: sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest<Void>(sql: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql: sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchAll(db, rawSQL: sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, sql: sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(rawSQL: sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, literal: SQLLiteral(sql: sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest<Void>(sql: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql: sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -640,20 +640,20 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Optional<Fetched>.fetchAll(db, rawSQL: sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, sql: sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, literal: SQLLiteral(rawSQL: sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest<Void>(rawSQL: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(rawSQL: sql).fetchAll(db), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, literal: SQLLiteral(sql: sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest<Void>(sql: sql)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql: sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchAll(db, rawSQL: sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, sql: sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, literal: SQLLiteral(rawSQL: sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest<Void>(rawSQL: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(rawSQL: sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, literal: SQLLiteral(sql: sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest<Void>(sql: sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql: sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,13 +36,13 @@ class DatabaseValueConvertibleSubclassTests: GRDBTestCase {
|
||||
func testParent() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE parents (name TEXT)")
|
||||
try db.execute(rawSQL: "INSERT INTO parents (name) VALUES (?)", arguments: [FetchableParent()])
|
||||
let string = try String.fetchOne(db, rawSQL: "SELECT * FROM parents")!
|
||||
try db.execute(sql: "CREATE TABLE parents (name TEXT)")
|
||||
try db.execute(sql: "INSERT INTO parents (name) VALUES (?)", arguments: [FetchableParent()])
|
||||
let string = try String.fetchOne(db, sql: "SELECT * FROM parents")!
|
||||
XCTAssertEqual(string, "Parent")
|
||||
let parent = try FetchableParent.fetchOne(db, rawSQL: "SELECT * FROM parents")!
|
||||
let parent = try FetchableParent.fetchOne(db, sql: "SELECT * FROM parents")!
|
||||
XCTAssertEqual(parent.description, "Parent")
|
||||
let parents = try FetchableParent.fetchAll(db, rawSQL: "SELECT * FROM parents")
|
||||
let parents = try FetchableParent.fetchAll(db, sql: "SELECT * FROM parents")
|
||||
XCTAssertEqual(parents.first!.description, "Parent")
|
||||
}
|
||||
}
|
||||
@@ -50,13 +50,13 @@ class DatabaseValueConvertibleSubclassTests: GRDBTestCase {
|
||||
func testChild() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE children (name TEXT)")
|
||||
try db.execute(rawSQL: "INSERT INTO children (name) VALUES (?)", arguments: [FetchableChild()])
|
||||
let string = try String.fetchOne(db, rawSQL: "SELECT * FROM children")!
|
||||
try db.execute(sql: "CREATE TABLE children (name TEXT)")
|
||||
try db.execute(sql: "INSERT INTO children (name) VALUES (?)", arguments: [FetchableChild()])
|
||||
let string = try String.fetchOne(db, sql: "SELECT * FROM children")!
|
||||
XCTAssertEqual(string, "Child")
|
||||
let child = try FetchableChild.fetchOne(db, rawSQL: "SELECT * FROM children")!
|
||||
let child = try FetchableChild.fetchOne(db, sql: "SELECT * FROM children")!
|
||||
XCTAssertEqual(child.description, "Child")
|
||||
let children = try FetchableChild.fetchAll(db, rawSQL: "SELECT * FROM children")
|
||||
let children = try FetchableChild.fetchAll(db, sql: "SELECT * FROM children")
|
||||
XCTAssertEqual(children.first!.description, "Child")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,21 +12,21 @@ class DatabaseValueTests: GRDBTestCase {
|
||||
func testDatabaseValueAsDatabaseValueConvertible() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: "SELECT 1")!.storage, DatabaseValue.Storage.int64(1))
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: "SELECT 1.0")!.storage, DatabaseValue.Storage.double(1))
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: "SELECT 'foo'")!.storage, DatabaseValue.Storage.string("foo"))
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, rawSQL: "SELECT x'53514C697465'")!.storage, DatabaseValue.Storage.blob("SQLite".data(using: .utf8)!))
|
||||
XCTAssertTrue(try DatabaseValue.fetchOne(db, rawSQL: "SELECT NULL")!.isNull)
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: "SELECT 1")!.storage, DatabaseValue.Storage.int64(1))
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: "SELECT 1.0")!.storage, DatabaseValue.Storage.double(1))
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: "SELECT 'foo'")!.storage, DatabaseValue.Storage.string("foo"))
|
||||
XCTAssertEqual(try DatabaseValue.fetchOne(db, sql: "SELECT x'53514C697465'")!.storage, DatabaseValue.Storage.blob("SQLite".data(using: .utf8)!))
|
||||
XCTAssertTrue(try DatabaseValue.fetchOne(db, sql: "SELECT NULL")!.isNull)
|
||||
}
|
||||
}
|
||||
|
||||
func testDatabaseValueCanBeUsedAsStatementArgument() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE integers (integer INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO integers (integer) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE integers (integer INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO integers (integer) VALUES (1)")
|
||||
let dbValue: DatabaseValue = 1.databaseValue
|
||||
let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM integers WHERE integer = ?", arguments: [dbValue])!
|
||||
let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM integers WHERE integer = ?", arguments: [dbValue])!
|
||||
XCTAssertEqual(count, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ class DatabaseWriterTests : GRDBTestCase {
|
||||
t.column("id", .integer).primaryKey()
|
||||
}
|
||||
try dbQueue.unsafeReentrantWrite { db2 in
|
||||
try db2.execute(rawSQL: "INSERT INTO table1 (id) VALUES (NULL)")
|
||||
try db2.execute(sql: "INSERT INTO table1 (id) VALUES (NULL)")
|
||||
|
||||
try dbQueue.unsafeReentrantWrite { db3 in
|
||||
try XCTAssertEqual(Int.fetchOne(db3, rawSQL: "SELECT * FROM table1"), 1)
|
||||
try XCTAssertEqual(Int.fetchOne(db3, sql: "SELECT * FROM table1"), 1)
|
||||
XCTAssertTrue(db1 === db2)
|
||||
XCTAssertTrue(db2 === db3)
|
||||
}
|
||||
@@ -34,10 +34,10 @@ class DatabaseWriterTests : GRDBTestCase {
|
||||
t.column("id", .integer).primaryKey()
|
||||
}
|
||||
try dbPool.unsafeReentrantWrite { db2 in
|
||||
try db2.execute(rawSQL: "INSERT INTO table1 (id) VALUES (NULL)")
|
||||
try db2.execute(sql: "INSERT INTO table1 (id) VALUES (NULL)")
|
||||
|
||||
try dbPool.unsafeReentrantWrite { db3 in
|
||||
try XCTAssertEqual(Int.fetchOne(db3, rawSQL: "SELECT * FROM table1"), 1)
|
||||
try XCTAssertEqual(Int.fetchOne(db3, sql: "SELECT * FROM table1"), 1)
|
||||
XCTAssertTrue(db1 === db2)
|
||||
XCTAssertTrue(db2 === db3)
|
||||
}
|
||||
@@ -61,7 +61,7 @@ class DatabaseWriterTests : GRDBTestCase {
|
||||
migrator.registerMigration("init") { db in
|
||||
// Create a database with recursive constraints, so that we test
|
||||
// that those don't prevent database erasure.
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE t1 (id INTEGER PRIMARY KEY AUTOINCREMENT, b UNIQUE, c REFERENCES t2(id) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE t2 (id INTEGER PRIMARY KEY AUTOINCREMENT, b UNIQUE, c REFERENCES t1(id) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE VIRTUAL TABLE ft USING fts4(content);
|
||||
@@ -87,7 +87,7 @@ class DatabaseWriterTests : GRDBTestCase {
|
||||
try writer.vacuum()
|
||||
|
||||
try writer.read { db in
|
||||
try XCTAssertNil(Row.fetchOne(db, rawSQL: "SELECT * FROM sqlite_master"))
|
||||
try XCTAssertNil(Row.fetchOne(db, sql: "SELECT * FROM sqlite_master"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class DatabaseWriterTests : GRDBTestCase {
|
||||
func testIssue424() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.write { db in
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE t(a);
|
||||
INSERT INTO t VALUES (1)
|
||||
""")
|
||||
@@ -110,7 +110,7 @@ class DatabaseWriterTests : GRDBTestCase {
|
||||
func testIssue424Minimal() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: """
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE t(a);
|
||||
INSERT INTO t VALUES (1);
|
||||
PRAGMA query_only = 1;
|
||||
|
||||
@@ -9,8 +9,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM data")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,10 +84,10 @@ class EncryptionTests: GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.change(passphrase: "newSecret")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (2)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (2)")
|
||||
}
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM data")!, 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "newSecret"
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM data")!, 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,8 +105,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite")
|
||||
try dbPool.read { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM data")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,8 +124,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,8 +147,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,8 +170,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,8 +180,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite")
|
||||
try dbPool.change(passphrase: "newSecret")
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (2)")
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM data")!, 2)
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (2)")
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "newSecret"
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite")
|
||||
try dbPool.read { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM data")!, 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,8 +199,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite")
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite")
|
||||
try dbPool.read { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM data")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,8 +218,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite")
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,8 +241,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite")
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,8 +265,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite")
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,8 +275,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite")
|
||||
try dbPool.change(passphrase: "newSecret")
|
||||
try dbPool.write { db in
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (2)")
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM data")!, 2)
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (2)")
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "newSecret"
|
||||
let dbPool = try makeDatabasePool(filename: "test.sqlite")
|
||||
try dbPool.read { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM data")!, 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -294,9 +294,9 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = nil
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "PRAGMA key = 'secret'")
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "PRAGMA key = 'secret'")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM data")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -314,9 +314,9 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = nil
|
||||
let dbQueue = try makeDatabaseQueue(filename: "test.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "PRAGMA key = 'secret'")
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "PRAGMA key = 'secret'")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,8 +345,8 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = nil
|
||||
let plainTextDBQueue = try makeDatabaseQueue(filename: "plaintext.sqlite")
|
||||
try plainTextDBQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(rawSQL: "INSERT INTO data (value) VALUES (1)")
|
||||
try db.execute(sql: "CREATE TABLE data (value INTEGER)")
|
||||
try db.execute(sql: "INSERT INTO data (value) VALUES (1)")
|
||||
}
|
||||
|
||||
dbConfiguration.passphrase = "secret"
|
||||
@@ -362,9 +362,9 @@ class EncryptionTests: GRDBTestCase {
|
||||
let encryptedDBQueue = try makeDatabaseQueue(filename: "encrypted.sqlite")
|
||||
|
||||
try plainTextDBQueue.inDatabase { db in
|
||||
try db.execute(rawSQL: "ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"])
|
||||
try db.execute(rawSQL: "SELECT sqlcipher_export('encrypted')")
|
||||
try db.execute(rawSQL: "DETACH DATABASE encrypted")
|
||||
try db.execute(sql: "ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"])
|
||||
try db.execute(sql: "SELECT sqlcipher_export('encrypted')")
|
||||
try db.execute(sql: "DETACH DATABASE encrypted")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,7 +372,7 @@ class EncryptionTests: GRDBTestCase {
|
||||
dbConfiguration.passphrase = "secret"
|
||||
let dbQueue = try makeDatabaseQueue(filename: "encrypted.sqlite")
|
||||
try dbQueue.inDatabase { db in
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM data")!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ class FTS3PatternTests: GRDBTestCase {
|
||||
t.column("author")
|
||||
t.column("body")
|
||||
}
|
||||
try db.execute(rawSQL: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Moby Dick", "Herman Melville", "Call me Ishmael. Some years ago--never mind how long precisely--having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world."])
|
||||
try db.execute(rawSQL: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Red Mars", "Kim Stanley Robinson", "History is not evolution! It is a false analogy! Evolution is a matter of environment and chance, acting over millions of years. But history is a matter of environment and choice, acting within lifetimes, and sometimes within years, or months, or days! History is Lamarckian!"])
|
||||
try db.execute(rawSQL: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Querelle de Brest", "Jean Genet", "L’idée de mer évoque souvent l’idée de mer, de marins. Mer et marins ne se présentent pas alors avec la précision d’une image, le meurtre plutôt fait en nous l’émotion déferler par vagues."])
|
||||
try db.execute(rawSQL: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Éden, Éden, Éden", "Pierre Guyotat", "/ Les soldats, casqués, jambes ouvertes, foulent, muscles retenus, les nouveau-nés emmaillotés dans les châles écarlates, violets : les bébés roulent hors des bras des femmes accroupies sur les tôles mitraillées des G. M. C. ;"])
|
||||
try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Moby Dick", "Herman Melville", "Call me Ishmael. Some years ago--never mind how long precisely--having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world."])
|
||||
try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Red Mars", "Kim Stanley Robinson", "History is not evolution! It is a false analogy! Evolution is a matter of environment and chance, acting over millions of years. But history is a matter of environment and choice, acting within lifetimes, and sometimes within years, or months, or days! History is Lamarckian!"])
|
||||
try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Querelle de Brest", "Jean Genet", "L’idée de mer évoque souvent l’idée de mer, de marins. Mer et marins ne se présentent pas alors avec la précision d’une image, le meurtre plutôt fait en nous l’émotion déferler par vagues."])
|
||||
try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Éden, Éden, Éden", "Pierre Guyotat", "/ Les soldats, casqués, jambes ouvertes, foulent, muscles retenus, les nouveau-nés emmaillotés dans les châles écarlates, violets : les bébés roulent hors des bras des femmes accroupies sur les tôles mitraillées des G. M. C. ;"])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class FTS3PatternTests: GRDBTestCase {
|
||||
]
|
||||
for (rawPattern, expectedCount) in validRawPatterns {
|
||||
let pattern = try FTS3Pattern(rawPattern: rawPattern)
|
||||
let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results")
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class FTS3PatternTests: GRDBTestCase {
|
||||
if let pattern = FTS3Pattern(matchingAnyTokenIn: string) {
|
||||
let rawPattern = String.fromDatabaseValue(pattern.databaseValue)!
|
||||
XCTAssertEqual(rawPattern, expectedRawPattern)
|
||||
let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results")
|
||||
}
|
||||
}
|
||||
@@ -136,7 +136,7 @@ class FTS3PatternTests: GRDBTestCase {
|
||||
if let pattern = FTS3Pattern(matchingAllTokensIn: string) {
|
||||
let rawPattern = String.fromDatabaseValue(pattern.databaseValue)!
|
||||
XCTAssertEqual(rawPattern, expectedRawPattern)
|
||||
let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results")
|
||||
}
|
||||
}
|
||||
@@ -172,7 +172,7 @@ class FTS3PatternTests: GRDBTestCase {
|
||||
if let pattern = FTS3Pattern(matchingPhrase: string) {
|
||||
let rawPattern = String.fromDatabaseValue(pattern.databaseValue)!
|
||||
XCTAssertEqual(rawPattern, expectedRawPattern)
|
||||
let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ class FTS3TableBuilderTests: GRDBTestCase {
|
||||
try db.create(virtualTable: "documents", using: FTS3())
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts3")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1)
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ class FTS3TableBuilderTests: GRDBTestCase {
|
||||
try db.create(virtualTable: "documents", ifNotExists: true, using: FTS3())
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE IF NOT EXISTS \"documents\" USING fts3")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1)
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,12 +136,12 @@ class FTS3TableBuilderTests: GRDBTestCase {
|
||||
}
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"books\" USING fts3(author, title, body)")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Melville"])!, 1)
|
||||
try db.execute(sql: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Melville"])!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,11 @@ import XCTest
|
||||
class FTS3TokenizerTests: GRDBTestCase {
|
||||
|
||||
private func match(_ db: Database, _ content: String, _ query: String) -> Bool {
|
||||
try! db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: [content])
|
||||
try! db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: [content])
|
||||
defer {
|
||||
try! db.execute(rawSQL: "DELETE FROM documents")
|
||||
try! db.execute(sql: "DELETE FROM documents")
|
||||
}
|
||||
return try! Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: [query])! > 0
|
||||
return try! Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: [query])! > 0
|
||||
}
|
||||
|
||||
func testSimpleTokenizer() throws {
|
||||
|
||||
@@ -26,8 +26,8 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
try db.create(virtualTable: "documents", using: FTS4())
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts4")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1)
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
try db.create(virtualTable: "documents", ifNotExists: true, using: FTS4())
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE IF NOT EXISTS \"documents\" USING fts4")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1)
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,12 +136,12 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
}
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"books\" USING fts4(author, title, body)")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Melville"])!, 1)
|
||||
try db.execute(sql: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Melville"])!, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,17 +161,17 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
}
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"books\" USING fts4(author, notindexed=author, title, body, notindexed=body)")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Dick"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Dick"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Dick"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Dick"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Dick"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Melville"])!, 0)
|
||||
try db.execute(sql: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Dick"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Dick"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Dick"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Dick"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Dick"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE title MATCH ?", arguments: ["Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE author MATCH ?", arguments: ["Melville"])!, 0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,9 +189,9 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
}
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts4(content, languageid=\"lid\", content=\"\", compress=\"zip\", uncompress=\"unzip\", matchinfo=\"fts3\", prefix=\"2,4\")")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents (docid, content, lid) VALUES (?, ?, ?)", arguments: [1, "abc", 0])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ? AND lid=0", arguments: ["abc"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ? AND lid=1", arguments: ["abc"])!, 0)
|
||||
try db.execute(sql: "INSERT INTO documents (docid, content, lid) VALUES (?, ?, ?)", arguments: [1, "abc", 0])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ? AND lid=0", arguments: ["abc"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ? AND lid=1", arguments: ["abc"])!, 0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,30 +202,30 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
t.column("id", .integer).primaryKey()
|
||||
t.column("content", .text)
|
||||
}
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.create(virtualTable: "ft_documents", using: FTS4()) { t in
|
||||
t.synchronize(withTable: "documents")
|
||||
t.column("content")
|
||||
}
|
||||
|
||||
// Prepopulated
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 0)
|
||||
|
||||
// Synchronized on update
|
||||
try db.execute(rawSQL: "UPDATE documents SET content = ?", arguments: ["bar"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
|
||||
try db.execute(sql: "UPDATE documents SET content = ?", arguments: ["bar"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
|
||||
|
||||
// Synchronized on insert
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
|
||||
|
||||
// Synchronized on delete
|
||||
try db.execute(rawSQL: "DELETE FROM documents WHERE content = ?", arguments: ["foo"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
|
||||
try db.execute(sql: "DELETE FROM documents WHERE content = ?", arguments: ["foo"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
t.column("id", .integer).primaryKey()
|
||||
t.column("content", .text)
|
||||
}
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.create(virtualTable: "ft_documents", using: FTS4()) { t in
|
||||
t.synchronize(withTable: "documents")
|
||||
t.column("content")
|
||||
@@ -246,9 +246,9 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
try db.dropFTS4SynchronizationTriggers(forTable: "ft_documents")
|
||||
|
||||
// It is possible to modify the content table
|
||||
try db.execute(rawSQL: "UPDATE documents SET content = ?", arguments: ["bar"])
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(rawSQL: "DELETE FROM documents WHERE content = ?", arguments: ["foo"])
|
||||
try db.execute(sql: "UPDATE documents SET content = ?", arguments: ["bar"])
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(sql: "DELETE FROM documents WHERE content = ?", arguments: ["foo"])
|
||||
|
||||
// It is possible to recreate the FT table
|
||||
try db.create(virtualTable: "ft_documents", using: FTS4()) { t in
|
||||
@@ -265,7 +265,7 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
t.column("id", .integer).primaryKey()
|
||||
t.column("content", .text)
|
||||
}
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.create(virtualTable: "ft_documents", using: FTS4()) { t in
|
||||
t.synchronize(withTable: "documents")
|
||||
t.column("content")
|
||||
@@ -276,9 +276,9 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
try db.dropFTS4SynchronizationTriggers(forTable: "ft_documents")
|
||||
|
||||
// It is possible to modify the content table
|
||||
try db.execute(rawSQL: "UPDATE documents SET content = ?", arguments: ["bar"])
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(rawSQL: "DELETE FROM documents WHERE content = ?", arguments: ["foo"])
|
||||
try db.execute(sql: "UPDATE documents SET content = ?", arguments: ["bar"])
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(sql: "DELETE FROM documents WHERE content = ?", arguments: ["foo"])
|
||||
|
||||
// It is possible to recreate the FT table
|
||||
try db.create(virtualTable: "ft_documents", using: FTS4()) { t in
|
||||
@@ -311,12 +311,12 @@ class FTS4TableBuilderTests: GRDBTestCase {
|
||||
}
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts4(content, compress=\"zipit\", uncompress=\"unzipit\")")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["abc"])
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertTrue(compressCalled)
|
||||
}
|
||||
|
||||
try dbPool.read { db in
|
||||
_ = try Row.fetchOne(db, rawSQL: "SELECT * FROM documents")
|
||||
_ = try Row.fetchOne(db, sql: "SELECT * FROM documents")
|
||||
XCTAssertTrue(uncompressCalled)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,15 +210,15 @@ class FTS5CustomTokenizerTests: GRDBTestCase {
|
||||
t.column("content")
|
||||
}
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["foo bar"])
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["foo baz"])
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["foo bar"])
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["foo baz"])
|
||||
|
||||
// foo is not ignored
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2)
|
||||
// bar is ignored
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0)
|
||||
// bar is ignored in queries too: the "foo bar baz" phrase matches the "foo baz" content
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,24 +232,24 @@ class FTS5CustomTokenizerTests: GRDBTestCase {
|
||||
t.column("content")
|
||||
}
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["foo bar"])
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["foo baz"])
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["foo bar"])
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["foo baz"])
|
||||
|
||||
// foo is not ignored
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2)
|
||||
// bar is ignored
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0)
|
||||
// bar is ignored in queries too: the "foo bar baz" phrase matches the "foo baz" content
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1)
|
||||
}
|
||||
|
||||
try dbPool.read { db in
|
||||
// foo is not ignored
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["foo"]), 2)
|
||||
// bar is ignored
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["bar"]), 0)
|
||||
// bar is ignored in queries too: the "foo bar baz" phrase matches the "foo baz" content
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,12 +264,12 @@ class FTS5CustomTokenizerTests: GRDBTestCase {
|
||||
t.column("content")
|
||||
}
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["aimé\u{FB01}"]) // U+FB01: LATIN SMALL LIGATURE FI
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["aimé\u{FB01}"]) // U+FB01: LATIN SMALL LIGATURE FI
|
||||
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé\u{FB01}"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimefi"]), 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aim\u{00E9}fi"]), 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301}\u{FB01}"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé\u{FB01}"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimefi"]), 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aim\u{00E9}fi"]), 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301}\u{FB01}"]), 1)
|
||||
|
||||
try db.drop(table: "documents")
|
||||
}
|
||||
@@ -281,12 +281,12 @@ class FTS5CustomTokenizerTests: GRDBTestCase {
|
||||
t.column("content")
|
||||
}
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["aimé\u{FB01}"]) // U+FB01: LATIN SMALL LIGATURE FI
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["aimé\u{FB01}"]) // U+FB01: LATIN SMALL LIGATURE FI
|
||||
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé\u{FB01}"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimefi"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aim\u{00E9}fi"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301}\u{FB01}"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé\u{FB01}"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimefi"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aim\u{00E9}fi"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301}\u{FB01}"]), 1)
|
||||
|
||||
try db.drop(table: "documents")
|
||||
}
|
||||
@@ -299,12 +299,12 @@ class FTS5CustomTokenizerTests: GRDBTestCase {
|
||||
t.column("content")
|
||||
}
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["aimé\u{FB01}"]) // U+FB01: LATIN SMALL LIGATURE FI
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["aimé\u{FB01}"]) // U+FB01: LATIN SMALL LIGATURE FI
|
||||
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé\u{FB01}"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimefi"]), 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aim\u{00E9}fi"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301}\u{FB01}"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimé\u{FB01}"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aimefi"]), 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aim\u{00E9}fi"]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["aime\u{0301}\u{FB01}"]), 1)
|
||||
|
||||
try db.drop(table: "documents")
|
||||
}
|
||||
@@ -320,17 +320,17 @@ class FTS5CustomTokenizerTests: GRDBTestCase {
|
||||
t.column("content")
|
||||
}
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["first foo"])
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["1st bar"])
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["first foo"])
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["1st bar"])
|
||||
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["first"]), 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1st"]), 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"first foo\""]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"1st foo\""]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"first bar\""]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"1st bar\""]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["fi*"]), 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1s*"]), 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["first"]), 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1st"]), 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"first foo\""]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"1st foo\""]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"first bar\""]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"1st bar\""]), 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["fi*"]), 2)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1s*"]), 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ class FTS5PatternTests: GRDBTestCase {
|
||||
t.column("author")
|
||||
t.column("body")
|
||||
}
|
||||
try db.execute(rawSQL: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Moby-Dick", "Herman Melville", "Call me Ishmael. Some years ago--never mind how long precisely--having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world."])
|
||||
try db.execute(rawSQL: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Red Mars", "Kim Stanley Robinson", "History is not evolution! It is a false analogy! Evolution is a matter of environment and chance, acting over millions of years. But history is a matter of environment and choice, acting within lifetimes, and sometimes within years, or months, or days! History is Lamarckian!"])
|
||||
try db.execute(rawSQL: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Querelle de Brest", "Jean Genet", "L’idée de mer évoque souvent l’idée de mer, de marins. Mer et marins ne se présentent pas alors avec la précision d’une image, le meurtre plutôt fait en nous l’émotion déferler par vagues."])
|
||||
try db.execute(rawSQL: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Éden, Éden, Éden", "Pierre Guyotat", "/ Les soldats, casqués, jambes ouvertes, foulent, muscles retenus, les nouveau-nés emmaillotés dans les châles écarlates, violets : les bébés roulent hors des bras des femmes accroupies sur les tôles mitraillées des G. M. C. ;"])
|
||||
try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Moby-Dick", "Herman Melville", "Call me Ishmael. Some years ago--never mind how long precisely--having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world."])
|
||||
try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Red Mars", "Kim Stanley Robinson", "History is not evolution! It is a false analogy! Evolution is a matter of environment and chance, acting over millions of years. But history is a matter of environment and choice, acting within lifetimes, and sometimes within years, or months, or days! History is Lamarckian!"])
|
||||
try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Querelle de Brest", "Jean Genet", "L’idée de mer évoque souvent l’idée de mer, de marins. Mer et marins ne se présentent pas alors avec la précision d’une image, le meurtre plutôt fait en nous l’émotion déferler par vagues."])
|
||||
try db.execute(sql: "INSERT INTO books (title, author, body) VALUES (?, ?, ?)", arguments: ["Éden, Éden, Éden", "Pierre Guyotat", "/ Les soldats, casqués, jambes ouvertes, foulent, muscles retenus, les nouveau-nés emmaillotés dans les châles écarlates, violets : les bébés roulent hors des bras des femmes accroupies sur les tôles mitraillées des G. M. C. ;"])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class FTS5PatternTests: GRDBTestCase {
|
||||
]
|
||||
for (rawPattern, expectedCount) in validRawPatterns {
|
||||
let pattern = try db.makeFTS5Pattern(rawPattern: rawPattern, forTable: "books")
|
||||
let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results")
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class FTS5PatternTests: GRDBTestCase {
|
||||
if let pattern = FTS5Pattern(matchingAnyTokenIn: string) {
|
||||
let rawPattern = String.fromDatabaseValue(pattern.databaseValue)!
|
||||
XCTAssertEqual(rawPattern, expectedRawPattern)
|
||||
let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results")
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,7 @@ class FTS5PatternTests: GRDBTestCase {
|
||||
if let pattern = FTS5Pattern(matchingAllTokensIn: string) {
|
||||
let rawPattern = String.fromDatabaseValue(pattern.databaseValue)!
|
||||
XCTAssertEqual(rawPattern, expectedRawPattern)
|
||||
let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results")
|
||||
}
|
||||
}
|
||||
@@ -155,7 +155,7 @@ class FTS5PatternTests: GRDBTestCase {
|
||||
if let pattern = FTS5Pattern(matchingPhrase: string) {
|
||||
let rawPattern = String.fromDatabaseValue(pattern.databaseValue)!
|
||||
XCTAssertEqual(rawPattern, expectedRawPattern)
|
||||
let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results")
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,7 @@ class FTS5PatternTests: GRDBTestCase {
|
||||
if let pattern = FTS5Pattern(matchingPrefixPhrase: string) {
|
||||
let rawPattern = String.fromDatabaseValue(pattern.databaseValue)!
|
||||
XCTAssertEqual(rawPattern, expectedRawPattern)
|
||||
let count = try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])!
|
||||
XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ class FTS5TableBuilderTests: GRDBTestCase {
|
||||
}
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts5(content)")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1)
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ class FTS5TableBuilderTests: GRDBTestCase {
|
||||
}
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE IF NOT EXISTS \"documents\" USING fts5(content)")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO documents VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1)
|
||||
try db.execute(sql: "INSERT INTO documents VALUES (?)", arguments: ["abc"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["abc"])!, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,10 +145,10 @@ class FTS5TableBuilderTests: GRDBTestCase {
|
||||
}
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"books\" USING fts5(author, title, body)")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 1)
|
||||
try db.execute(sql: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,13 +162,13 @@ class FTS5TableBuilderTests: GRDBTestCase {
|
||||
}
|
||||
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"books\" USING fts5(author UNINDEXED, title, body UNINDEXED)")
|
||||
|
||||
try db.execute(rawSQL: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Dick"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Dick"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Dick"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 0)
|
||||
try db.execute(sql: "INSERT INTO books VALUES (?, ?, ?)", arguments: ["Melville", "Moby Dick", "Call me Ishmael."])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Dick"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Dick"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Dick"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["title:Melville"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: ["author:Melville"])!, 0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,30 +193,30 @@ class FTS5TableBuilderTests: GRDBTestCase {
|
||||
t.column("id", .integer).primaryKey()
|
||||
t.column("content", .text)
|
||||
}
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.create(virtualTable: "ft_documents", using: FTS5()) { t in
|
||||
t.synchronize(withTable: "documents")
|
||||
t.column("content")
|
||||
}
|
||||
|
||||
// Prepopulated
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 0)
|
||||
|
||||
// Synchronized on update
|
||||
try db.execute(rawSQL: "UPDATE documents SET content = ?", arguments: ["bar"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
|
||||
try db.execute(sql: "UPDATE documents SET content = ?", arguments: ["bar"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
|
||||
|
||||
// Synchronized on insert
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 1)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
|
||||
|
||||
// Synchronized on delete
|
||||
try db.execute(rawSQL: "DELETE FROM documents WHERE content = ?", arguments: ["foo"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, rawSQL: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
|
||||
try db.execute(sql: "DELETE FROM documents WHERE content = ?", arguments: ["foo"])
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["foo"])!, 0)
|
||||
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM ft_documents WHERE ft_documents MATCH ?", arguments: ["bar"])!, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ class FTS5TableBuilderTests: GRDBTestCase {
|
||||
t.column("id", .integer).primaryKey()
|
||||
t.column("content", .text)
|
||||
}
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.create(virtualTable: "ft_documents", using: FTS5()) { t in
|
||||
t.synchronize(withTable: "documents")
|
||||
t.column("content")
|
||||
@@ -237,9 +237,9 @@ class FTS5TableBuilderTests: GRDBTestCase {
|
||||
try db.dropFTS5SynchronizationTriggers(forTable: "ft_documents")
|
||||
|
||||
// It is possible to modify the content table
|
||||
try db.execute(rawSQL: "UPDATE documents SET content = ?", arguments: ["bar"])
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(rawSQL: "DELETE FROM documents WHERE content = ?", arguments: ["foo"])
|
||||
try db.execute(sql: "UPDATE documents SET content = ?", arguments: ["bar"])
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(sql: "DELETE FROM documents WHERE content = ?", arguments: ["foo"])
|
||||
|
||||
// It is possible to recreate the FT table
|
||||
try db.create(virtualTable: "ft_documents", using: FTS5()) { t in
|
||||
@@ -256,7 +256,7 @@ class FTS5TableBuilderTests: GRDBTestCase {
|
||||
t.column("id", .integer).primaryKey()
|
||||
t.column("content", .text)
|
||||
}
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.create(virtualTable: "ft_documents", using: FTS5()) { t in
|
||||
t.synchronize(withTable: "documents")
|
||||
t.column("content")
|
||||
@@ -267,9 +267,9 @@ class FTS5TableBuilderTests: GRDBTestCase {
|
||||
try db.dropFTS5SynchronizationTriggers(forTable: "ft_documents")
|
||||
|
||||
// It is possible to modify the content table
|
||||
try db.execute(rawSQL: "UPDATE documents SET content = ?", arguments: ["bar"])
|
||||
try db.execute(rawSQL: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(rawSQL: "DELETE FROM documents WHERE content = ?", arguments: ["foo"])
|
||||
try db.execute(sql: "UPDATE documents SET content = ?", arguments: ["bar"])
|
||||
try db.execute(sql: "INSERT INTO documents (content) VALUES (?)", arguments: ["foo"])
|
||||
try db.execute(sql: "DELETE FROM documents WHERE content = ?", arguments: ["foo"])
|
||||
|
||||
// It is possible to recreate the FT table
|
||||
try db.create(virtualTable: "ft_documents", using: FTS5()) { t in
|
||||
|
||||
Loaded 100 of 188 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user