Remove availability checks for macOS 10.10 (forgotten in #719)

This commit is contained in:
Gwendal Roué committed 2020-03-08 19:08:15 +01:00
1 parent 41e0885bce
commit 00b0dc2a04
24 files changed
+265 -790

No files matched your search

+3 -10
View File
@@ -181,8 +181,8 @@ public struct Configuration {
///
/// The quality of service is ignored if you supply a target queue.
///
/// Default: .default (.unspecified on macOS < 10.10)
public var qos: DispatchQoS
/// Default: .default
public var qos: DispatchQoS = .default
/// The target queue for all database accesses.
///
@@ -200,14 +200,7 @@ public struct Configuration {
// MARK: - Factory Configuration
/// Creates a factory configuration
public init() {
if #available(OSX 10.10, *) {
qos = .default
} else {
qos = .unspecified
}
}
public init() { }
// MARK: - Not Public
-48
View File
@@ -423,48 +423,6 @@ public final class Database {
}
private static func closeConnection(_ sqliteConnection: SQLiteConnection) {
// sqlite3_close_v2 was added in SQLite 3.7.14 http://www.sqlite.org/changes.html#version_3_7_14
// It is available from iOS 8.2 and OS X 10.10
// https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
#if GRDBCUSTOMSQLITE || GRDBCIPHER
closeConnection_v2(sqliteConnection, sqlite3_close_v2)
#else
if #available(iOS 8.2, OSX 10.10, OSXApplicationExtension 10.10, *) {
closeConnection_v2(sqliteConnection, sqlite3_close_v2)
} else {
closeConnection_v1(sqliteConnection)
}
#endif
}
private static func closeConnection_v1(_ sqliteConnection: SQLiteConnection) {
// https://www.sqlite.org/c3ref/close.html
// > If the database connection is associated with unfinalized prepared
// > statements or unfinished sqlite3_backup objects then
// > sqlite3_close() will leave the database connection open and
// > return SQLITE_BUSY.
let code = sqlite3_close(sqliteConnection)
if code != SQLITE_OK, let log = logError {
// A rare situation where GRDB doesn't fatalError on
// unprocessed errors.
let message = String(cString: sqlite3_errmsg(sqliteConnection))
log(ResultCode(rawValue: code), "could not close database: \(message)")
if code == SQLITE_BUSY {
// Let the user know about unfinalized statements that did
// prevent the connection from closing properly.
var stmt: SQLiteStatement? = sqlite3_next_stmt(sqliteConnection, nil)
while stmt != nil {
log(ResultCode(rawValue: code), "unfinalized statement: \(String(cString: sqlite3_sql(stmt)))")
stmt = sqlite3_next_stmt(sqliteConnection, stmt)
}
}
}
}
private static func closeConnection_v2(
_ sqliteConnection: SQLiteConnection,
_ sqlite3_close_v2: @convention(c) (OpaquePointer?) -> Int32)
{
// https://www.sqlite.org/c3ref/close.html
// > If sqlite3_close_v2() is called with unfinalized prepared
// > statements and/or unfinished sqlite3_backups, then the database
@@ -545,9 +503,6 @@ public final class Database {
func beginReadOnly() throws {
if configuration.readonly { return }
if _readOnlyDepth == 0 {
// PRAGMA query_only was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
// It is available from iOS 8.2 and OS X 10.10
// https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
try internalCachedUpdateStatement(sql: "PRAGMA query_only = 1").execute()
}
_readOnlyDepth += 1
@@ -557,9 +512,6 @@ public final class Database {
if configuration.readonly { return }
_readOnlyDepth -= 1
if _readOnlyDepth == 0 {
// PRAGMA query_only was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
// It is available from iOS 8.2 and OS X 10.10
// https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
try internalCachedUpdateStatement(sql: "PRAGMA query_only = 0").execute()
}
}
-11
View File
@@ -159,18 +159,7 @@ public struct ResultCode: RawRepresentable, Equatable, CustomStringConvertible {
// CustomStringConvertible
extension ResultCode {
var errorString: String? {
// sqlite3_errstr was added in SQLite 3.7.15 http://www.sqlite.org/changes.html#version_3_7_15
// It is available from iOS 8.2 and OS X 10.10
// https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
#if GRDBCUSTOMSQLITE || GRDBCIPHER
return String(cString: sqlite3_errstr(rawValue))
#else
if #available(iOS 8.2, OSX 10.10, OSXApplicationExtension 10.10, *) {
return String(cString: sqlite3_errstr(rawValue))
} else {
return nil
}
#endif
}
/// :nodoc:
+2 -3
View File
@@ -365,9 +365,8 @@ extension DatabasePool: DatabaseReader {
/// }
/// }
///
/// Starting SQLite 3.8.0 (iOS 8.2+, OSX 10.10+, custom SQLite builds and
/// SQLCipher), attempts to write in the database from this method throw a
/// DatabaseError of resultCode `SQLITE_READONLY`.
/// Attempts to write in the database from this method throw a DatabaseError
/// of resultCode `SQLITE_READONLY`.
///
/// - parameter block: A block that accesses the database.
public func asyncRead(_ block: @escaping (Result<Database, Error>) -> Void) {
+4 -6
View File
@@ -189,9 +189,8 @@ extension DatabaseQueue {
///
/// This method is *not* reentrant.
///
/// Starting SQLite 3.8.0 (iOS 8.2+, OSX 10.10+, custom SQLite builds and
/// SQLCipher), attempts to write in the database from this method throw a
/// DatabaseError of resultCode `SQLITE_READONLY`.
/// Attempts to write in the database from this method throw a DatabaseError
/// of resultCode `SQLITE_READONLY`.
///
/// - parameter block: A block that accesses the database.
/// - throws: The error thrown by the block.
@@ -212,9 +211,8 @@ extension DatabaseQueue {
/// }
/// }
///
/// Starting SQLite 3.8.0 (iOS 8.2+, OSX 10.10+, custom SQLite builds and
/// SQLCipher), attempts to write in the database from this method throw a
/// DatabaseError of resultCode `SQLITE_READONLY`.
/// Attempts to write in the database from this method throw a DatabaseError
/// of resultCode `SQLITE_READONLY`.
///
/// - parameter block: A block that accesses the database.
public func asyncRead(_ block: @escaping (Result<Database, Error>) -> Void) {
+2 -4
View File
@@ -107,8 +107,7 @@ public protocol DatabaseReader: AnyObject {
/// let count = try Player.fetchCount(db)
/// }
///
/// Guarantee 2: Starting iOS 8.2, OSX 10.10, and with custom SQLite builds
/// and SQLCipher, attempts to write in the database throw a DatabaseError
/// Guarantee 2: attempts to write in the database throw a DatabaseError
/// whose resultCode is `SQLITE_READONLY`.
///
/// - parameter block: A block that accesses the database.
@@ -134,8 +133,7 @@ public protocol DatabaseReader: AnyObject {
/// }
/// }
///
/// Guarantee 2: Starting iOS 8.2, OSX 10.10, and with custom SQLite builds
/// and SQLCipher, attempts to write in the database throw a DatabaseError
/// Guarantee 2: attempts to write in the database throw a DatabaseError
/// whose resultCode is `SQLITE_READONLY`.
///
/// - parameter block: A block that accesses the database.
-44
View File
@@ -31,7 +31,6 @@ public struct FTS3Pattern {
self.rawPattern = rawPattern
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Creates a pattern that matches any token found in the input string;
/// returns nil if no pattern could be built.
///
@@ -70,49 +69,6 @@ public struct FTS3Pattern {
guard !tokens.isEmpty else { return nil }
try? self.init(rawPattern: "\"" + tokens.joined(separator: " ") + "\"")
}
#else
/// Creates a pattern that matches any token found in the input string;
/// returns nil if no pattern could be built.
///
/// FTS3Pattern(matchingAnyTokenIn: "") // nil
/// FTS3Pattern(matchingAnyTokenIn: "foo bar") // foo OR bar
///
/// - parameter string: The string to turn into an FTS3 pattern
@available(OSX 10.10, *)
public init?(matchingAnyTokenIn string: String) {
let tokens = FTS3TokenizerDescriptor.simple.tokenize(string)
guard !tokens.isEmpty else { return nil }
try? self.init(rawPattern: tokens.joined(separator: " OR "))
}
/// Creates a pattern that matches all tokens found in the input string;
/// returns nil if no pattern could be built.
///
/// FTS3Pattern(matchingAllTokensIn: "") // nil
/// FTS3Pattern(matchingAllTokensIn: "foo bar") // foo bar
///
/// - parameter string: The string to turn into an FTS3 pattern
@available(OSX 10.10, *)
public init?(matchingAllTokensIn string: String) {
let tokens = FTS3TokenizerDescriptor.simple.tokenize(string)
guard !tokens.isEmpty else { return nil }
try? self.init(rawPattern: tokens.joined(separator: " "))
}
/// Creates a pattern that matches a contiguous string; returns nil if no
/// pattern could be built.
///
/// FTS3Pattern(matchingPhrase: "") // nil
/// FTS3Pattern(matchingPhrase: "foo bar") // "foo bar"
///
/// - parameter string: The string to turn into an FTS3 pattern
@available(OSX 10.10, *)
public init?(matchingPhrase string: String) {
let tokens = FTS3TokenizerDescriptor.simple.tokenize(string)
guard !tokens.isEmpty else { return nil }
try? self.init(rawPattern: "\"" + tokens.joined(separator: " ") + "\"")
}
#endif
}
extension FTS3Pattern: DatabaseValueConvertible {
-40
View File
@@ -32,7 +32,6 @@ public struct FTS3TokenizerDescriptor {
/// See https://www.sqlite.org/fts3.html#tokenizer
public static let porter = FTS3TokenizerDescriptor("porter")
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// The "unicode61" tokenizer.
///
/// db.create(virtualTable: "book", using: FTS4()) { t in
@@ -56,35 +55,6 @@ public struct FTS3TokenizerDescriptor {
{
return _unicode61(diacritics: diacritics, separators: separators, tokenCharacters: tokenCharacters)
}
#else
/// The "unicode61" tokenizer.
///
/// db.create(virtualTable: "book", using: FTS4()) { t in
/// t.tokenizer = .unicode61()
/// }
///
/// - parameters:
/// - diacritics: By default SQLite will strip diacritics from
/// latin characters.
/// - separators: Unless empty (the default), SQLite will consider these
/// characters as token separators.
/// - tokenCharacters: Unless empty (the default), SQLite will consider
/// these characters as token characters.
///
/// See https://www.sqlite.org/fts3.html#tokenizer
@available(OSX 10.10, *)
public static func unicode61(
diacritics: FTS3.Diacritics = .removeLegacy,
separators: Set<Character> = [],
tokenCharacters: Set<Character> = [])
-> FTS3TokenizerDescriptor
{
// query_only pragma was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
// It is available from iOS 8.2 and OS X 10.10
// https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
return _unicode61(diacritics: diacritics, separators: separators, tokenCharacters: tokenCharacters)
}
#endif
private static func _unicode61(
diacritics: FTS3.Diacritics,
@@ -118,24 +88,14 @@ public struct FTS3TokenizerDescriptor {
return FTS3TokenizerDescriptor("unicode61", arguments: arguments)
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
func tokenize(_ string: String) -> [String] {
return _tokenize(string)
}
#else
@available(OSX 10.10, *)
func tokenize(_ string: String) -> [String] {
return _tokenize(string)
}
#endif
/// Returns an array of tokens found in the string argument.
///
/// FTS3TokenizerDescriptor.simple.tokenize("foo bar") // ["foo", "bar"]
private func _tokenize(_ string: String) -> [String] {
// fts3tokenize was introduced in SQLite 3.7.17 https://www.sqlite.org/changes.html#version_3_7_17
// It is available from iOS 8.2 and OS X 10.10
// https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
return DatabaseQueue().inDatabase { db in
var tokenizerChunks: [String] = []
tokenizerChunks.append(name)
-26
View File
@@ -261,7 +261,6 @@ public final class FTS4ColumnDefinition {
self.isLanguageId = false
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Excludes the column from the full-text index.
///
/// try db.create(virtualTable: "document", using: FTS4()) { t in
@@ -272,36 +271,11 @@ public final class FTS4ColumnDefinition {
/// See https://www.sqlite.org/fts3.html#the_notindexed_option
///
/// - returns: Self so that you can further refine the column definition.
/// :nodoc:
@discardableResult
public func notIndexed() -> Self {
// notindexed FTS4 option was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
// It is available from iOS 8.2 and OS X 10.10
// https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
self.isIndexed = false
return self
}
#else
/// Excludes the column from the full-text index.
///
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("a")
/// t.column("b").notIndexed()
/// }
///
/// See https://www.sqlite.org/fts3.html#the_notindexed_option
///
/// - returns: Self so that you can further refine the column definition.
@available(OSX 10.10, *)
@discardableResult
public func notIndexed() -> Self {
// notindexed FTS4 option was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
// It is available from iOS 8.2 and OS X 10.10
// https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
self.isIndexed = false
return self
}
#endif
/// Uses the column as the Int32 language id hidden column.
///
@@ -2,7 +2,6 @@ extension Database {
// MARK: - Database Schema
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Creates a database table.
///
/// try db.create(table: "place") { t in
@@ -42,88 +41,6 @@ extension Database {
let sql = try definition.sql(self)
try execute(sql: sql)
}
#else
/// Creates a database table.
///
/// try db.create(table: "place") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("title", .text)
/// t.column("favorite", .boolean).notNull().default(false)
/// t.column("longitude", .double).notNull()
/// t.column("latitude", .double).notNull()
/// }
///
/// See https://www.sqlite.org/lang_createtable.html and
/// https://www.sqlite.org/withoutrowid.html
///
/// - parameters:
/// - name: The table name.
/// - temporary: If true, creates a temporary table.
/// - ifNotExists: If false (the default), an error is thrown if the
/// table already exists. Otherwise, the table is created unless it
/// already exists.
/// - withoutRowID: If true, uses WITHOUT ROWID optimization.
/// - body: A closure that defines table columns and constraints.
/// - throws: A DatabaseError whenever an SQLite error occurs.
@available(OSX 10.10, *)
public func create(
table name: String,
temporary: Bool = false,
ifNotExists: Bool = false,
withoutRowID: Bool,
body: (TableDefinition) -> Void)
throws
{
// WITHOUT ROWID was added in SQLite 3.8.2 http://www.sqlite.org/changes.html#version_3_8_2
// 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 = TableDefinition(
name: name,
temporary: temporary,
ifNotExists: ifNotExists,
withoutRowID: withoutRowID)
body(definition)
let sql = try definition.sql(self)
try execute(sql: sql)
}
/// Creates a database table.
///
/// try db.create(table: "place") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("title", .text)
/// t.column("favorite", .boolean).notNull().default(false)
/// t.column("longitude", .double).notNull()
/// t.column("latitude", .double).notNull()
/// }
///
/// See https://www.sqlite.org/lang_createtable.html
///
/// - parameters:
/// - name: The table name.
/// - temporary: If true, creates a temporary table.
/// - ifNotExists: If false (the default), an error is thrown if the
/// table already exists. Otherwise, the table is created unless it
/// already exists.
/// - body: A closure that defines table columns and constraints.
/// - throws: A DatabaseError whenever an SQLite error occurs.
public func create(
table name: String,
temporary: Bool = false,
ifNotExists: Bool = false,
body: (TableDefinition) -> Void)
throws
{
let definition = TableDefinition(
name: name,
temporary: temporary,
ifNotExists: ifNotExists,
withoutRowID: false)
body(definition)
let sql = try definition.sql(self)
try execute(sql: sql)
}
#endif
/// Renames a database table.
///
@@ -162,7 +79,6 @@ extension Database {
try execute(sql: "DROP TABLE \(name.quotedDatabaseIdentifier)")
}
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Creates an index.
///
/// try db.create(index: "playerByEmail", on: "player", columns: ["email"])
@@ -192,9 +108,6 @@ extension Database {
condition: SQLExpressible? = nil)
throws
{
// Partial indexes were introduced in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
// 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,
@@ -205,85 +118,6 @@ extension Database {
let sql = definition.sql()
try execute(sql: sql)
}
#else
/// Creates an index.
///
/// try db.create(index: "playerByEmail", on: "player", columns: ["email"])
///
/// SQLite can also index expressions (https://www.sqlite.org/expridx.html)
/// and use specific collations. To create such an index, use a raw SQL
/// query.
///
/// try db.execute(sql: "CREATE INDEX ...")
///
/// See https://www.sqlite.org/lang_createindex.html
///
/// - parameters:
/// - name: The index name.
/// - table: The name of the indexed table.
/// - columns: The indexed columns.
/// - unique: If true, creates a unique index.
/// - ifNotExists: If false, no error is thrown if index already exists.
public func create(
index name: String,
on table: String,
columns: [String],
unique: Bool = false,
ifNotExists: Bool = false)
throws
{
// Partial indexes were introduced in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
// 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(sql: sql)
}
/// Creates a partial index.
///
/// try db.create(index: "playerByEmail", on: "player", columns: ["email"], condition: Column("email") != nil)
///
/// See https://www.sqlite.org/lang_createindex.html, and
/// https://www.sqlite.org/partialindex.html
///
/// - parameters:
/// - name: The index name.
/// - table: The name of the indexed table.
/// - columns: The indexed columns.
/// - unique: If true, creates a unique index.
/// - ifNotExists: If false, no error is thrown if index already exists.
/// - condition: The condition that indexed rows must verify.
@available(OSX 10.10, *)
public func create(
index name: String,
on table: String,
columns: [String],
unique: Bool = false,
ifNotExists: Bool = false,
condition: SQLExpressible)
throws
{
// Partial indexes were introduced in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
// 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(sql: sql)
}
#endif
/// Deletes a database index.
///
+1 -1
View File
@@ -1742,7 +1742,7 @@ When the same query will be used several times in the lifetime of your applicati
**Don't cache statements yourself.**
> :point_up: **Note**: This is because you don't have the necessary tools. Statements are tied to specific SQLite connections and dispatch queues which you don't manage yourself, especially when you use [database pools](#database-pools). A change in the database schema [may, or may not](https://www.sqlite.org/compile.html#max_schema_retry) invalidate a statement. On systems earlier than OSX 10.10 that don't have the [sqlite3_close_v2 function](https://www.sqlite.org/c3ref/close.html), SQLite connections won't close properly if statements have been kept alive.
> :point_up: **Note**: This is because you don't have the necessary tools. Statements are tied to specific SQLite connections and dispatch queues which you don't manage yourself, especially when you use [database pools](#database-pools). A change in the database schema [may, or may not](https://www.sqlite.org/compile.html#max_schema_retry) invalidate a statement.
Instead, use the `cachedUpdateStatement` and `cachedSelectStatement` methods. GRDB does all the hard caching and [memory management](#memory-management) stuff for you:
+13 -32
View File
@@ -8,14 +8,11 @@ import XCTest
class DatabaseErrorTests: GRDBTestCase {
func testDatabaseErrorMessage() {
// Error messages are not always available
if #available(iOS 8.2, OSX 10.10, OSXApplicationExtension 10.10, iOSApplicationExtension 8.2, *) {
// We don't test for actual messages, since they may depend on SQLite version
XCTAssertEqual(DatabaseError().resultCode, .SQLITE_ERROR)
XCTAssertNotNil(DatabaseError().message)
XCTAssertNotNil(DatabaseError(resultCode: .SQLITE_BUSY).message)
XCTAssertNotEqual(DatabaseError().message, DatabaseError(resultCode: .SQLITE_BUSY).message)
}
// We don't test for actual messages, since they may depend on SQLite version
XCTAssertEqual(DatabaseError().resultCode, .SQLITE_ERROR)
XCTAssertNotNil(DatabaseError().message)
XCTAssertNotNil(DatabaseError(resultCode: .SQLITE_BUSY).message)
XCTAssertNotEqual(DatabaseError().message, DatabaseError(resultCode: .SQLITE_BUSY).message)
}
func testDatabaseErrorInTransaction() throws {
@@ -30,9 +27,7 @@ class DatabaseErrorTests: GRDBTestCase {
return .commit
}
} 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)
XCTAssert((error.resultCode == error.extendedResultCode) || error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssert(error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssertEqual(error.resultCode, .SQLITE_CONSTRAINT)
XCTAssertEqual(error.message!.lowercased(), "foreign key constraint failed") // lowercased: accept multiple SQLite version
XCTAssertEqual(error.sql!, "INSERT INTO pets (masterId, name) VALUES (?, ?)")
@@ -67,9 +62,7 @@ class DatabaseErrorTests: GRDBTestCase {
}
}
} 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)
XCTAssert((error.resultCode == error.extendedResultCode) || error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssert(error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssertEqual(error.resultCode, .SQLITE_CONSTRAINT)
XCTAssertEqual(error.message!.lowercased(), "foreign key constraint failed") // lowercased: accept multiple SQLite version
XCTAssertEqual(error.sql!, "INSERT INTO pets (masterId, name) VALUES (?, ?)")
@@ -90,9 +83,7 @@ class DatabaseErrorTests: GRDBTestCase {
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
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
XCTAssert((error.resultCode == error.extendedResultCode) || error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssert(error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssertEqual(error.resultCode, .SQLITE_CONSTRAINT)
XCTAssertEqual(error.message!.lowercased(), "foreign key constraint failed") // lowercased: accept multiple SQLite version
XCTAssertEqual(error.sql!, "INSERT INTO pets (masterId, name) VALUES (?, ?)")
@@ -107,9 +98,7 @@ class DatabaseErrorTests: GRDBTestCase {
try statement.execute(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
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
XCTAssert((error.resultCode == error.extendedResultCode) || error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssert(error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssertEqual(error.resultCode, .SQLITE_CONSTRAINT)
XCTAssertEqual(error.message!.lowercased(), "foreign key constraint failed") // lowercased: accept multiple SQLite version
XCTAssertEqual(error.sql!, "INSERT INTO pets (masterId, name) VALUES (?, ?)")
@@ -125,9 +114,7 @@ class DatabaseErrorTests: GRDBTestCase {
try statement.execute()
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
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
XCTAssert((error.resultCode == error.extendedResultCode) || error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssert(error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssertEqual(error.resultCode, .SQLITE_CONSTRAINT)
XCTAssertEqual(error.message!.lowercased(), "foreign key constraint failed") // lowercased: accept multiple SQLite version
XCTAssertEqual(error.sql!, "INSERT INTO pets (masterId, name) VALUES (?, ?)")
@@ -147,9 +134,7 @@ class DatabaseErrorTests: GRDBTestCase {
""")
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
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
XCTAssert((error.resultCode == error.extendedResultCode) || error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssert(error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssertEqual(error.resultCode, .SQLITE_CONSTRAINT)
XCTAssertEqual(error.message!.lowercased(), "foreign key constraint failed") // lowercased: accept multiple SQLite version
XCTAssertEqual(error.sql!, "INSERT INTO pets (masterId, name) VALUES (1, 'Bobby')")
@@ -166,9 +151,7 @@ class DatabaseErrorTests: GRDBTestCase {
do {
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)
XCTAssert((error.resultCode == error.extendedResultCode) || error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssert(error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssertEqual(error.resultCode.rawValue, 19) // primary SQLITE_CONSTRAINT
}
}
@@ -184,9 +167,7 @@ class DatabaseErrorTests: GRDBTestCase {
} catch let error as NSError {
XCTAssertEqual(DatabaseError.errorDomain, "GRDB.DatabaseError")
XCTAssertEqual(error.domain, DatabaseError.errorDomain)
// 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)
XCTAssert([19, 787].contains(error.code))
XCTAssertEqual(error.code, 787)
}
}
}
+1 -8
View File
@@ -159,9 +159,7 @@ class DatabaseMigratorTests : GRDBTestCase {
// The first migration should be committed.
// The second migration should be rollbacked.
// 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)
XCTAssert((error.resultCode == error.extendedResultCode) || error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssert(error.extendedResultCode == .SQLITE_CONSTRAINT_FOREIGNKEY)
XCTAssertEqual(error.resultCode, .SQLITE_CONSTRAINT)
XCTAssertEqual(error.message!.lowercased(), "foreign key constraint failed") // lowercased: accept multiple SQLite version
@@ -173,11 +171,6 @@ class DatabaseMigratorTests : GRDBTestCase {
}
func testForeignKeyViolation() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
var migrator = DatabaseMigrator()
migrator.registerMigration("createPersons") { db in
try db.execute(sql: "CREATE TABLE persons (id INTEGER PRIMARY KEY, name TEXT, tmp TEXT)")
@@ -36,7 +36,6 @@ class DatabasePoolBackupTests: GRDBTestCase {
}
// TODO: fix flaky test
// @available(OSX 10.10, *)
// func testConcurrentWriteDuringBackup() throws {
// let source = try makeDatabasePool(filename: "source.sqlite")
// let destination = try makeDatabasePool(filename: "destination.sqlite")
@@ -1185,91 +1185,87 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
// MARK: - Barrier
func testBarrierLocksReads() throws {
if #available(OSX 10.10, *) {
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let dbPool = try makeDatabasePool()
try dbPool.write { db in
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
}
var fetchedValue: Int?
let s1 = DispatchSemaphore(value: 0)
let s2 = DispatchSemaphore(value: 0)
let s3 = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
try! dbPool.barrierWriteWithoutTransaction { db in
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
s1.signal()
s2.wait()
}
}
DispatchQueue.global().async {
// Wait for barrier to start
s1.wait()
fetchedValue = try! dbPool.read { db in
try Int.fetchOne(db, sql: "SELECT id FROM items")!
}
expectation.fulfill()
s3.signal()
}
// Assert that read is blocked
waitForExpectations(timeout: 1)
// Release barrier
s2.signal()
// Wait for read to complete
s3.wait()
XCTAssertEqual(fetchedValue, 1)
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let dbPool = try makeDatabasePool()
try dbPool.write { db in
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
}
var fetchedValue: Int?
let s1 = DispatchSemaphore(value: 0)
let s2 = DispatchSemaphore(value: 0)
let s3 = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
try! dbPool.barrierWriteWithoutTransaction { db in
try db.execute(sql: "INSERT INTO items (id) VALUES (NULL)")
s1.signal()
s2.wait()
}
}
DispatchQueue.global().async {
// Wait for barrier to start
s1.wait()
fetchedValue = try! dbPool.read { db in
try Int.fetchOne(db, sql: "SELECT id FROM items")!
}
expectation.fulfill()
s3.signal()
}
// Assert that read is blocked
waitForExpectations(timeout: 1)
// Release barrier
s2.signal()
// Wait for read to complete
s3.wait()
XCTAssertEqual(fetchedValue, 1)
}
func testBarrierIsLockedByOneUnfinishedRead() throws {
if #available(OSX 10.10, *) {
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let dbPool = try makeDatabasePool()
try dbPool.write { db in
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
}
let s1 = DispatchSemaphore(value: 0)
let s2 = DispatchSemaphore(value: 0)
let s3 = DispatchSemaphore(value: 0)
let s4 = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
try! dbPool.read { _ in
s1.signal()
s2.signal()
s3.wait()
}
}
DispatchQueue.global().async {
// Wait for read to start
s1.wait()
dbPool.barrierWriteWithoutTransaction { _ in }
expectation.fulfill()
s4.signal()
}
// Assert that barrier is blocked
waitForExpectations(timeout: 1)
// Release read
s3.signal()
// Wait for barrier to complete
s4.wait()
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let dbPool = try makeDatabasePool()
try dbPool.write { db in
try db.execute(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)")
}
let s1 = DispatchSemaphore(value: 0)
let s2 = DispatchSemaphore(value: 0)
let s3 = DispatchSemaphore(value: 0)
let s4 = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
try! dbPool.read { _ in
s1.signal()
s2.signal()
s3.wait()
}
}
DispatchQueue.global().async {
// Wait for read to start
s1.wait()
dbPool.barrierWriteWithoutTransaction { _ in }
expectation.fulfill()
s4.signal()
}
// Assert that barrier is blocked
waitForExpectations(timeout: 1)
// Release read
s3.signal()
// Wait for barrier to complete
s4.wait()
}
// MARK: - Concurrent opening
-8
View File
@@ -266,14 +266,6 @@ class DatabaseTests : GRDBTestCase {
}
func testFailedCommitIsRollbacked() throws {
// PRAGMA defer_foreign_keys = ON was introduced in SQLite 3.12.0 http://www.sqlite.org/changes.html#version_3_8_0
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.execute(sql: "CREATE TABLE parent (id INTEGER PRIMARY KEY)")
-18
View File
@@ -70,12 +70,6 @@ class FTS3PatternTests: GRDBTestCase {
}
func testFTS3PatternWithAnyToken() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let wrongInputs = ["", "*", "^", " ", "(", "()", "\"", "?!"]
for string in wrongInputs {
if let pattern = FTS3Pattern(matchingAnyTokenIn: string) {
@@ -106,12 +100,6 @@ class FTS3PatternTests: GRDBTestCase {
}
func testFTS3PatternWithAllTokens() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let wrongInputs = ["", "*", "^", " ", "(", "()", "\"", "?!"]
for string in wrongInputs {
if let pattern = FTS3Pattern(matchingAllTokensIn: string) {
@@ -142,12 +130,6 @@ class FTS3PatternTests: GRDBTestCase {
}
func testFTS3PatternWithPhrase() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let wrongInputs = ["", "*", "^", " ", "(", "()", "\"", "?!"]
for string in wrongInputs {
if let pattern = FTS3Pattern(matchingPhrase: string) {
@@ -61,12 +61,6 @@ class FTS3TableBuilderTests: GRDBTestCase {
}
func testUnicode61Tokenizer() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS3()) { t in
@@ -77,12 +71,6 @@ class FTS3TableBuilderTests: GRDBTestCase {
}
func testUnicode61TokenizerDiacriticsKeep() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS3()) { t in
@@ -105,12 +93,6 @@ class FTS3TableBuilderTests: GRDBTestCase {
#endif
func testUnicode61TokenizerSeparators() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS3()) { t in
@@ -121,12 +103,6 @@ class FTS3TableBuilderTests: GRDBTestCase {
}
func testUnicode61TokenizerTokenCharacters() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS3()) { t in
-24
View File
@@ -58,12 +58,6 @@ class FTS3TokenizerTests: GRDBTestCase {
}
func testUnicode61Tokenizer() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS3()) { t in
@@ -85,12 +79,6 @@ class FTS3TokenizerTests: GRDBTestCase {
}
func testUnicode61TokenizerDiacriticsKeep() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS3()) { t in
@@ -135,12 +123,6 @@ class FTS3TokenizerTests: GRDBTestCase {
#endif
func testUnicode61TokenizerSeparators() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS3()) { t in
@@ -155,12 +137,6 @@ class FTS3TokenizerTests: GRDBTestCase {
}
func testUnicode61TokenizerTokenCharacters() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS3()) { t in
+1 -30
View File
@@ -61,12 +61,6 @@ class FTS4TableBuilderTests: GRDBTestCase {
}
func testUnicode61Tokenizer() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS4()) { t in
@@ -77,12 +71,6 @@ class FTS4TableBuilderTests: GRDBTestCase {
}
func testUnicode61TokenizerDiacriticsKeep() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS4()) { t in
@@ -92,6 +80,7 @@ class FTS4TableBuilderTests: GRDBTestCase {
}
}
// TODO: why only custom SQLite build?
#if GRDBCUSTOMSQLITE
func testUnicode61TokenizerDiacriticsRemove() throws {
let dbQueue = try makeDatabaseQueue()
@@ -105,12 +94,6 @@ class FTS4TableBuilderTests: GRDBTestCase {
#endif
func testUnicode61TokenizerSeparators() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS4()) { t in
@@ -121,12 +104,6 @@ class FTS4TableBuilderTests: GRDBTestCase {
}
func testUnicode61TokenizerTokenCharacters() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS4()) { t in
@@ -156,12 +133,6 @@ class FTS4TableBuilderTests: GRDBTestCase {
}
func testNotIndexedColumns() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "books", using: FTS4()) { t in
+155 -165
View File
@@ -67,188 +67,178 @@ class PoolTests: XCTestCase {
}
func testBarrierLocksElements() throws {
if #available(OSX 10.10, *) {
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let pool = makeCounterPool(maximumCount: 1)
var element: Int?
let s1 = DispatchSemaphore(value: 0)
let s2 = DispatchSemaphore(value: 0)
let s3 = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
pool.barrier {
s1.signal()
s2.wait()
}
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let pool = makeCounterPool(maximumCount: 1)
var element: Int?
let s1 = DispatchSemaphore(value: 0)
let s2 = DispatchSemaphore(value: 0)
let s3 = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
pool.barrier {
s1.signal()
s2.wait()
}
DispatchQueue.global().async {
// Wait for barrier to start
s1.wait()
let first = try! pool.get()
element = first.element
first.release()
expectation.fulfill()
s3.signal()
}
// Assert that get() is blocked
waitForExpectations(timeout: 1)
// Release barrier
s2.signal()
// Wait for get() to complete
s3.wait()
XCTAssertEqual(element, 1)
}
DispatchQueue.global().async {
// Wait for barrier to start
s1.wait()
let first = try! pool.get()
element = first.element
first.release()
expectation.fulfill()
s3.signal()
}
// Assert that get() is blocked
waitForExpectations(timeout: 1)
// Release barrier
s2.signal()
// Wait for get() to complete
s3.wait()
XCTAssertEqual(element, 1)
}
func testBarrierIsLockedByOneUsedElementOutOfOne() throws {
if #available(OSX 10.10, *) {
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let pool = makeCounterPool(maximumCount: 1)
// Get element
let first = try pool.get()
XCTAssertEqual(first.element, 1)
let s = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
pool.barrier { }
expectation.fulfill()
s.signal()
}
// Assert that barrier is blocked
waitForExpectations(timeout: 1)
// Release element
first.release()
// Wait for barrier to complete
s.wait()
// Get and release recycled element
let second = try pool.get()
XCTAssertEqual(second.element, 1)
second.release()
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let pool = makeCounterPool(maximumCount: 1)
// Get element
let first = try pool.get()
XCTAssertEqual(first.element, 1)
let s = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
pool.barrier { }
expectation.fulfill()
s.signal()
}
// Assert that barrier is blocked
waitForExpectations(timeout: 1)
// Release element
first.release()
// Wait for barrier to complete
s.wait()
// Get and release recycled element
let second = try pool.get()
XCTAssertEqual(second.element, 1)
second.release()
}
func testBarrierIsLockedByOneUsedElementOutOfTwo() throws {
if #available(OSX 10.10, *) {
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let pool = makeCounterPool(maximumCount: 2)
// Get elements
let first = try pool.get()
XCTAssertEqual(first.element, 1)
let second = try pool.get()
XCTAssertEqual(second.element, 2)
// Release first element
first.release()
let s = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
pool.barrier { }
expectation.fulfill()
s.signal()
}
// Assert that barrier is blocked
waitForExpectations(timeout: 1)
// Release second element
second.release()
// Wait for barrier to complete
s.wait()
// Get and release recycled element
let third = try pool.get()
XCTAssertEqual(third.element, 1)
third.release()
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let pool = makeCounterPool(maximumCount: 2)
// Get elements
let first = try pool.get()
XCTAssertEqual(first.element, 1)
let second = try pool.get()
XCTAssertEqual(second.element, 2)
// Release first element
first.release()
let s = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
pool.barrier { }
expectation.fulfill()
s.signal()
}
// Assert that barrier is blocked
waitForExpectations(timeout: 1)
// Release second element
second.release()
// Wait for barrier to complete
s.wait()
// Get and release recycled element
let third = try pool.get()
XCTAssertEqual(third.element, 1)
third.release()
}
func testBarrierIsLockedByTwoUsedElementsOutOfTwo() throws {
if #available(OSX 10.10, *) {
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let pool = makeCounterPool(maximumCount: 2)
// Get elements
let first = try pool.get()
XCTAssertEqual(first.element, 1)
let second = try pool.get()
XCTAssertEqual(second.element, 2)
let s = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
pool.barrier { }
expectation.fulfill()
s.signal()
}
// Assert that barrier is blocked
waitForExpectations(timeout: 1)
// Release elements
first.release()
second.release()
// Wait for barrier to complete
s.wait()
// Get and release recycled element
let third = try pool.get()
XCTAssertEqual(third.element, 1)
third.release()
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let pool = makeCounterPool(maximumCount: 2)
// Get elements
let first = try pool.get()
XCTAssertEqual(first.element, 1)
let second = try pool.get()
XCTAssertEqual(second.element, 2)
let s = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
pool.barrier { }
expectation.fulfill()
s.signal()
}
// Assert that barrier is blocked
waitForExpectations(timeout: 1)
// Release elements
first.release()
second.release()
// Wait for barrier to complete
s.wait()
// Get and release recycled element
let third = try pool.get()
XCTAssertEqual(third.element, 1)
third.release()
}
func testBarrierRemoveAll() throws {
if #available(OSX 10.10, *) {
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let pool = makeCounterPool(maximumCount: 1)
// Get element
let first = try pool.get()
XCTAssertEqual(first.element, 1)
let s = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
// No deadlock
pool.barrier { pool.removeAll() }
expectation.fulfill()
s.signal()
}
// Assert that barrier is blocked
waitForExpectations(timeout: 1)
// Release element
first.release()
// Wait for barrier to complete
s.wait()
// Get and release new element
let second = try pool.get()
XCTAssertEqual(second.element, 2)
second.release()
let expectation = self.expectation(description: "lock")
expectation.isInverted = true
let pool = makeCounterPool(maximumCount: 1)
// Get element
let first = try pool.get()
XCTAssertEqual(first.element, 1)
let s = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
// No deadlock
pool.barrier { pool.removeAll() }
expectation.fulfill()
s.signal()
}
// Assert that barrier is blocked
waitForExpectations(timeout: 1)
// Release element
first.release()
// Wait for barrier to complete
s.wait()
// Get and release new element
let second = try pool.get()
XCTAssertEqual(second.element, 2)
second.release()
}
}
+7 -24
View File
@@ -35,25 +35,14 @@ class TableDefinitionTests: GRDBTestCase {
func testTableCreationOptions() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
if #available(iOS 8.2, OSX 10.10, *) {
try db.create(table: "test", temporary: true, ifNotExists: true, withoutRowID: true) { t in
t.column("id", .integer).primaryKey()
}
assertEqualSQL(
lastSQLQuery,
("CREATE TEMPORARY TABLE IF NOT EXISTS \"test\" (" +
"\"id\" INTEGER PRIMARY KEY" +
") WITHOUT ROWID") as String)
} else {
try db.create(table: "test", temporary: true, ifNotExists: true) { t in
t.column("id", .integer).primaryKey()
}
assertEqualSQL(
lastSQLQuery,
("CREATE TEMPORARY TABLE IF NOT EXISTS \"test\" (" +
"\"id\" INTEGER PRIMARY KEY" +
")") as String)
try db.create(table: "test", temporary: true, ifNotExists: true, withoutRowID: true) { t in
t.column("id", .integer).primaryKey()
}
assertEqualSQL(
lastSQLQuery,
("CREATE TEMPORARY TABLE IF NOT EXISTS \"test\" (" +
"\"id\" INTEGER PRIMARY KEY" +
") WITHOUT ROWID") as String)
}
}
@@ -568,12 +557,6 @@ class TableDefinitionTests: GRDBTestCase {
}
func testCreatePartialIndex() throws {
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "test") { t in
@@ -50,7 +50,6 @@ class ValueObservationSchedulingTests: GRDBTestCase {
try test(makeDatabasePool())
}
@available(OSX 10.10, *) // DispatchQueue qos
func testMainQueueObservationStartedFromAnotherQueue() throws {
func test(_ dbWriter: DatabaseWriter) throws {
// We need something to change
@@ -49,14 +49,6 @@ private final class FTS3TokenizeTableDefinition {
class VirtualTableModuleTests: GRDBTestCase {
func testCustomVirtualTableModule() throws {
// fts3tokenize was introduced in SQLite 3.7.17 https://www.sqlite.org/changes.html#version_3_7_17
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "test", using: FTS3TokenizeModule()) { t in
@@ -68,14 +60,6 @@ class VirtualTableModuleTests: GRDBTestCase {
}
func testThrowingCustomVirtualTableModule() throws {
// fts3tokenize was introduced in SQLite 3.7.17 https://www.sqlite.org/changes.html#version_3_7_17
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
#if !GRDBCUSTOMSQLITE && !GRDBCIPHER
guard #available(iOS 8.2, OSX 10.10, *) else {
return
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
do {