From cf128ac800e335d4b37b10ee43e01f8828eab9b7 Mon Sep 17 00:00:00 2001 From: Marcel Ball Date: Wed, 25 Jul 2018 17:24:57 -0300 Subject: [PATCH 01/29] Added configuration option to set cipher_page_size on connection * Defaults to 1024 - which is the default in SQLCipher --- GRDB/Core/Configuration.swift | 12 ++++++++++++ GRDB/Core/Database.swift | 16 ++++++++++++++++ Tests/GRDBTests/EncryptionTests.swift | 24 ++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/GRDB/Core/Configuration.swift b/GRDB/Core/Configuration.swift index fac576893..78e19c19e 100644 --- a/GRDB/Core/Configuration.swift +++ b/GRDB/Core/Configuration.swift @@ -81,6 +81,18 @@ public struct Configuration { /// /// Default: nil public var passphrase: String? + + public enum CipherPageSize: Int { + case ps1024 = 1024 + case ps2048 = 2048 + case ps4096 = 4096 + case ps8192 = 8192 + case ps16384 = 16384 + case ps32768 = 32768 + case ps65536 = 65536 + } + + public var cipherPageSize: CipherPageSize = .ps1024 #endif diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 8d50b0dcf..f71f2c729 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -173,6 +173,7 @@ public final class Database { try Database.validateSQLCipher(sqliteConnection) if let passphrase = configuration.passphrase { try Database.set(passphrase: passphrase, forConnection: sqliteConnection) + try Database.set(cipherPageSize: configuration.cipherPageSize, forConnection: sqliteConnection) } #endif try Database.validateDatabaseFormat(sqliteConnection) @@ -261,6 +262,21 @@ extension Database { throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) } } + + private static func set(cipherPageSize: Configuration.CipherPageSize, forConnection sqliteConnection: SQLiteConnection) throws { + var sqliteStatement: SQLiteStatement? = nil + let code = sqlite3_prepare_v2(sqliteConnection, "PRAGMA cipher_page_size = \(cipherPageSize.rawValue)", -1, &sqliteStatement, nil) + guard code == SQLITE_OK else { + throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) + } + defer { + sqlite3_finalize(sqliteStatement) + } + let step = sqlite3_step(sqliteStatement) + if step != SQLITE_DONE { + throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "Unable to set cipher_page_size") + } + } #endif private static func validateDatabaseFormat(_ sqliteConnection: SQLiteConnection) throws { diff --git a/Tests/GRDBTests/EncryptionTests.swift b/Tests/GRDBTests/EncryptionTests.swift index bfe96d34a..d21ba8ea7 100644 --- a/Tests/GRDBTests/EncryptionTests.swift +++ b/Tests/GRDBTests/EncryptionTests.swift @@ -333,6 +333,30 @@ class EncryptionTests: GRDBTestCase { } } + func testCipherPageSize() throws { + do { + dbConfiguration.passphrase = "secret" + dbConfiguration.cipherPageSize = .ps8192 + + let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") + try dbQueue.inDatabase({ db in + XCTAssertEqual(try Int.fetchOne(db, "PRAGMA cipher_page_size")!, 8192) + }) + } + + do { + dbConfiguration.cipherPageSize = .ps4096 + + let dbQueue = try makeDatabasePool(filename: "testpool.sqlite") + try dbQueue.read({ db in + XCTAssertEqual(try Int.fetchOne(db, "PRAGMA cipher_page_size")!, 4096) + }) + try dbQueue.write({ db in + XCTAssertEqual(try Int.fetchOne(db, "PRAGMA cipher_page_size")!, 4096) + }) + } + } + func testExportPlainTextDatabaseToEncryptedDatabase() throws { // See https://discuss.zetetic.net/t/how-to-encrypt-a-plaintext-sqlite-database-to-use-sqlcipher-and-avoid-file-is-encrypted-or-is-not-a-database-errors/868?source_topic_id=939 do { From 4aecad36492d544fbd7076b0754419f921d15bce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 6 Mar 2019 21:58:36 +0100 Subject: [PATCH 02/29] Failing test for https://github.com/groue/GRDB.swift/issues/495 --- .../AssociationBelongsToSQLTests.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Tests/GRDBTests/AssociationBelongsToSQLTests.swift b/Tests/GRDBTests/AssociationBelongsToSQLTests.swift index 3f619c67b..97af38506 100644 --- a/Tests/GRDBTests/AssociationBelongsToSQLTests.swift +++ b/Tests/GRDBTests/AssociationBelongsToSQLTests.swift @@ -873,4 +873,22 @@ class AssociationBelongsToSQLTests: GRDBTestCase { static let parent2 = belongsTo(Parent.self, using: ForeignKeys.parent2) } } + + // Regression test for https://github.com/groue/GRDB.swift/issues/495 + func testFetchCount() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.create(table: "a") { t in + t.autoIncrementedPrimaryKey("id") + } + try db.create(table: "b") { t in + t.autoIncrementedPrimaryKey("id") + t.column("aId", .integer).references("a") + } + struct A: TableRecord { } + struct B: TableRecord { } + let request = B.joining(required: B.belongsTo(A.self)) + let _ = try request.fetchCount(db) + } + } } From 8fbc3ca8752685d5140eda64f3caf494f838c99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 6 Mar 2019 22:09:01 +0100 Subject: [PATCH 03/29] From future import OrderedDictionary --- GRDB/QueryInterface/SQLRelation.swift | 10 ++-- GRDB/Utils/OrderedDictionary.swift | 79 +++++++++++++++++++++------ 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/GRDB/QueryInterface/SQLRelation.swift b/GRDB/QueryInterface/SQLRelation.swift index 7187abdb1..144d91185 100644 --- a/GRDB/QueryInterface/SQLRelation.swift +++ b/GRDB/QueryInterface/SQLRelation.swift @@ -81,9 +81,9 @@ extension SQLRelation { // can't merge fatalError("The association key \"\(key)\" is ambiguous. Use the Association.forKey(_:) method is order to disambiguate.") } - relation.joins.append(value: mergedJoin, forKey: key) + relation.joins.appendValue(mergedJoin, forKey: key) } else { - relation.joins.append(value: join, forKey: key) + relation.joins.appendValue(join, forKey: key) } return relation } @@ -390,13 +390,13 @@ extension SQLRelation { // can't merge return nil } - mergedJoins.append(value: mergedJoin, forKey: key) + mergedJoins.appendValue(mergedJoin, forKey: key) } else { - mergedJoins.append(value: join, forKey: key) + mergedJoins.appendValue(join, forKey: key) } } for (key, join) in other.joins where mergedJoins[key] == nil { - mergedJoins.append(value: join, forKey: key) + mergedJoins.appendValue(join, forKey: key) } // replace selection unless empty diff --git a/GRDB/Utils/OrderedDictionary.swift b/GRDB/Utils/OrderedDictionary.swift index c4fb38609..d6a6a7ab4 100644 --- a/GRDB/Utils/OrderedDictionary.swift +++ b/GRDB/Utils/OrderedDictionary.swift @@ -9,37 +9,74 @@ /// dict["qux"] // nil /// dict.map { $0.key } // ["foo", "bar"], in this order. struct OrderedDictionary { - private var keys: [Key] - private var values: [Key: Value] + private(set) var keys: [Key] + private(set) var dictionary: [Key: Value] + + var values: [Value] { + return keys.map { dictionary[$0]! } + } /// Creates an empty ordered dictionary. init() { - self.keys = [] - self.values = [:] + keys = [] + dictionary = [:] + } + + /// Creates an empty ordered dictionary. + init(minimumCapacity: Int) { + keys = [] + keys.reserveCapacity(minimumCapacity) + dictionary = Dictionary(minimumCapacity: minimumCapacity) } /// Returns the value associated with key, or nil. + @inlinable subscript(_ key: Key) -> Value? { - return values[key] + get { return dictionary[key] } + set { + if let value = newValue { + updateValue(value, forKey: key) + } else { + removeValue(forKey: key) + } + } } /// Appends the given value for the given key. /// /// - precondition: There is no value associated with key yet. - mutating func append(value: Value, forKey key: Key) { - guard values.updateValue(value, forKey: key) == nil else { + mutating func appendValue(_ value: Value, forKey key: Key) { + guard updateValue(value, forKey: key) == nil else { fatalError("key is already defined") } + } + + /// Updates the value stored in the dictionary for the given key, or + /// appnds a new key-value pair if the key does not exist. + /// + /// Use this method instead of key-based subscripting when you need to know + /// whether the new value supplants the value of an existing key. If the + /// value of an existing key is updated, updateValue(_:forKey:) returns the + /// original value. If the given key is not present in the dictionary, this + /// method appends the key-value pair and returns nil. + @discardableResult + @inlinable + mutating func updateValue(_ value: Value, forKey key: Key) -> Value? { + if let oldValue = dictionary.updateValue(value, forKey: key) { + return oldValue + } keys.append(key) + return nil } /// Removes the value associated with key. @discardableResult + @usableFromInline mutating func removeValue(forKey key: Key) -> Value? { - guard let value = values.removeValue(forKey: key) else { + guard let value = dictionary.removeValue(forKey: key) else { return nil } - let index = keys.index { $0 == key }! + let index = keys.firstIndex { $0 == key }! keys.remove(at: index) return value } @@ -48,35 +85,41 @@ struct OrderedDictionary { /// with the values transformed by the given closure. func mapValues(_ transform: (Value) throws -> T) rethrows -> OrderedDictionary { return try reduce(into: OrderedDictionary()) { dict, pair in - dict.append(value: try transform(pair.value), forKey: pair.key) + dict.appendValue(try transform(pair.value), forKey: pair.key) } } } extension OrderedDictionary: Collection { - typealias Index = Int + @usableFromInline typealias Index = Int - var startIndex: Int { + @usableFromInline var startIndex: Int { return 0 } - var endIndex: Int { + @usableFromInline var endIndex: Int { return keys.count } - func index(after i: Int) -> Int { + @usableFromInline func index(after i: Int) -> Int { return i + 1 } - subscript(position: Int) -> (key: Key, value: Value) { + @usableFromInline subscript(position: Int) -> (key: Key, value: Value) { let key = keys[position] - return (key: key, value: values[key]!) + return (key: key, value: dictionary[key]!) } } extension OrderedDictionary: ExpressibleByDictionaryLiteral { - init(dictionaryLiteral elements: (Key, Value)...) { + @usableFromInline init(dictionaryLiteral elements: (Key, Value)...) { self.keys = elements.map { $0.0 } - self.values = Dictionary(uniqueKeysWithValues: elements) + self.dictionary = Dictionary(uniqueKeysWithValues: elements) + } +} + +extension Dictionary { + init(_ orderedDictionary: OrderedDictionary) { + self = orderedDictionary.dictionary } } From ee481b2327c457884d8a39be77758b95de21a2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 6 Mar 2019 22:09:31 +0100 Subject: [PATCH 04/29] Fix #495 --- .../QueryInterface/SQLGenerationContext.swift | 9 +++++-- .../SQLSelectQueryGenerator.swift | 16 ++++++++++-- .../SQLSelectable+QueryInterface.swift | 25 ++++++++++++++++--- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/GRDB/QueryInterface/SQLGenerationContext.swift b/GRDB/QueryInterface/SQLGenerationContext.swift index 7a98561dd..a28be67ad 100644 --- a/GRDB/QueryInterface/SQLGenerationContext.swift +++ b/GRDB/QueryInterface/SQLGenerationContext.swift @@ -19,10 +19,15 @@ public struct SQLGenerationContext { /// Used for SQLSelectQuery.makeSelectStatement() and SQLSelectQuery.makeDeleteStatement() static func queryGenerationContext(aliases: [TableAlias]) -> SQLGenerationContext { + let uniqueAliases = aliases.reduce(into: [TableAlias]()) { + if !$0.contains($1) { + $0.append($1) + } + } return SQLGenerationContext( arguments: [], - resolvedNames: aliases.resolvedNames, - qualifierNeeded: aliases.count > 1) + resolvedNames: uniqueAliases.resolvedNames, + qualifierNeeded: uniqueAliases.count > 1) } /// Used for TableRecord.selectionSQL diff --git a/GRDB/QueryInterface/SQLSelectQueryGenerator.swift b/GRDB/QueryInterface/SQLSelectQueryGenerator.swift index edf3c3571..977786d19 100644 --- a/GRDB/QueryInterface/SQLSelectQueryGenerator.swift +++ b/GRDB/QueryInterface/SQLSelectQueryGenerator.swift @@ -224,9 +224,12 @@ private struct SQLQualifiedRelation { /// All aliases, including aliases of joined relations var allAliases: [TableAlias] { - return joins.reduce(into: [alias]) { - $0.append(contentsOf: $1.value.relation.allAliases) + var aliases = [alias] + for join in joins.values { + aliases.append(contentsOf: join.relation.allAliases) } + aliases.append(contentsOf: source.allAliases) + return aliases } /// The source @@ -366,6 +369,15 @@ private enum SQLQualifiedSource { } } + var allAliases: [TableAlias] { + switch self { + case .table(_, let alias): + return [alias] + case .query(let query): + return query.relation.allAliases + } + } + init(_ source: SQLSource) { switch source { case .table(let tableName, let alias): diff --git a/GRDB/QueryInterface/SQLSelectable+QueryInterface.swift b/GRDB/QueryInterface/SQLSelectable+QueryInterface.swift index 411b88829..08fbe4c48 100644 --- a/GRDB/QueryInterface/SQLSelectable+QueryInterface.swift +++ b/GRDB/QueryInterface/SQLSelectable+QueryInterface.swift @@ -78,10 +78,27 @@ extension QualifiedAllColumns : SQLSelectable { } func countedSQL(_ context: inout SQLGenerationContext) -> String { - if context.qualifier(for: alias) != nil { - // SELECT COUNT(t.*) is invalid SQL - fatalError("Not implemented, or invalid query") - } + // TODO: restore the check below. + // + // It is currently disabled because of AssociationAggregateTests.testHasManyIsEmpty: + // + // let request = Team.having(Team.players.isEmpty) + // try XCTAssertEqual(request.fetchCount(db), 1) + // + // This should build the trivial count query `SELECT COUNT(*) FROM (SELECT ...)` + // + // Unfortunately, we don't support anonymous table aliases that would be + // required here. Because we don't support anonymous tables aliases, + // everything happens as if we wanted to generate + // `SELECT COUNT(team.*) FROM (SELECT ...)`, which is invalid SQL. + // + // So let's always return `*`, and fix this later. + +// if context.qualifier(for: alias) != nil { +// // SELECT COUNT(t.*) is invalid SQL +// fatalError("Not implemented, or invalid query") +// } + return "*" } From 5bed0ac58ec9bf9cd76c00afdb3c37b21284c55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 6 Mar 2019 22:12:54 +0100 Subject: [PATCH 05/29] Too much future --- GRDB/Utils/OrderedDictionary.swift | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/GRDB/Utils/OrderedDictionary.swift b/GRDB/Utils/OrderedDictionary.swift index d6a6a7ab4..e0a5207ed 100644 --- a/GRDB/Utils/OrderedDictionary.swift +++ b/GRDB/Utils/OrderedDictionary.swift @@ -30,7 +30,6 @@ struct OrderedDictionary { } /// Returns the value associated with key, or nil. - @inlinable subscript(_ key: Key) -> Value? { get { return dictionary[key] } set { @@ -60,7 +59,6 @@ struct OrderedDictionary { /// original value. If the given key is not present in the dictionary, this /// method appends the key-value pair and returns nil. @discardableResult - @inlinable mutating func updateValue(_ value: Value, forKey key: Key) -> Value? { if let oldValue = dictionary.updateValue(value, forKey: key) { return oldValue @@ -71,7 +69,6 @@ struct OrderedDictionary { /// Removes the value associated with key. @discardableResult - @usableFromInline mutating func removeValue(forKey key: Key) -> Value? { guard let value = dictionary.removeValue(forKey: key) else { return nil @@ -91,28 +88,28 @@ struct OrderedDictionary { } extension OrderedDictionary: Collection { - @usableFromInline typealias Index = Int + typealias Index = Int - @usableFromInline var startIndex: Int { + var startIndex: Int { return 0 } - @usableFromInline var endIndex: Int { + var endIndex: Int { return keys.count } - @usableFromInline func index(after i: Int) -> Int { + func index(after i: Int) -> Int { return i + 1 } - @usableFromInline subscript(position: Int) -> (key: Key, value: Value) { + subscript(position: Int) -> (key: Key, value: Value) { let key = keys[position] return (key: key, value: dictionary[key]!) } } extension OrderedDictionary: ExpressibleByDictionaryLiteral { - @usableFromInline init(dictionaryLiteral elements: (Key, Value)...) { + init(dictionaryLiteral elements: (Key, Value)...) { self.keys = elements.map { $0.0 } self.dictionary = Dictionary(uniqueKeysWithValues: elements) } From d566838dc55cf8477b88cb22c534f5eb913e6852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 6 Mar 2019 22:22:35 +0100 Subject: [PATCH 06/29] Restore missing comment --- GRDB/QueryInterface/SQLGenerationContext.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/GRDB/QueryInterface/SQLGenerationContext.swift b/GRDB/QueryInterface/SQLGenerationContext.swift index a28be67ad..6a42c4790 100644 --- a/GRDB/QueryInterface/SQLGenerationContext.swift +++ b/GRDB/QueryInterface/SQLGenerationContext.swift @@ -19,6 +19,7 @@ public struct SQLGenerationContext { /// Used for SQLSelectQuery.makeSelectStatement() and SQLSelectQuery.makeDeleteStatement() static func queryGenerationContext(aliases: [TableAlias]) -> SQLGenerationContext { + // Unique aliases, but with preserved ordering, so that we have stable SQL generation let uniqueAliases = aliases.reduce(into: [TableAlias]()) { if !$0.contains($1) { $0.append($1) From 090eea99233ea7f3e905bc6e17f6d963a9f5739e Mon Sep 17 00:00:00 2001 From: Marcel Ball Date: Wed, 6 Mar 2019 20:41:01 -0400 Subject: [PATCH 07/29] Update naming for the enumeration to be clearer --- GRDB/Core/Configuration.swift | 16 ++++++++-------- Tests/GRDBTests/EncryptionTests.swift | 16 +++++++++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/GRDB/Core/Configuration.swift b/GRDB/Core/Configuration.swift index 78e19c19e..0fb00fe42 100644 --- a/GRDB/Core/Configuration.swift +++ b/GRDB/Core/Configuration.swift @@ -83,16 +83,16 @@ public struct Configuration { public var passphrase: String? public enum CipherPageSize: Int { - case ps1024 = 1024 - case ps2048 = 2048 - case ps4096 = 4096 - case ps8192 = 8192 - case ps16384 = 16384 - case ps32768 = 32768 - case ps65536 = 65536 + case pageSize1K = 1024 + case pageSize2K = 2048 + case pageSize4K = 4096 + case pageSize8K = 8192 + case pageSize16K = 16384 + case pageSize32K = 32768 + case pageSize64K = 65536 } - public var cipherPageSize: CipherPageSize = .ps1024 + public var cipherPageSize: CipherPageSize = .pageSize1K #endif diff --git a/Tests/GRDBTests/EncryptionTests.swift b/Tests/GRDBTests/EncryptionTests.swift index d21ba8ea7..ac69d6c64 100644 --- a/Tests/GRDBTests/EncryptionTests.swift +++ b/Tests/GRDBTests/EncryptionTests.swift @@ -336,7 +336,7 @@ class EncryptionTests: GRDBTestCase { func testCipherPageSize() throws { do { dbConfiguration.passphrase = "secret" - dbConfiguration.cipherPageSize = .ps8192 + dbConfiguration.cipherPageSize = .pageSize8K let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase({ db in @@ -345,15 +345,21 @@ class EncryptionTests: GRDBTestCase { } do { - dbConfiguration.cipherPageSize = .ps4096 + dbConfiguration.cipherPageSize = .pageSize4K let dbQueue = try makeDatabasePool(filename: "testpool.sqlite") - try dbQueue.read({ db in - XCTAssertEqual(try Int.fetchOne(db, "PRAGMA cipher_page_size")!, 4096) - }) try dbQueue.write({ db in XCTAssertEqual(try Int.fetchOne(db, "PRAGMA cipher_page_size")!, 4096) + try db.execute("CREATE TABLE data(value INTEGER)") + try db.execute("INSERT INTO data(value) VALUES(1)") }) + try dbQueue.read({ db in + XCTAssertEqual(try Int.fetchOne(db, "PRAGMA cipher_page_size")!, 4096) + XCTAssertEqual(try Int.fetchOne(db, "SELECT value FROM data"), 1) + }) + + } + } } } From d4eb7ba27b256afa526a6dc8b63b8d5e72a0677f Mon Sep 17 00:00:00 2001 From: Marcel Ball Date: Wed, 6 Mar 2019 20:41:38 -0400 Subject: [PATCH 08/29] Added configuration options to GRDBcipher for kdf_iterations --- GRDB/Core/Configuration.swift | 2 ++ GRDB/Core/Database.swift | 16 ++++++++++++++ Tests/GRDBTests/EncryptionTests.swift | 32 +++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/GRDB/Core/Configuration.swift b/GRDB/Core/Configuration.swift index 0fb00fe42..53d0544d0 100644 --- a/GRDB/Core/Configuration.swift +++ b/GRDB/Core/Configuration.swift @@ -93,6 +93,8 @@ public struct Configuration { } public var cipherPageSize: CipherPageSize = .pageSize1K + + public var cipherKDFIterations: Int = 64000 #endif diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index f71f2c729..6e78de44a 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -174,6 +174,7 @@ public final class Database { if let passphrase = configuration.passphrase { try Database.set(passphrase: passphrase, forConnection: sqliteConnection) try Database.set(cipherPageSize: configuration.cipherPageSize, forConnection: sqliteConnection) + try Database.set(kdfIterations: configuration.cipherKDFIterations, forConnection: sqliteConnection) } #endif try Database.validateDatabaseFormat(sqliteConnection) @@ -277,6 +278,21 @@ extension Database { throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "Unable to set cipher_page_size") } } + + private static func set(kdfIterations: Int, forConnection sqliteConnection: SQLiteConnection) throws { + var sqliteStatement: SQLiteStatement? = nil + let code = sqlite3_prepare_v2(sqliteConnection, "PRAGMA kdf_iter = \(kdfIterations)", -1, &sqliteStatement, nil) + guard code == SQLITE_OK else { + throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) + } + defer { + sqlite3_finalize(sqliteStatement) + } + let step = sqlite3_step(sqliteStatement) + if step != SQLITE_DONE { + throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "Unable to set kdf_iter") + } + } #endif private static func validateDatabaseFormat(_ sqliteConnection: SQLiteConnection) throws { diff --git a/Tests/GRDBTests/EncryptionTests.swift b/Tests/GRDBTests/EncryptionTests.swift index ac69d6c64..7d00dc73d 100644 --- a/Tests/GRDBTests/EncryptionTests.swift +++ b/Tests/GRDBTests/EncryptionTests.swift @@ -360,6 +360,38 @@ class EncryptionTests: GRDBTestCase { } } + + func testCipherKDFSettings() throws { + do { + dbConfiguration.passphrase = "secret" + dbConfiguration.cipherKDFIterations = 128000 + + var dbQueue: DatabaseQueue? = try makeDatabaseQueue(filename: "test.sqlite") + try dbQueue!.inDatabase { db in + XCTAssertEqual(try Int.fetchOne(db, "PRAGMA kdf_iter"), 128000) + } + + dbQueue = nil + print("Closed") + } + + do { + dbConfiguration.cipherKDFIterations = 128000 + + var dbQueue: DatabasePool? = try makeDatabasePool(filename: "testpool.sqlite") + try dbQueue!.write { db in + XCTAssertEqual(try Int.fetchOne(db, "PRAGMA kdf_iter"), 128000) + try db.execute("CREATE TABLE data(value INTEGER)") + try db.execute("INSERT INTO data(value) VALUES(1)") + } + + try dbQueue!.read { db in + XCTAssertEqual(try Int.fetchOne(db, "PRAGMA kdf_iter"), 128000) + XCTAssertEqual(try Int.fetchOne(db, "SELECT value FROM data"), 1) + } + + dbQueue = nil + print("Closed") } } From 8415e8c2a07f7b9fcb8cf5226dbaef2adb9acfbf Mon Sep 17 00:00:00 2001 From: Marcel Ball Date: Wed, 6 Mar 2019 20:58:29 -0400 Subject: [PATCH 09/29] Rename parameter to better align with the SQLCipher PRAGMA --- GRDB/Core/Configuration.swift | 2 +- GRDB/Core/Database.swift | 2 +- Tests/GRDBTests/EncryptionTests.swift | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/GRDB/Core/Configuration.swift b/GRDB/Core/Configuration.swift index 53d0544d0..dfe799e6f 100644 --- a/GRDB/Core/Configuration.swift +++ b/GRDB/Core/Configuration.swift @@ -94,7 +94,7 @@ public struct Configuration { public var cipherPageSize: CipherPageSize = .pageSize1K - public var cipherKDFIterations: Int = 64000 + public var KDFIterations: Int = 64000 #endif diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 6e78de44a..dd0e01b48 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -174,7 +174,7 @@ public final class Database { if let passphrase = configuration.passphrase { try Database.set(passphrase: passphrase, forConnection: sqliteConnection) try Database.set(cipherPageSize: configuration.cipherPageSize, forConnection: sqliteConnection) - try Database.set(kdfIterations: configuration.cipherKDFIterations, forConnection: sqliteConnection) + try Database.set(kdfIterations: configuration.KDFIterations, forConnection: sqliteConnection) } #endif try Database.validateDatabaseFormat(sqliteConnection) diff --git a/Tests/GRDBTests/EncryptionTests.swift b/Tests/GRDBTests/EncryptionTests.swift index 7d00dc73d..7ada6d1ec 100644 --- a/Tests/GRDBTests/EncryptionTests.swift +++ b/Tests/GRDBTests/EncryptionTests.swift @@ -364,7 +364,7 @@ class EncryptionTests: GRDBTestCase { func testCipherKDFSettings() throws { do { dbConfiguration.passphrase = "secret" - dbConfiguration.cipherKDFIterations = 128000 + dbConfiguration.KDFIterations = 128000 var dbQueue: DatabaseQueue? = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue!.inDatabase { db in @@ -376,7 +376,7 @@ class EncryptionTests: GRDBTestCase { } do { - dbConfiguration.cipherKDFIterations = 128000 + dbConfiguration.KDFIterations = 128000 var dbQueue: DatabasePool? = try makeDatabasePool(filename: "testpool.sqlite") try dbQueue!.write { db in From 349ef328c7278d359db5acbfc3709f138a6b88ae Mon Sep 17 00:00:00 2001 From: Marcel Ball Date: Wed, 6 Mar 2019 21:01:08 -0400 Subject: [PATCH 10/29] Updated documentation to cover new configuration options --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 413d8786a..d19568439 100644 --- a/README.md +++ b/README.md @@ -7303,6 +7303,30 @@ try clearDBQueue.inDatabase { db in // Now the copy is done, and the clear-text database can be deleted. ``` +**Advanced configuration options for SQLCipher** +There are two advanced configuration options that you can set for configuring SQLCipher that control aspects of the encryption and key generation process. + +```swift +var configuartion = Configuration() +configuration.passphrase = "secret" +configuration.cipherPageSize = .pageSize4K +configuration.KDFIterations = 128000 +let dbQueue = try DatabaseQueue(path: "...", configuration: configuration) +``` +***cipherPageSize*** +The `cipherPageSize` is used to adjust the page size for the encrypted database (this corresponds to the SQLCipher `PRAGMA cipher_page_size` configuration option). Increasing the page size can noticeably improve performance for certain queries that access large numbers of pages. + +WARNING: The same `cipherPageSize` must be supplied every time that the database file is open; attempting to access the database without setting the proper `cipherPageSize` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. + +The default `cipherPageSize` in the current version of SQLCipher used in GRDB.swift is `.pageSize1K`. + +***KDFIterations*** +The `KDFIterations` value is used to adjust the number of iterations that the PBKDF2 key derivation is run to derive the key from the `passphrase` supplied (this corresponds to the SQLCipher `PRAGMA kdf_iter` configuration option). + +WARNING: The same `KDFIterations` must be supplied every time that the database file is open; attempting to access the database without setting the proper `KDFIterations` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. + +The default `KDFIterations` in the current version of SQLCipher used in GRDB.swift is `64000`. It is not recommend to reduce the number of iterations used from the default. + ## Backup From 47f9b0f4a90bc95c38268a425025fb581d9d0df4 Mon Sep 17 00:00:00 2001 From: Marcel Ball Date: Wed, 6 Mar 2019 21:21:43 -0400 Subject: [PATCH 11/29] Added inline comments for new configuration options. --- GRDB/Core/Configuration.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/GRDB/Core/Configuration.swift b/GRDB/Core/Configuration.swift index dfe799e6f..6139f420e 100644 --- a/GRDB/Core/Configuration.swift +++ b/GRDB/Core/Configuration.swift @@ -82,6 +82,7 @@ public struct Configuration { /// Default: nil public var passphrase: String? + // Valid options for the cipher_page_size setting public enum CipherPageSize: Int { case pageSize1K = 1024 case pageSize2K = 2048 @@ -92,8 +93,14 @@ public struct Configuration { case pageSize64K = 65536 } + /// The cipher_page_size for encrypted databases + /// + /// Default: .pageSize1K - this corresponds to the default used until now in SQLCipher/GRDBCipher 3 public var cipherPageSize: CipherPageSize = .pageSize1K + /// The kdf_iter setting for encrypted database + /// + /// Default: 64000 - this corresponds to the default used until now in SQLCipher/GRDBCipher 3 public var KDFIterations: Int = 64000 #endif From 8ca983943364bfd5b43b72e6cb5a1800222fd3bc Mon Sep 17 00:00:00 2001 From: Marcel Ball Date: Wed, 6 Mar 2019 21:31:37 -0400 Subject: [PATCH 12/29] Cleanup of some things leftover from debugging/testing --- Tests/GRDBTests/EncryptionTests.swift | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Tests/GRDBTests/EncryptionTests.swift b/Tests/GRDBTests/EncryptionTests.swift index 7ada6d1ec..3b0a3d71b 100644 --- a/Tests/GRDBTests/EncryptionTests.swift +++ b/Tests/GRDBTests/EncryptionTests.swift @@ -366,19 +366,16 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" dbConfiguration.KDFIterations = 128000 - var dbQueue: DatabaseQueue? = try makeDatabaseQueue(filename: "test.sqlite") + let dbQueue: DatabaseQueue? = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue!.inDatabase { db in XCTAssertEqual(try Int.fetchOne(db, "PRAGMA kdf_iter"), 128000) } - - dbQueue = nil - print("Closed") } do { dbConfiguration.KDFIterations = 128000 - var dbQueue: DatabasePool? = try makeDatabasePool(filename: "testpool.sqlite") + let dbQueue: DatabasePool? = try makeDatabasePool(filename: "testpool.sqlite") try dbQueue!.write { db in XCTAssertEqual(try Int.fetchOne(db, "PRAGMA kdf_iter"), 128000) try db.execute("CREATE TABLE data(value INTEGER)") @@ -389,9 +386,6 @@ class EncryptionTests: GRDBTestCase { XCTAssertEqual(try Int.fetchOne(db, "PRAGMA kdf_iter"), 128000) XCTAssertEqual(try Int.fetchOne(db, "SELECT value FROM data"), 1) } - - dbQueue = nil - print("Closed") } } From b0638707396ace88cfab11c5f011545e2ce32df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 7 Mar 2019 05:06:58 +0100 Subject: [PATCH 13/29] Too much future: firstIndex is not available on Xcode 9.4- --- GRDB/Utils/OrderedDictionary.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GRDB/Utils/OrderedDictionary.swift b/GRDB/Utils/OrderedDictionary.swift index e0a5207ed..126c2f97c 100644 --- a/GRDB/Utils/OrderedDictionary.swift +++ b/GRDB/Utils/OrderedDictionary.swift @@ -73,7 +73,7 @@ struct OrderedDictionary { guard let value = dictionary.removeValue(forKey: key) else { return nil } - let index = keys.firstIndex { $0 == key }! + let index = keys.index { $0 == key }! keys.remove(at: index) return value } From 7d0b5cf03c8c3765a7f1ec2a2d1f6de8dc83bd1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 7 Mar 2019 18:32:30 +0100 Subject: [PATCH 14/29] Don't codesign GRDBFTS5MacOS test app --- .../GRDBFTS5MacOS.xcodeproj/project.pbxproj | 17 +++++++++++------ .../GRDBFTS5MacOS/GRDBFTS5MacOS.entitlements | 7 +------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.pbxproj b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.pbxproj index 3e841b4df..c84e27fbe 100644 --- a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.pbxproj +++ b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.pbxproj @@ -118,6 +118,11 @@ TargetAttributes = { 562697B021107C130066800A = { CreatedOnToolsVersion = 9.4.1; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 0; + }; + }; }; }; }; @@ -331,10 +336,9 @@ baseConfigurationReference = EC2C210DD2F8C1485D2B51F8 /* Pods-GRDBFTS5MacOS.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_ENTITLEMENTS = GRDBFTS5MacOS/GRDBFTS5MacOS.entitlements; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = AMD8W895CT; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GRDBFTS5MacOS/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -342,6 +346,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBFTS5MacOS; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 4.2; }; name = Debug; @@ -351,10 +356,9 @@ baseConfigurationReference = 966036335047A35A92E51A77 /* Pods-GRDBFTS5MacOS.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_ENTITLEMENTS = GRDBFTS5MacOS/GRDBFTS5MacOS.entitlements; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = AMD8W895CT; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GRDBFTS5MacOS/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -362,6 +366,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBFTS5MacOS; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 4.2; }; name = Release; diff --git a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/GRDBFTS5MacOS.entitlements b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/GRDBFTS5MacOS.entitlements index f2ef3ae02..0c67376eb 100644 --- a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/GRDBFTS5MacOS.entitlements +++ b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/GRDBFTS5MacOS.entitlements @@ -1,10 +1,5 @@ - - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - - + From 519fa9a41a8a96f836330a4a5c293c7242e5abf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 7 Mar 2019 18:34:19 +0100 Subject: [PATCH 15/29] Don't codesign GRDBCipherMacOS test app --- .../GRDBCipherMacOS.xcodeproj/project.pbxproj | 17 +++++++++++------ .../GRDBCipherMacOS.entitlements | 7 +------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS.xcodeproj/project.pbxproj b/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS.xcodeproj/project.pbxproj index b85379444..2c37b257b 100644 --- a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS.xcodeproj/project.pbxproj +++ b/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS.xcodeproj/project.pbxproj @@ -118,6 +118,11 @@ TargetAttributes = { 56269771211036C10066800A = { CreatedOnToolsVersion = 9.4.1; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 0; + }; + }; }; }; }; @@ -333,10 +338,9 @@ baseConfigurationReference = A3F8791E6F512575865AC37C /* Pods-GRDBCipherMacOS.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_ENTITLEMENTS = GRDBCipherMacOS/GRDBCipherMacOS.entitlements; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = AMD8W895CT; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GRDBCipherMacOS/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -344,6 +348,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBCipherMacOS; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 4.2; }; name = Debug; @@ -353,10 +358,9 @@ baseConfigurationReference = 2AB57EA4305B77469C9A4267 /* Pods-GRDBCipherMacOS.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_ENTITLEMENTS = GRDBCipherMacOS/GRDBCipherMacOS.entitlements; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = AMD8W895CT; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GRDBCipherMacOS/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -364,6 +368,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBCipherMacOS; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 4.2; }; name = Release; diff --git a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/GRDBCipherMacOS.entitlements b/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/GRDBCipherMacOS.entitlements index f2ef3ae02..0c67376eb 100644 --- a/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/GRDBCipherMacOS.entitlements +++ b/Tests/CocoaPods/GRDBCipherMacOS/GRDBCipherMacOS/GRDBCipherMacOS.entitlements @@ -1,10 +1,5 @@ - - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - - + From 6543d75f6d1df7fa1450743f85006ce3696778f3 Mon Sep 17 00:00:00 2001 From: Marcel Ball Date: Thu, 7 Mar 2019 17:51:16 -0400 Subject: [PATCH 16/29] Updated based upon feedback from @groue - Renamed `KDFIternations` to `kdfIterations` to better fit naming conventions - In case of errors setting values return the sqlite error code and message instead of .SQLITE_MISUSE and a generic message - Fixed formatting/typos in documentation --- GRDB/Core/Configuration.swift | 2 +- GRDB/Core/Database.swift | 18 +++++++++--------- README.md | 21 ++++++++++++--------- Tests/GRDBTests/EncryptionTests.swift | 4 ++-- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/GRDB/Core/Configuration.swift b/GRDB/Core/Configuration.swift index 6139f420e..91b178271 100644 --- a/GRDB/Core/Configuration.swift +++ b/GRDB/Core/Configuration.swift @@ -101,7 +101,7 @@ public struct Configuration { /// The kdf_iter setting for encrypted database /// /// Default: 64000 - this corresponds to the default used until now in SQLCipher/GRDBCipher 3 - public var KDFIterations: Int = 64000 + public var kdfIterations: Int = 64000 #endif diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index dd0e01b48..41711c013 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -174,7 +174,7 @@ public final class Database { if let passphrase = configuration.passphrase { try Database.set(passphrase: passphrase, forConnection: sqliteConnection) try Database.set(cipherPageSize: configuration.cipherPageSize, forConnection: sqliteConnection) - try Database.set(kdfIterations: configuration.KDFIterations, forConnection: sqliteConnection) + try Database.set(kdfIterations: configuration.kdfIterations, forConnection: sqliteConnection) } #endif try Database.validateDatabaseFormat(sqliteConnection) @@ -266,31 +266,31 @@ extension Database { private static func set(cipherPageSize: Configuration.CipherPageSize, forConnection sqliteConnection: SQLiteConnection) throws { var sqliteStatement: SQLiteStatement? = nil - let code = sqlite3_prepare_v2(sqliteConnection, "PRAGMA cipher_page_size = \(cipherPageSize.rawValue)", -1, &sqliteStatement, nil) + var code = sqlite3_prepare_v2(sqliteConnection, "PRAGMA cipher_page_size = \(cipherPageSize.rawValue)", -1, &sqliteStatement, nil) guard code == SQLITE_OK else { throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) } defer { sqlite3_finalize(sqliteStatement) } - let step = sqlite3_step(sqliteStatement) - if step != SQLITE_DONE { - throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "Unable to set cipher_page_size") + code = sqlite3_step(sqliteStatement) + if code != SQLITE_DONE { + throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) } } private static func set(kdfIterations: Int, forConnection sqliteConnection: SQLiteConnection) throws { var sqliteStatement: SQLiteStatement? = nil - let code = sqlite3_prepare_v2(sqliteConnection, "PRAGMA kdf_iter = \(kdfIterations)", -1, &sqliteStatement, nil) + var code = sqlite3_prepare_v2(sqliteConnection, "PRAGMA kdf_iter = \(kdfIterations)", -1, &sqliteStatement, nil) guard code == SQLITE_OK else { throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) } defer { sqlite3_finalize(sqliteStatement) } - let step = sqlite3_step(sqliteStatement) - if step != SQLITE_DONE { - throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "Unable to set kdf_iter") + code = sqlite3_step(sqliteStatement) + if code != SQLITE_DONE { + throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) } } #endif diff --git a/README.md b/README.md index d19568439..0697fc285 100644 --- a/README.md +++ b/README.md @@ -7303,29 +7303,32 @@ try clearDBQueue.inDatabase { db in // Now the copy is done, and the clear-text database can be deleted. ``` -**Advanced configuration options for SQLCipher** +## Advanced configuration options for SQLCipher + There are two advanced configuration options that you can set for configuring SQLCipher that control aspects of the encryption and key generation process. ```swift -var configuartion = Configuration() +var configuration = Configuration() configuration.passphrase = "secret" configuration.cipherPageSize = .pageSize4K -configuration.KDFIterations = 128000 +configuration.kdfIterations = 128000 let dbQueue = try DatabaseQueue(path: "...", configuration: configuration) ``` -***cipherPageSize*** -The `cipherPageSize` is used to adjust the page size for the encrypted database (this corresponds to the SQLCipher `PRAGMA cipher_page_size` configuration option). Increasing the page size can noticeably improve performance for certain queries that access large numbers of pages. +### cipherPageSize + +The `cipherPageSize` is used to adjust the page size for the encrypted database (this corresponds to the [SQLCipher `PRAGMA cipher_page_size`](https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_page_size) configuration option). Increasing the page size can noticeably improve performance for certain queries that access large numbers of pages. WARNING: The same `cipherPageSize` must be supplied every time that the database file is open; attempting to access the database without setting the proper `cipherPageSize` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. The default `cipherPageSize` in the current version of SQLCipher used in GRDB.swift is `.pageSize1K`. -***KDFIterations*** -The `KDFIterations` value is used to adjust the number of iterations that the PBKDF2 key derivation is run to derive the key from the `passphrase` supplied (this corresponds to the SQLCipher `PRAGMA kdf_iter` configuration option). +### kdfIterations -WARNING: The same `KDFIterations` must be supplied every time that the database file is open; attempting to access the database without setting the proper `KDFIterations` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. +The `kdfIterations` value is used to adjust the number of iterations that the PBKDF2 key derivation is run to derive the key from the `passphrase` supplied (this corresponds to the [SQLCipher `PRAGMA kdf_iter`](https://www.zetetic.net/sqlcipher/sqlcipher-api/#kdf_iter) configuration option). -The default `KDFIterations` in the current version of SQLCipher used in GRDB.swift is `64000`. It is not recommend to reduce the number of iterations used from the default. +WARNING: The same `kdfIterations` must be supplied every time that the database file is open; attempting to access the database without setting the proper `kdfIterations` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. + +The default `kdfIterations` in the current version of SQLCipher used in GRDB.swift is `64000`. It is not recommend to reduce the number of iterations used from the default. ## Backup diff --git a/Tests/GRDBTests/EncryptionTests.swift b/Tests/GRDBTests/EncryptionTests.swift index 3b0a3d71b..c913cc001 100644 --- a/Tests/GRDBTests/EncryptionTests.swift +++ b/Tests/GRDBTests/EncryptionTests.swift @@ -364,7 +364,7 @@ class EncryptionTests: GRDBTestCase { func testCipherKDFSettings() throws { do { dbConfiguration.passphrase = "secret" - dbConfiguration.KDFIterations = 128000 + dbConfiguration.kdfIterations = 128000 let dbQueue: DatabaseQueue? = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue!.inDatabase { db in @@ -373,7 +373,7 @@ class EncryptionTests: GRDBTestCase { } do { - dbConfiguration.KDFIterations = 128000 + dbConfiguration.kdfIterations = 128000 let dbQueue: DatabasePool? = try makeDatabasePool(filename: "testpool.sqlite") try dbQueue!.write { db in From c46dbdd97e4a14949d5067341872d3269efc83f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 8 Mar 2019 08:25:02 +0100 Subject: [PATCH 17/29] Turn WARNING into a Note --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0697fc285..8311bccbe 100644 --- a/README.md +++ b/README.md @@ -7314,22 +7314,23 @@ configuration.cipherPageSize = .pageSize4K configuration.kdfIterations = 128000 let dbQueue = try DatabaseQueue(path: "...", configuration: configuration) ``` + ### cipherPageSize The `cipherPageSize` is used to adjust the page size for the encrypted database (this corresponds to the [SQLCipher `PRAGMA cipher_page_size`](https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_page_size) configuration option). Increasing the page size can noticeably improve performance for certain queries that access large numbers of pages. -WARNING: The same `cipherPageSize` must be supplied every time that the database file is open; attempting to access the database without setting the proper `cipherPageSize` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. - The default `cipherPageSize` in the current version of SQLCipher used in GRDB.swift is `.pageSize1K`. +> :point_up: **Note**: the same `cipherPageSize` must be supplied every time that the database file is open; attempting to access the database without setting the proper `cipherPageSize` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. + ### kdfIterations The `kdfIterations` value is used to adjust the number of iterations that the PBKDF2 key derivation is run to derive the key from the `passphrase` supplied (this corresponds to the [SQLCipher `PRAGMA kdf_iter`](https://www.zetetic.net/sqlcipher/sqlcipher-api/#kdf_iter) configuration option). -WARNING: The same `kdfIterations` must be supplied every time that the database file is open; attempting to access the database without setting the proper `kdfIterations` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. - The default `kdfIterations` in the current version of SQLCipher used in GRDB.swift is `64000`. It is not recommend to reduce the number of iterations used from the default. +> :point_up: **Note**: he same `kdfIterations` must be supplied every time that the database file is open; attempting to access the database without setting the proper `kdfIterations` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. + ## Backup From 53d2e6b895413bf89650a27b894cade1a3b37d37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 8 Mar 2019 08:26:18 +0100 Subject: [PATCH 18/29] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8311bccbe..869bf80d5 100644 --- a/README.md +++ b/README.md @@ -7329,7 +7329,7 @@ The `kdfIterations` value is used to adjust the number of iterations that the PB The default `kdfIterations` in the current version of SQLCipher used in GRDB.swift is `64000`. It is not recommend to reduce the number of iterations used from the default. -> :point_up: **Note**: he same `kdfIterations` must be supplied every time that the database file is open; attempting to access the database without setting the proper `kdfIterations` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. +> :point_up: **Note**: the same `kdfIterations` must be supplied every time that the database file is open; attempting to access the database without setting the proper `kdfIterations` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown. ## Backup From bad862ba16a5895acc69e2bffea3d52f4e30439a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 8 Mar 2019 12:40:00 +0100 Subject: [PATCH 19/29] Remove all mentions of GRDBPlus --- .travis.yml | 18 - Makefile | 30 +- .../GRDBFTS5MacOS.xcodeproj/project.pbxproj | 398 ---------- .../contents.xcworkspacedata | 7 - .../xcshareddata/IDEWorkspaceChecks.plist | 8 - .../GRDBFTS5MacOS/AppDelegate.swift | 21 - .../AppIcon.appiconset/Contents.json | 58 -- .../Assets.xcassets/Contents.json | 6 - .../GRDBFTS5MacOS/Base.lproj/MainMenu.xib | 692 ------------------ .../GRDBFTS5MacOS/GRDBFTS5MacOS.entitlements | 5 - .../GRDBFTS5MacOS/GRDBFTS5MacOS/Info.plist | 32 - Tests/CocoaPods/GRDBFTS5MacOS/Podfile | 5 - 12 files changed, 2 insertions(+), 1278 deletions(-) delete mode 100644 Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.pbxproj delete mode 100644 Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist delete mode 100644 Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/AppDelegate.swift delete mode 100644 Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Assets.xcassets/AppIcon.appiconset/Contents.json delete mode 100644 Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Assets.xcassets/Contents.json delete mode 100644 Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Base.lproj/MainMenu.xib delete mode 100644 Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/GRDBFTS5MacOS.entitlements delete mode 100644 Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Info.plist delete mode 100644 Tests/CocoaPods/GRDBFTS5MacOS/Podfile diff --git a/.travis.yml b/.travis.yml index 8380e54ec..da4bbbdc3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -177,15 +177,6 @@ jobs: - TID=CocoaPods Lint GRDB.swift (Xcode 10) script: make test_CocoaPodsLint_GRDB - # CocoaPods Lint (Xcode 10) - - stage: Test Installation - osx_image: xcode10 - install: - - gem install cocoapods --pre # >= 1.6.0.beta.1 for cocoapods lint - env: - - TID=CocoaPods Lint GRDBPlus (Xcode 10) - script: make test_CocoaPodsLint_GRDBPlus - # CocoaPods Lint (Xcode 10) - stage: Test Installation osx_image: xcode10 @@ -204,15 +195,6 @@ jobs: - TID=CocoaPods GRDB (Xcode 10) script: make test_install_GRDB_CocoaPods - # CocoaPods Install (Xcode 10) - - stage: Test Installation - osx_image: xcode10 - install: - - gem install cocoapods --pre # >= 1.6.0.beta.1 for cocoapods lint - env: - - TID=CocoaPods GRDB+FTS5 (Xcode 10) - script: make test_install_GRDBFTS5_CocoaPods - # CocoaPods Install (Xcode 10) - stage: Test Installation osx_image: xcode10 diff --git a/Makefile b/Makefile index 7e9e9889e..9906e062a 100644 --- a/Makefile +++ b/Makefile @@ -112,8 +112,8 @@ test_framework_darwin: test_framework_GRDB test_framework_GRDBCustom test_framew test_framework_GRDB: test_framework_GRDBOSX test_framework_GRDBWatchOS test_framework_GRDBiOS test_framework_GRDBCustom: test_framework_GRDBCustomSQLiteOSX test_framework_GRDBCustomSQLiteiOS test_framework_GRDBCipher: test_framework_GRDBCipherOSX test_framework_GRDBCipheriOS -test_install: test_install_manual test_install_GRDBCipher test_install_SPM test_install_GRDB_CocoaPods test_install_GRDBFTS5_CocoaPods test_install_GRDBCipher_CocoaPods test_CocoaPodsLint -test_CocoaPodsLint: test_CocoaPodsLint_GRDB test_CocoaPodsLint_GRDBPlus test_CocoaPodsLint_GRDBCipher +test_install: test_install_manual test_install_GRDBCipher test_install_SPM test_install_GRDB_CocoaPods test_install_GRDBCipher_CocoaPods test_CocoaPodsLint +test_CocoaPodsLint: test_CocoaPodsLint_GRDB test_CocoaPodsLint_GRDBCipher test_framework_GRDBOSX: test_framework_GRDBOSX_maxSwift test_framework_GRDBOSX_minSwift @@ -307,24 +307,6 @@ else @exit 1 endif -test_install_GRDBFTS5_CocoaPods: -ifdef POD - cd Tests/CocoaPods/GRDBFTS5MacOS && \ - rm -rf GRDBFTS5MacOS.xcworkspace && \ - rm -rf Pods && \ - rm -rf Podfile.lock && \ - $(POD) install && \ - $(XCODEBUILD) \ - -workspace GRDBFTS5MacOS.xcworkspace \ - -scheme GRDBFTS5MacOS \ - -configuration Release \ - clean build \ - $(XCPRETTY) -else - @echo CocoaPods must be installed for test_install_GRDBFTS5_CocoaPods - @exit 1 -endif - test_install_GRDBCipher_CocoaPods: ifdef POD cd Tests/CocoaPods/GRDBCipherMacOS && \ @@ -351,14 +333,6 @@ else @exit 1 endif -test_CocoaPodsLint_GRDBPlus: -ifdef POD - $(POD) lib lint GRDBPlus.podspec --allow-warnings $(COCOAPODS_EXTRA_TIME) -else - @echo CocoaPods must be installed for test_CocoaPodsLint_GRDBPlus - @exit 1 -endif - test_CocoaPodsLint_GRDBCipher: ifdef POD $(POD) lib lint GRDBCipher.podspec --allow-warnings $(COCOAPODS_EXTRA_TIME) diff --git a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.pbxproj b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.pbxproj deleted file mode 100644 index c84e27fbe..000000000 --- a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.pbxproj +++ /dev/null @@ -1,398 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 50; - objects = { - -/* Begin PBXBuildFile section */ - 562697B521107C130066800A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562697B421107C130066800A /* AppDelegate.swift */; }; - 562697B721107C140066800A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 562697B621107C140066800A /* Assets.xcassets */; }; - 562697BA21107C140066800A /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 562697B821107C140066800A /* MainMenu.xib */; }; - CFA022B8C32840D0B6DEE0F0 /* Pods_GRDBFTS5MacOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6CD0FDB86C1C7C5D392EEDC0 /* Pods_GRDBFTS5MacOS.framework */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 562697B121107C130066800A /* GRDBFTS5MacOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GRDBFTS5MacOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 562697B421107C130066800A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 562697B621107C140066800A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 562697B921107C140066800A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; - 562697BB21107C140066800A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 562697BC21107C140066800A /* GRDBFTS5MacOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GRDBFTS5MacOS.entitlements; sourceTree = ""; }; - 6CD0FDB86C1C7C5D392EEDC0 /* Pods_GRDBFTS5MacOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GRDBFTS5MacOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 966036335047A35A92E51A77 /* Pods-GRDBFTS5MacOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GRDBFTS5MacOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-GRDBFTS5MacOS/Pods-GRDBFTS5MacOS.release.xcconfig"; sourceTree = ""; }; - EC2C210DD2F8C1485D2B51F8 /* Pods-GRDBFTS5MacOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GRDBFTS5MacOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-GRDBFTS5MacOS/Pods-GRDBFTS5MacOS.debug.xcconfig"; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 562697AE21107C130066800A /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - CFA022B8C32840D0B6DEE0F0 /* Pods_GRDBFTS5MacOS.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 562697A821107C130066800A = { - isa = PBXGroup; - children = ( - 562697B321107C130066800A /* GRDBFTS5MacOS */, - 562697B221107C130066800A /* Products */, - BC88EA1E9BA0651EB954E368 /* Pods */, - A3A77F69118F72CFF483B37C /* Frameworks */, - ); - sourceTree = ""; - }; - 562697B221107C130066800A /* Products */ = { - isa = PBXGroup; - children = ( - 562697B121107C130066800A /* GRDBFTS5MacOS.app */, - ); - name = Products; - sourceTree = ""; - }; - 562697B321107C130066800A /* GRDBFTS5MacOS */ = { - isa = PBXGroup; - children = ( - 562697B421107C130066800A /* AppDelegate.swift */, - 562697B621107C140066800A /* Assets.xcassets */, - 562697B821107C140066800A /* MainMenu.xib */, - 562697BB21107C140066800A /* Info.plist */, - 562697BC21107C140066800A /* GRDBFTS5MacOS.entitlements */, - ); - path = GRDBFTS5MacOS; - sourceTree = ""; - }; - A3A77F69118F72CFF483B37C /* Frameworks */ = { - isa = PBXGroup; - children = ( - 6CD0FDB86C1C7C5D392EEDC0 /* Pods_GRDBFTS5MacOS.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; - BC88EA1E9BA0651EB954E368 /* Pods */ = { - isa = PBXGroup; - children = ( - EC2C210DD2F8C1485D2B51F8 /* Pods-GRDBFTS5MacOS.debug.xcconfig */, - 966036335047A35A92E51A77 /* Pods-GRDBFTS5MacOS.release.xcconfig */, - ); - name = Pods; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 562697B021107C130066800A /* GRDBFTS5MacOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = 562697BF21107C140066800A /* Build configuration list for PBXNativeTarget "GRDBFTS5MacOS" */; - buildPhases = ( - 686592AFA9220CAC4B74492A /* [CP] Check Pods Manifest.lock */, - 562697AD21107C130066800A /* Sources */, - 562697AE21107C130066800A /* Frameworks */, - 562697AF21107C130066800A /* Resources */, - D7E14FB39185BF47C54C6643 /* [CP] Embed Pods Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = GRDBFTS5MacOS; - productName = GRDBFTS5MacOS; - productReference = 562697B121107C130066800A /* GRDBFTS5MacOS.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 562697A921107C130066800A /* Project object */ = { - isa = PBXProject; - attributes = { - LastSwiftUpdateCheck = 0940; - LastUpgradeCheck = 0940; - ORGANIZATIONNAME = "Gwendal Roué"; - TargetAttributes = { - 562697B021107C130066800A = { - CreatedOnToolsVersion = 9.4.1; - SystemCapabilities = { - com.apple.Sandbox = { - enabled = 0; - }; - }; - }; - }; - }; - buildConfigurationList = 562697AC21107C130066800A /* Build configuration list for PBXProject "GRDBFTS5MacOS" */; - compatibilityVersion = "Xcode 9.3"; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 562697A821107C130066800A; - productRefGroup = 562697B221107C130066800A /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 562697B021107C130066800A /* GRDBFTS5MacOS */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 562697AF21107C130066800A /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 562697B721107C140066800A /* Assets.xcassets in Resources */, - 562697BA21107C140066800A /* MainMenu.xib in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXShellScriptBuildPhase section */ - 686592AFA9220CAC4B74492A /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-GRDBFTS5MacOS-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; - D7E14FB39185BF47C54C6643 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-GRDBFTS5MacOS/Pods-GRDBFTS5MacOS-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/GRDBPlus/GRDB.framework", - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GRDB.framework", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-GRDBFTS5MacOS/Pods-GRDBFTS5MacOS-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; -/* End PBXShellScriptBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 562697AD21107C130066800A /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 562697B521107C130066800A /* AppDelegate.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXVariantGroup section */ - 562697B821107C140066800A /* MainMenu.xib */ = { - isa = PBXVariantGroup; - children = ( - 562697B921107C140066800A /* Base */, - ); - name = MainMenu.xib; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - 562697BD21107C140066800A /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "Mac Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - 562697BE21107C140066800A /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "Mac Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = macosx; - SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; - }; - name = Release; - }; - 562697C021107C140066800A /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = EC2C210DD2F8C1485D2B51F8 /* Pods-GRDBFTS5MacOS.debug.xcconfig */; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_STYLE = Manual; - COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = ""; - INFOPLIST_FILE = GRDBFTS5MacOS/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBFTS5MacOS; - PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = ""; - SWIFT_VERSION = 4.2; - }; - name = Debug; - }; - 562697C121107C140066800A /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 966036335047A35A92E51A77 /* Pods-GRDBFTS5MacOS.release.xcconfig */; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_STYLE = Manual; - COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = ""; - INFOPLIST_FILE = GRDBFTS5MacOS/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBFTS5MacOS; - PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = ""; - SWIFT_VERSION = 4.2; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 562697AC21107C130066800A /* Build configuration list for PBXProject "GRDBFTS5MacOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 562697BD21107C140066800A /* Debug */, - 562697BE21107C140066800A /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 562697BF21107C140066800A /* Build configuration list for PBXNativeTarget "GRDBFTS5MacOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 562697C021107C140066800A /* Debug */, - 562697C121107C140066800A /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 562697A921107C130066800A /* Project object */; -} diff --git a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index fd8686896..000000000 --- a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d981003..000000000 --- a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/AppDelegate.swift b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/AppDelegate.swift deleted file mode 100644 index d010e0e4b..000000000 --- a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/AppDelegate.swift +++ /dev/null @@ -1,21 +0,0 @@ -import Cocoa -import GRDB - -@NSApplicationMain -class AppDelegate: NSObject, NSApplicationDelegate { - @IBOutlet weak var window: NSWindow! - - func applicationDidFinishLaunching(_ aNotification: Notification) { - let dbQueue = DatabaseQueue() - try! dbQueue.write { db in - // Test access to FTS5 C API - _ = try db.makeTokenizer(.unicode61()) - - // Test creation of FTS5 table - try db.create(virtualTable: "document", using: FTS5()) { t in - t.column("content") - } - } - } -} - diff --git a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Assets.xcassets/AppIcon.appiconset/Contents.json b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 2db2b1c7c..000000000 --- a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "images" : [ - { - "idiom" : "mac", - "size" : "16x16", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "16x16", - "scale" : "2x" - }, - { - "idiom" : "mac", - "size" : "32x32", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "32x32", - "scale" : "2x" - }, - { - "idiom" : "mac", - "size" : "128x128", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "128x128", - "scale" : "2x" - }, - { - "idiom" : "mac", - "size" : "256x256", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "256x256", - "scale" : "2x" - }, - { - "idiom" : "mac", - "size" : "512x512", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "512x512", - "scale" : "2x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Assets.xcassets/Contents.json b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Assets.xcassets/Contents.json deleted file mode 100644 index da4a164c9..000000000 --- a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Assets.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Base.lproj/MainMenu.xib b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Base.lproj/MainMenu.xib deleted file mode 100644 index 623f91d00..000000000 --- a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Base.lproj/MainMenu.xib +++ /dev/null @@ -1,692 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/GRDBFTS5MacOS.entitlements b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/GRDBFTS5MacOS.entitlements deleted file mode 100644 index 0c67376eb..000000000 --- a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/GRDBFTS5MacOS.entitlements +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Info.plist b/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Info.plist deleted file mode 100644 index cfde06cd5..000000000 --- a/Tests/CocoaPods/GRDBFTS5MacOS/GRDBFTS5MacOS/Info.plist +++ /dev/null @@ -1,32 +0,0 @@ - - - - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIconFile - - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - LSMinimumSystemVersion - $(MACOSX_DEPLOYMENT_TARGET) - NSHumanReadableCopyright - Copyright © 2018 Gwendal Roué. All rights reserved. - NSMainNibFile - MainMenu - NSPrincipalClass - NSApplication - - diff --git a/Tests/CocoaPods/GRDBFTS5MacOS/Podfile b/Tests/CocoaPods/GRDBFTS5MacOS/Podfile deleted file mode 100644 index 1ad4d78b6..000000000 --- a/Tests/CocoaPods/GRDBFTS5MacOS/Podfile +++ /dev/null @@ -1,5 +0,0 @@ -use_frameworks! - -target 'GRDBFTS5MacOS' -platform :macos, '10.13' -pod 'GRDBPlus', :path => '../../..' From 2b460083af1ac6708c192f04246f7dfe030b358a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 8 Mar 2019 12:52:17 +0100 Subject: [PATCH 20/29] GRDBPlus CocoaPod is deprecated --- GRDBPlus.podspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/GRDBPlus.podspec b/GRDBPlus.podspec index 560f0fcb6..34064c1f4 100644 --- a/GRDBPlus.podspec +++ b/GRDBPlus.podspec @@ -1,6 +1,8 @@ Pod::Spec.new do |s| s.name = 'GRDBPlus' s.version = '3.6.2' + s.deprecated = true + s.deprecated_in_favor_of = 'GRDB.swift' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' From 82423c41f23c249b60cfdb99f3fd5b88beb65141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 8 Mar 2019 12:55:05 +0100 Subject: [PATCH 21/29] Disable Travis check for CocoaPods GRDBCipher until we figure out what has turned wrong --- .travis.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index da4bbbdc3..da9eac35b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -195,14 +195,17 @@ jobs: - TID=CocoaPods GRDB (Xcode 10) script: make test_install_GRDB_CocoaPods - # CocoaPods Install (Xcode 10) - - stage: Test Installation - osx_image: xcode10 - install: - - gem install cocoapods --pre # >= 1.6.0.beta.1 for cocoapods lint - env: - - TID=CocoaPods GRDBCipher (Xcode 10) - script: make test_install_GRDBCipher_CocoaPods + # Disabled until we understand the reason for this failure: + # https://travis-ci.org/groue/GRDB.swift/jobs/503214543 + # + # # CocoaPods Install (Xcode 10) + # - stage: Test Installation + # osx_image: xcode10 + # install: + # - gem install cocoapods --pre # >= 1.6.0.beta.1 for cocoapods lint + # env: + # - TID=CocoaPods GRDBCipher (Xcode 10) + # script: make test_install_GRDBCipher_CocoaPods # SPM Install (Xcode 10) - stage: Test Installation From d60b68ab8afcff69cd642b70c34aefce86fb228c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 9 Mar 2019 12:45:11 +0100 Subject: [PATCH 22/29] Document the BusyMode.timeout unit (#498) --- GRDB/Core/Database.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 41711c013..15d482433 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -955,6 +955,7 @@ extension Database { /// /// To set the busy mode of a database, use Configuration: /// + /// // Wait 1 second before failing with SQLITE_BUSY /// let configuration = Configuration(busyMode: .timeout(1)) /// let dbQueue = DatabaseQueue(path: "...", configuration: configuration) /// @@ -970,7 +971,7 @@ extension Database { case immediateError /// The SQLITE_BUSY error will be returned only if the database remains - /// locked for more than the specified duration. + /// locked for more than the specified duration (in seconds). case timeout(TimeInterval) /// A custom callback that is called when a database is locked. From 211ac7aadac0023d31627145b0a352ec4fd1be0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 9 Mar 2019 13:37:51 +0100 Subject: [PATCH 23/29] Make Configuration.cipherPageSize an Int As said in https://github.com/groue/GRDB.swift/issues/498#issuecomment-471156347 --- GRDB/Core/Configuration.swift | 29 ++++++++++---------------- GRDB/Core/Database.swift | 4 ++-- Tests/GRDBTests/EncryptionTests.swift | 30 +++++++++++++++++---------- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/GRDB/Core/Configuration.swift b/GRDB/Core/Configuration.swift index 91b178271..18934e3ff 100644 --- a/GRDB/Core/Configuration.swift +++ b/GRDB/Core/Configuration.swift @@ -77,30 +77,23 @@ public struct Configuration { // MARK: - Encryption #if SQLITE_HAS_CODEC - /// The passphrase for encrypted database. + /// The passphrase for the encrypted database. /// /// Default: nil public var passphrase: String? - // Valid options for the cipher_page_size setting - public enum CipherPageSize: Int { - case pageSize1K = 1024 - case pageSize2K = 2048 - case pageSize4K = 4096 - case pageSize8K = 8192 - case pageSize16K = 16384 - case pageSize32K = 32768 - case pageSize64K = 65536 - } - - /// The cipher_page_size for encrypted databases + /// The cipher_page_size setting for the encrypted database. /// - /// Default: .pageSize1K - this corresponds to the default used until now in SQLCipher/GRDBCipher 3 - public var cipherPageSize: CipherPageSize = .pageSize1K - - /// The kdf_iter setting for encrypted database + /// See https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_page_size /// - /// Default: 64000 - this corresponds to the default used until now in SQLCipher/GRDBCipher 3 + /// Default: 1024 - this corresponds to the default used by SQLCipher 3 + public var cipherPageSize: Int = 1024 + + /// The kdf_iter setting for the encrypted database. + /// + /// See https://www.zetetic.net/sqlcipher/sqlcipher-api/#kdf_iter + /// + /// Default: 64000 - this corresponds to the default used by SQLCipher 3 public var kdfIterations: Int = 64000 #endif diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 15d482433..5319692c0 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -264,9 +264,9 @@ extension Database { } } - private static func set(cipherPageSize: Configuration.CipherPageSize, forConnection sqliteConnection: SQLiteConnection) throws { + private static func set(cipherPageSize: Int, forConnection sqliteConnection: SQLiteConnection) throws { var sqliteStatement: SQLiteStatement? = nil - var code = sqlite3_prepare_v2(sqliteConnection, "PRAGMA cipher_page_size = \(cipherPageSize.rawValue)", -1, &sqliteStatement, nil) + var code = sqlite3_prepare_v2(sqliteConnection, "PRAGMA cipher_page_size = \(cipherPageSize)", -1, &sqliteStatement, nil) guard code == SQLITE_OK else { throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection))) } diff --git a/Tests/GRDBTests/EncryptionTests.swift b/Tests/GRDBTests/EncryptionTests.swift index c913cc001..ce5d9fbe1 100644 --- a/Tests/GRDBTests/EncryptionTests.swift +++ b/Tests/GRDBTests/EncryptionTests.swift @@ -37,6 +37,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = nil do { _ = try makeDatabaseQueue(filename: "test.sqlite") + XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") @@ -60,6 +61,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "wrong" do { _ = try makeDatabaseQueue(filename: "test.sqlite") + XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") @@ -133,6 +135,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = nil do { _ = try makeDatabasePool(filename: "test.sqlite") + XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") @@ -156,6 +159,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "wrong" do { _ = try makeDatabasePool(filename: "test.sqlite") + XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") @@ -227,6 +231,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = nil do { _ = try makeDatabasePool(filename: "test.sqlite") + XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") @@ -250,6 +255,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "wrong" do { _ = try makeDatabasePool(filename: "test.sqlite") + XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") @@ -324,6 +330,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = nil do { _ = try makeDatabaseQueue(filename: "test.sqlite") + XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") @@ -336,7 +343,7 @@ class EncryptionTests: GRDBTestCase { func testCipherPageSize() throws { do { dbConfiguration.passphrase = "secret" - dbConfiguration.cipherPageSize = .pageSize8K + dbConfiguration.cipherPageSize = 8192 let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") try dbQueue.inDatabase({ db in @@ -345,15 +352,15 @@ class EncryptionTests: GRDBTestCase { } do { - dbConfiguration.cipherPageSize = .pageSize4K + dbConfiguration.cipherPageSize = 4096 - let dbQueue = try makeDatabasePool(filename: "testpool.sqlite") - try dbQueue.write({ db in + let dbPool = try makeDatabasePool(filename: "testpool.sqlite") + try dbPool.write({ db in XCTAssertEqual(try Int.fetchOne(db, "PRAGMA cipher_page_size")!, 4096) try db.execute("CREATE TABLE data(value INTEGER)") try db.execute("INSERT INTO data(value) VALUES(1)") }) - try dbQueue.read({ db in + try dbPool.read({ db in XCTAssertEqual(try Int.fetchOne(db, "PRAGMA cipher_page_size")!, 4096) XCTAssertEqual(try Int.fetchOne(db, "SELECT value FROM data"), 1) }) @@ -361,13 +368,13 @@ class EncryptionTests: GRDBTestCase { } } - func testCipherKDFSettings() throws { + func testCipherKDFIterations() throws { do { dbConfiguration.passphrase = "secret" dbConfiguration.kdfIterations = 128000 - let dbQueue: DatabaseQueue? = try makeDatabaseQueue(filename: "test.sqlite") - try dbQueue!.inDatabase { db in + let dbQueue = try makeDatabaseQueue(filename: "test.sqlite") + try dbQueue.inDatabase { db in XCTAssertEqual(try Int.fetchOne(db, "PRAGMA kdf_iter"), 128000) } } @@ -375,14 +382,14 @@ class EncryptionTests: GRDBTestCase { do { dbConfiguration.kdfIterations = 128000 - let dbQueue: DatabasePool? = try makeDatabasePool(filename: "testpool.sqlite") - try dbQueue!.write { db in + let dbPool = try makeDatabasePool(filename: "testpool.sqlite") + try dbPool.write { db in XCTAssertEqual(try Int.fetchOne(db, "PRAGMA kdf_iter"), 128000) try db.execute("CREATE TABLE data(value INTEGER)") try db.execute("INSERT INTO data(value) VALUES(1)") } - try dbQueue!.read { db in + try dbPool.read { db in XCTAssertEqual(try Int.fetchOne(db, "PRAGMA kdf_iter"), 128000) XCTAssertEqual(try Int.fetchOne(db, "SELECT value FROM data"), 1) } @@ -408,6 +415,7 @@ class EncryptionTests: GRDBTestCase { dbConfiguration.passphrase = "secret" do { _ = try makeDatabaseQueue(filename: "plaintext.sqlite") + XCTFail("Expected error") } catch let error as DatabaseError { XCTAssertEqual(error.resultCode, .SQLITE_NOTADB) XCTAssertEqual(error.message!, "file is not a database") From 9040970c8d618d63745f5d4f0610a158ff600c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 9 Mar 2019 14:04:49 +0100 Subject: [PATCH 24/29] CHANGELOG --- CHANGELOG.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70181620b..6b0fd2c47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/). #### 3.x Releases +- `3.7.x` Releases - [3.7.0](#370) - `3.6.x` Releases - [3.6.0](#360) | [3.6.1](#361) | [3.6.2](#362) - `3.5.x` Releases - [3.5.0](#350) - `3.4.x` Releases - [3.4.0](#340) @@ -42,6 +43,24 @@ GRDB adheres to [Semantic Versioning](https://semver.org/). - [0.110.0](#01100), ... +## 3.7.0 + +Released March 9, 2019 • [diff](https://github.com/groue/GRDB.swift/compare/v3.6.2...v3.7.20) + +### Fixed + +- [#496](https://github.com/groue/GRDB.swift/pull/496): Fix crash when trying to perform fetchCount or ValueObservation.trackCount on joined query + +### New + +- [#497](https://github.com/groue/GRDB.swift/pull/497): Add additional SQLCipher configuration options + +### Documentation Diff + +- [Advanced configuration options for SQLCipher](README.md#advanced-configuration-options-for-sqlcipher): this new chapter documents the new GRDBCipher APIs. +- [Enabling FTS5 Support](README.md#enabling-fts5-support) has been updated with a new technique for enabling FTS5 with the GRDB.swift CocoaPod. + + ## 3.6.2 Released January 5, 2019 • [diff](https://github.com/groue/GRDB.swift/compare/v3.6.1...v3.6.2) From d2b2e12a1095693cc7d0a2e661c348abce630e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 9 Mar 2019 14:05:57 +0100 Subject: [PATCH 25/29] Remove CHANGELOG.md requirement from PULL_REQUEST_TEMPLATE.md --- .github/PULL_REQUEST_TEMPLATE.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 1c05fd109..a9a667d0b 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -10,4 +10,3 @@ Please verify that your pull request checks those boxes: - [ ] Inline documentation has been updated. - [ ] README.md or another dedicated guide has been updated. - [ ] Changes are tested, for all flavors of GRDB, GRDBCipher, and GRDBCustomSQLite. -- [ ] CHANGELOG.md has been updated. From aeb41dc1ebdd2439bb56162e0accb4b05451709d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 9 Mar 2019 14:21:28 +0100 Subject: [PATCH 26/29] v3.7.0 --- Documentation/CustomSQLiteBuilds.md | 2 +- GRDB.swift.podspec | 2 +- GRDBCipher.podspec | 2 +- GRDBPlus.podspec | 2 +- Makefile | 6 +-- README.md | 64 ++++++++++++++--------------- Support/Info.plist | 2 +- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Documentation/CustomSQLiteBuilds.md b/Documentation/CustomSQLiteBuilds.md index 29b08440e..933453afa 100644 --- a/Documentation/CustomSQLiteBuilds.md +++ b/Documentation/CustomSQLiteBuilds.md @@ -15,7 +15,7 @@ GRDB builds SQLite with [swiftlyfalling/SQLiteLib](https://github.com/swiftlyfal ```sh cd [GRDB directory] - git checkout v3.6.2 + git checkout v3.7.0 git submodule update --init SQLiteCustom/src ```` diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index a5fccf960..c591c964b 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDB.swift' - s.version = '3.6.2' + s.version = '3.7.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' diff --git a/GRDBCipher.podspec b/GRDBCipher.podspec index eb358a91f..b4c8976de 100644 --- a/GRDBCipher.podspec +++ b/GRDBCipher.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDBCipher' - s.version = '3.6.2' + s.version = '3.7.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' diff --git a/GRDBPlus.podspec b/GRDBPlus.podspec index 34064c1f4..4642ffa29 100644 --- a/GRDBPlus.podspec +++ b/GRDBPlus.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDBPlus' - s.version = '3.6.2' + s.version = '3.7.0' s.deprecated = true s.deprecated_in_favor_of = 'GRDB.swift' diff --git a/Makefile b/Makefile index 9906e062a..0718753de 100644 --- a/Makefile +++ b/Makefile @@ -415,10 +415,10 @@ ifdef JAZZY --author 'Gwendal Roué' \ --author_url https://github.com/groue \ --github_url https://github.com/groue/GRDB.swift \ - --github-file-prefix https://github.com/groue/GRDB.swift/tree/v3.6.2 \ - --module-version 3.6 \ + --github-file-prefix https://github.com/groue/GRDB.swift/tree/v3.7.0 \ + --module-version 3.7 \ --module GRDB \ - --root-url http://groue.github.io/GRDB.swift/docs/3.6/ \ + --root-url http://groue.github.io/GRDB.swift/docs/3.7/ \ --output Documentation/Reference \ --xcodebuild-arguments -project,GRDB.xcodeproj,-scheme,GRDBiOS else diff --git a/README.md b/README.md index 869bf80d5..d5fb2b499 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,15 @@ GRDB 3 [![Swift](https://img.shields.io/badge/swift-4.1-orange.svg?style=flat)]( ### A toolkit for SQLite databases, with a focus on application development -**Latest release**: January 5, 2019 • version 3.6.2 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 2 to GRDB 3](Documentation/GRDB2MigrationGuide.md) +**Latest release**: March 9, 2019 • version 3.7.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 2 to GRDB 3](Documentation/GRDB2MigrationGuide.md) **Requirements**: iOS 8.0+ / macOS 10.9+ / watchOS 2.0+ • Swift 4.1+ / Xcode 9.3+ | Swift version | GRDB version | | ------------- | ----------------------------------------------------------- | | Swift 5 | [v4.0.0](https://github.com/groue/GRDB.swift/tree/GRDB-4.0) :construction: in development | -| **Swift 4.2** | **v3.6.2** | -| **Swift 4.1** | **v3.6.2** | +| **Swift 4.2** | **v3.7.0** | +| **Swift 4.1** | **v3.7.0** | | Swift 4 | [v2.10.0](https://github.com/groue/GRDB.swift/tree/v2.10.0) | | Swift 3.2 | [v1.3.0](https://github.com/groue/GRDB.swift/tree/v1.3.0) | | Swift 3.1 | [v1.3.0](https://github.com/groue/GRDB.swift/tree/v1.3.0) | @@ -242,7 +242,7 @@ Documentation #### Reference -- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/3.6/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) +- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/3.7/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) #### Getting Started @@ -324,7 +324,7 @@ The [Swift Package Manager](https://swift.org/package-manager/) automates the di ```swift let package = Package( dependencies: [ - .package(url: "https://github.com/groue/GRDB.swift.git", from: "3.6.2") + .package(url: "https://github.com/groue/GRDB.swift.git", from: "3.7.0") ] ) ``` @@ -341,7 +341,7 @@ If you decide to use Carthage despite this warning, and get any Carthage-related ## Manually -1. [Download](https://github.com/groue/GRDB.swift/releases/tag/v3.6.2) a copy of GRDB, or clone its repository and make sure you use the latest tagged version with the `git checkout v3.6.2` command. +1. [Download](https://github.com/groue/GRDB.swift/releases/tag/v3.7.0) a copy of GRDB, or clone its repository and make sure you use the latest tagged version with the `git checkout v3.7.0` command. 2. Embed the `GRDB.xcodeproj` project in your own project. @@ -456,7 +456,7 @@ let dbQueue = try DatabaseQueue( configuration: config) ``` -See [Configuration](http://groue.github.io/GRDB.swift/docs/3.6/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/3.7/Structs/Configuration.html) for more details. ## Database Pools @@ -537,7 +537,7 @@ let dbPool = try DatabasePool( configuration: config) ``` -See [Configuration](http://groue.github.io/GRDB.swift/docs/3.6/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/3.7/Structs/Configuration.html) for more details. Database pools are more memory-hungry than database queues. See [Memory Management](#memory-management) for more information. @@ -596,7 +596,7 @@ try dbQueue.write { db in } ``` -The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/3.6/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. +The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/3.7/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. **Never ever embed values directly in your SQL strings**, and always use arguments instead. See [Avoiding SQL Injection](#avoiding-sql-injection) for more information: @@ -769,7 +769,7 @@ Both arrays and cursors can iterate over database results. How do you choose one - **Cursors are granted with direct access to SQLite,** unlike arrays that have to take the time to copy database values. If you look after extra performance, you may prefer cursors over arrays. -- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/3.6/Protocols/Cursor.html) protocol, which looks a lot like standard [lazy sequences](https://developer.apple.com/reference/swift/lazysequenceprotocol) of Swift.** As such, cursors come with many convenience methods: `compactMap`, `contains`, `dropFirst`, `dropLast`, `drop(while:)`, `enumerated`, `filter`, `first`, `flatMap`, `forEach`, `joined`, `joined(separator:)`, `max`, `max(by:)`, `min`, `min(by:)`, `map`, `prefix`, `prefix(while:)`, `reduce`, `reduce(into:)`, `suffix`: +- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/3.7/Protocols/Cursor.html) protocol, which looks a lot like standard [lazy sequences](https://developer.apple.com/reference/swift/lazysequenceprotocol) of Swift.** As such, cursors come with many convenience methods: `compactMap`, `contains`, `dropFirst`, `dropLast`, `drop(while:)`, `enumerated`, `filter`, `first`, `flatMap`, `forEach`, `joined`, `joined(separator:)`, `max`, `max(by:)`, `min`, `min(by:)`, `map`, `prefix`, `prefix(while:)`, `reduce`, `reduce(into:)`, `suffix`: ```swift // Prints all Github links @@ -851,7 +851,7 @@ let rows = try Row.fetchAll(db, arguments: ["name": "Arthur"]) ``` -See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/3.6/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. +See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/3.7/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. Unlike row arrays that contain copies of the database rows, row cursors are close to the SQLite metal, and require a little care: @@ -1134,7 +1134,7 @@ GRDB ships with built-in support for the following value types: - Generally speaking, all types that adopt the [DatabaseValueConvertible](#custom-value-types) protocol. -Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/3.6/Structs/StatementArguments.html): +Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/3.7/Structs/StatementArguments.html): ```swift let url: URL = ... @@ -1541,7 +1541,7 @@ try dbQueue.inDatabase { db in // or dbPool.writeWithoutTransaction } ``` -Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/3.6/Structs/Configuration.html) configuration flag: +Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/3.7/Structs/Configuration.html) configuration flag: ```swift // fatal error: A transaction has been left opened at the end of a database access @@ -1655,7 +1655,7 @@ try dbQueue.write { db in } ``` -The `?` and colon-prefixed keys like `:name` in the SQL query are the statement arguments. You set them with arrays or dictionaries (arguments are actually of type [StatementArguments](http://groue.github.io/GRDB.swift/docs/3.6/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). +The `?` and colon-prefixed keys like `:name` in the SQL query are the statement arguments. You set them with arrays or dictionaries (arguments are actually of type [StatementArguments](http://groue.github.io/GRDB.swift/docs/3.7/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). ```swift updateStatement.arguments = ["name": "Arthur", "score": 1000] @@ -1914,7 +1914,7 @@ row["consumed"] // "Hello" row["produced"] // nil ``` -Row adapters are values that adopt the [RowAdapter](http://groue.github.io/GRDB.swift/docs/3.6/Protocols/RowAdapter.html) protocol. You can implement your own custom adapters ([**:fire: EXPERIMENTAL**](#what-are-experimental-features)), or use one of the four built-in adapters, described below. +Row adapters are values that adopt the [RowAdapter](http://groue.github.io/GRDB.swift/docs/3.7/Protocols/RowAdapter.html) protocol. You can implement your own custom adapters ([**:fire: EXPERIMENTAL**](#what-are-experimental-features)), or use one of the four built-in adapters, described below. To see how row adapters can be used, see [Joined Queries Support](#joined-queries-support). @@ -2057,8 +2057,8 @@ Before jumping in the low-level wagon, here is the list of all SQLite APIs used - `sqlite3_aggregate_context`, `sqlite3_create_function_v2`, `sqlite3_result_blob`, `sqlite3_result_double`, `sqlite3_result_error`, `sqlite3_result_error_code`, `sqlite3_result_int64`, `sqlite3_result_null`, `sqlite3_result_text`, `sqlite3_user_data`, `sqlite3_value_blob`, `sqlite3_value_bytes`, `sqlite3_value_double`, `sqlite3_value_int64`, `sqlite3_value_text`, `sqlite3_value_type`: see [Custom SQL Functions and Aggregates](#custom-sql-functions-and-aggregates) - `sqlite3_backup_finish`, `sqlite3_backup_init`, `sqlite3_backup_step`: see [Backup](#backup) - `sqlite3_bind_blob`, `sqlite3_bind_double`, `sqlite3_bind_int64`, `sqlite3_bind_null`, `sqlite3_bind_parameter_count`, `sqlite3_bind_parameter_name`, `sqlite3_bind_text`, `sqlite3_clear_bindings`, `sqlite3_column_blob`, `sqlite3_column_bytes`, `sqlite3_column_count`, `sqlite3_column_double`, `sqlite3_column_int64`, `sqlite3_column_name`, `sqlite3_column_text`, `sqlite3_column_type`, `sqlite3_exec`, `sqlite3_finalize`, `sqlite3_prepare_v2`, `sqlite3_reset`, `sqlite3_step`: see [Executing Updates](#executing-updates), [Fetch Queries](#fetch-queries), [Prepared Statements](#prepared-statements), [Values](#values) -- `sqlite3_busy_handler`, `sqlite3_busy_timeout`: see [Configuration.busyMode](http://groue.github.io/GRDB.swift/docs/3.6/Structs/Configuration.html) -- `sqlite3_changes`, `sqlite3_total_changes`: see [Database.changesCount and Database.totalChangesCount](http://groue.github.io/GRDB.swift/docs/3.6/Classes/Database.html) +- `sqlite3_busy_handler`, `sqlite3_busy_timeout`: see [Configuration.busyMode](http://groue.github.io/GRDB.swift/docs/3.7/Structs/Configuration.html) +- `sqlite3_changes`, `sqlite3_total_changes`: see [Database.changesCount and Database.totalChangesCount](http://groue.github.io/GRDB.swift/docs/3.7/Classes/Database.html) - `sqlite3_close`, `sqlite3_close_v2`, `sqlite3_next_stmt`, `sqlite3_open_v2`: see [Database Connections](#database-connections) - `sqlite3_commit_hook`, `sqlite3_rollback_hook`, `sqlite3_update_hook`: see [TransactionObserver Protocol](#transactionobserver-protocol), [DatabaseRegionObservation], [ValueObservation], [FetchedRecordsController] - `sqlite3_config`: see [Error Log](#error-log) @@ -2069,9 +2069,9 @@ Before jumping in the low-level wagon, here is the list of all SQLite APIs used - `sqlite3_last_insert_rowid`: see [Executing Updates](#executing-updates) - `sqlite3_preupdate_count`, `sqlite3_preupdate_depth`, `sqlite3_preupdate_hook`, `sqlite3_preupdate_new`, `sqlite3_preupdate_old`: see [Support for SQLite Pre-Update Hooks](#support-for-sqlite-pre-update-hooks) - `sqlite3_set_authorizer`: **reserved by GRDB** -- `sqlite3_sql`: see [Statement.sql](http://groue.github.io/GRDB.swift/docs/3.6/Classes/Statement.html) -- `sqlite3_trace`: see [Configuration.trace](http://groue.github.io/GRDB.swift/docs/3.6/Structs/Configuration.html) -- `sqlite3_wal_checkpoint_v2`: see [DatabasePool.checkpoint](http://groue.github.io/GRDB.swift/docs/3.6/Classes/DatabasePool.html) +- `sqlite3_sql`: see [Statement.sql](http://groue.github.io/GRDB.swift/docs/3.7/Classes/Statement.html) +- `sqlite3_trace`: see [Configuration.trace](http://groue.github.io/GRDB.swift/docs/3.7/Structs/Configuration.html) +- `sqlite3_wal_checkpoint_v2`: see [DatabasePool.checkpoint](http://groue.github.io/GRDB.swift/docs/3.7/Classes/DatabasePool.html) Records @@ -2390,7 +2390,7 @@ try Place.fetchAll(db, "SELECT ...", arguments:...) // [Place] try Place.fetchOne(db, "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. +See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/3.7/Structs/StatementArguments.html) for more information about the query arguments. > :point_up: **Note**: for performance reasons, the same row argument to `init(row:)` is reused during the iteration of a fetch query. If you want to keep the row for later use, make sure to store a copy: `self.row = row.copy()`. @@ -2762,7 +2762,7 @@ protocol MutablePersistableRecord { } ``` -See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/3.6/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/3.6/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/3.6/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. +See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/3.7/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/3.7/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/3.7/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. > :point_up: **Note**: there is no customization of uuid decoding, because UUID can already decode all its encoded variants (16-bytes blobs, and uuid strings). @@ -4019,7 +4019,7 @@ Player // SELECT * FROM player ``` -Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/3.6/Structs/StatementArguments.html): +Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/3.7/Structs/StatementArguments.html): ```swift // SELECT DATE(creationDate), COUNT(*) FROM player WHERE name = 'Arthur' GROUP BY date(creationDate) @@ -4587,7 +4587,7 @@ let request = Player.all() **To build custom requests**, you can use one of the built-in requests, derive requests from other requests, or create your own request type that adopts the [FetchRequest](#fetchrequest-protocol) protocol. -- [SQLRequest](http://groue.github.io/GRDB.swift/docs/3.6/Structs/SQLRequest.html) is a fetch request built from raw SQL. For example: +- [SQLRequest](http://groue.github.io/GRDB.swift/docs/3.7/Structs/SQLRequest.html) is a fetch request built from raw SQL. For example: ```swift extension Player { @@ -4620,7 +4620,7 @@ let request = Player.all() - The `adapted(_:)` method eases the consumption of complex rows with [row adapters](#row-adapters). See [Joined Queries Support](#joined-queries-support) for some sample code that uses this method. -- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/3.6/Structs/AnyFetchRequest.html): a [type-erased](http://chris.eidhof.nl/post/type-erasers-in-swift/) request. +- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/3.7/Structs/AnyFetchRequest.html): a [type-erased](http://chris.eidhof.nl/post/type-erasers-in-swift/) request. ### Fetching From Custom Requests @@ -5050,7 +5050,7 @@ let pattern = FTS3Pattern(matchingAnyTokenIn: "") // nil let pattern = FTS3Pattern(matchingAnyTokenIn: "*") // nil ``` -FTS3Pattern are regular [values](#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/3.6/Structs/StatementArguments.html): +FTS3Pattern are regular [values](#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/3.7/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, @@ -5299,7 +5299,7 @@ let pattern = FTS5Pattern(matchingAnyTokenIn: "") // nil let pattern = FTS5Pattern(matchingAnyTokenIn: "*") // nil ``` -FTS5Pattern are regular [values](#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/3.6/Structs/StatementArguments.html): +FTS5Pattern are regular [values](#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/3.7/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, @@ -7187,7 +7187,7 @@ After `stopObservingDatabaseChangesUntilNextTransaction()`, the `databaseDidChan ### DatabaseRegion -**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/3.6/Structs/DatabaseRegion.html) is a type that helps observing changes in the results of a database [request](#requests)**. +**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/3.7/Structs/DatabaseRegion.html) is a type that helps observing changes in the results of a database [request](#requests)**. A request knows which database modifications can impact its results. It can communicate this information to [transaction observers](#transactionobserver-protocol) by the way of a DatabaseRegion. @@ -7199,7 +7199,7 @@ For example, if you observe the region of `Player.select(max(Column("score")))`, Similarly, observing the region of `Country.filter(key: "FR")` will notify all changes that happen to the whole `country` table. That is because SQLite only notifies the numerical [rowid](https://www.sqlite.org/rowidtable.html) of changed rows, and we can't check if it is the row "FR" that has been changed, or another. This limitation does not apply to tables whose primary key is the rowid: `Player.filter(key: 42)` will only notify of changes performed on the row with id 42. -For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/3.6/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). +For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/3.7/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). #### The DatabaseRegionConvertible Protocol @@ -7254,7 +7254,7 @@ Alternatively, perform a manual installation of GRDB and SQLCipher: ```sh cd [GRDB directory] - git checkout v3.6.2 + git checkout v3.7.0 git submodule update --init SQLCipher/src ``` @@ -8073,7 +8073,7 @@ try snapshot2.read { db in ### DatabaseWriter and DatabaseReader Protocols -Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/3.6/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/3.6/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. +Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/3.7/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/3.7/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. These protocols provide a unified API that let you write generic code that targets all concurrency modes. They fuel, for example: @@ -8188,7 +8188,7 @@ If you absolutely need multiple connections, then: - Read about [isolation in SQLite](https://www.sqlite.org/isolation.html) - Learn about [locks and transactions](https://www.sqlite.org/lang_transaction.html) - Become a master of the [WAL mode](https://www.sqlite.org/wal.html) -- Prepare to setup a [busy handler](https://www.sqlite.org/c3ref/busy_handler.html) with [Configuration.busyMode](http://groue.github.io/GRDB.swift/docs/3.6/Structs/Configuration.html) +- Prepare to setup a [busy handler](https://www.sqlite.org/c3ref/busy_handler.html) with [Configuration.busyMode](http://groue.github.io/GRDB.swift/docs/3.7/Structs/Configuration.html) - [Ask questions](https://github.com/groue/GRDB.swift/issues) diff --git a/Support/Info.plist b/Support/Info.plist index 02e4bb299..767108022 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.6.2 + 3.7.0 CFBundleSignature ???? CFBundleVersion From cd6c4a423278bb671f81087c9e802b306df74738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 9 Mar 2019 15:11:48 +0100 Subject: [PATCH 27/29] CHANGELOG --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b0fd2c47..2db6d5601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,11 +53,12 @@ Released March 9, 2019 • [diff](https://github.com/groue/GRDB.swift/compare ### New -- [#497](https://github.com/groue/GRDB.swift/pull/497): Add additional SQLCipher configuration options +- [#494](https://github.com/groue/GRDB.swift/pull/494)by [@davidkraus](https://github.com/davidkraus): Document how to enable FTS5 with GRDB.swift CocoaPod +- [#497](https://github.com/groue/GRDB.swift/pull/497)by [@Marus](https://github.com/Marus): Add additional SQLCipher configuration options ### Documentation Diff -- [Advanced configuration options for SQLCipher](README.md#advanced-configuration-options-for-sqlcipher): this new chapter documents the new GRDBCipher APIs. +- [Advanced configuration options for SQLCipher](README.md#advanced-configuration-options-for-sqlcipher): this new chapter documents the new database encryption APIs. - [Enabling FTS5 Support](README.md#enabling-fts5-support) has been updated with a new technique for enabling FTS5 with the GRDB.swift CocoaPod. From d88fb4d96f2add43968256522127909c75fd18a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 9 Mar 2019 15:27:09 +0100 Subject: [PATCH 28/29] Fix typo --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2db6d5601..0423ae96c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,8 +53,8 @@ Released March 9, 2019 • [diff](https://github.com/groue/GRDB.swift/compare ### New -- [#494](https://github.com/groue/GRDB.swift/pull/494)by [@davidkraus](https://github.com/davidkraus): Document how to enable FTS5 with GRDB.swift CocoaPod -- [#497](https://github.com/groue/GRDB.swift/pull/497)by [@Marus](https://github.com/Marus): Add additional SQLCipher configuration options +- [#494](https://github.com/groue/GRDB.swift/pull/494) by [@davidkraus](https://github.com/davidkraus): Document how to enable FTS5 with GRDB.swift CocoaPod +- [#497](https://github.com/groue/GRDB.swift/pull/497) by [@Marus](https://github.com/Marus): Add additional SQLCipher configuration options ### Documentation Diff From 973e82b13982deeef6477979d0a8ef8a1605c23f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 10 Mar 2019 05:48:25 +0100 Subject: [PATCH 29/29] Fix a typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d5fb2b499..571354a9c 100644 --- a/README.md +++ b/README.md @@ -7319,7 +7319,7 @@ let dbQueue = try DatabaseQueue(path: "...", configuration: configuration) The `cipherPageSize` is used to adjust the page size for the encrypted database (this corresponds to the [SQLCipher `PRAGMA cipher_page_size`](https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_page_size) configuration option). Increasing the page size can noticeably improve performance for certain queries that access large numbers of pages. -The default `cipherPageSize` in the current version of SQLCipher used in GRDB.swift is `.pageSize1K`. +The default `cipherPageSize` in the current version of SQLCipher used in GRDB.swift is `1024`. > :point_up: **Note**: the same `cipherPageSize` must be supplied every time that the database file is open; attempting to access the database without setting the proper `cipherPageSize` will result in the `SQLite error 26: file is encrypted or is not a database` error being thrown.