mirror of
https://github.com/groue/GRDB.swift
synced 2026-12-06 05:28:44 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6ab92e60a | ||
|
|
c0d5f3019b | ||
|
|
b09d5c3833 | ||
|
|
3eff1b48b1 | ||
|
|
a12fffc4e7 | ||
|
|
94715130fc | ||
|
|
313188ca0e | ||
|
|
5a68b008c6 | ||
|
|
6fe9098c76 | ||
|
|
631a914acd | ||
|
|
d1f24c9722 | ||
|
|
7b76c9319a | ||
|
|
63083c5d1e | ||
|
|
c51a3cd624 | ||
|
|
1fadb7485a | ||
|
|
58e05d13d1 | ||
|
|
d8c9692d4d | ||
|
|
f83ffd3a25 | ||
|
|
d12ff2a92b | ||
|
|
8709d6f9a9 | ||
|
|
e2806c55ff | ||
|
|
08d6c843d6 | ||
|
|
0da3726a89 | ||
|
|
36676bcad3 | ||
|
|
1509e1e9a8 | ||
|
|
4c71dd9ebe | ||
|
|
ef8d0d6334 | ||
|
|
7477b7a173 | ||
|
|
246f36821b | ||
|
|
d567ee60bf | ||
|
|
3a157d2808 | ||
|
|
7d0c2f9ef8 | ||
|
|
f356f8734a | ||
|
|
5b7f4a7ff5 | ||
|
|
e10efca17a |
No files matched your search
+20
-1
@@ -1,6 +1,25 @@
|
||||
Release Notes
|
||||
=============
|
||||
|
||||
## 2.4.2
|
||||
|
||||
Released January 6, 2018 • [diff](https://github.com/groue/GRDB.swift/compare/v2.4.1...v2.4.2)
|
||||
|
||||
**Fixed**
|
||||
|
||||
- When using a database pool, the schema introspection methods could return wrong values whenever the database schema was concurrently read and modified. This has been fixed.
|
||||
- `DatabasePool.readFromCurrentState` no longer accepts to spawn a reader when a transaction is currently opened on the writer connection.
|
||||
|
||||
|
||||
## 2.4.1
|
||||
|
||||
Released December 16, 2017 • [diff](https://github.com/groue/GRDB.swift/compare/v2.4.0...v2.4.1)
|
||||
|
||||
**Fixed**
|
||||
|
||||
- [#284](https://github.com/groue/GRDB.swift/pull/284): fixes a misuse of the sqlite3_config() function when configuring the global SQLite [Error Log](https://github.com/groue/GRDB.swift/blob/master/README.md#error-log)
|
||||
|
||||
|
||||
## 2.4.0
|
||||
|
||||
Released December 3, 2017 • [diff](https://github.com/groue/GRDB.swift/compare/v2.3.1...v2.4.0)
|
||||
@@ -19,7 +38,7 @@ Released December 3, 2017 • [diff](https://github.com/groue/GRDB.swift/comp
|
||||
|
||||
**Breaking Change**
|
||||
|
||||
- [#282](https://github.com/groue/GRDB.swift/issues/282) This version comes with a breaking change that affects users who manually embed the GRDBCipher and GRDBCustom frameworks in their projects. This change does not affect users of the GRDB framework, or users of GRDBCipher through CocoaPods. Now, instead of embedding the GRDB.xcodeproj project, you have to embed the GRDBCipher.xcodeproj or GRDBCustom.xcodeproj. Please have a look at the updated [Encryption](https://github.com/groue/GRDB.swift/blob/master/README.md#encryption) and [Custom SQLite Builds](https://github.com/groue/GRDB.swift/blob/master/Documentation/CustomSQLiteBuilds.md) documentation chapters.
|
||||
- [#282](https://github.com/groue/GRDB.swift/issues/282): This version comes with a breaking change that affects users who manually embed the GRDBCipher and GRDBCustom frameworks in their projects. This change does not affect users of the GRDB framework, or users of GRDBCipher through CocoaPods. Now, instead of embedding the GRDB.xcodeproj project, you have to embed the GRDBCipher.xcodeproj or GRDBCustom.xcodeproj. Please have a look at the updated [Encryption](https://github.com/groue/GRDB.swift/blob/master/README.md#encryption) and [Custom SQLite Builds](https://github.com/groue/GRDB.swift/blob/master/Documentation/CustomSQLiteBuilds.md) documentation chapters.
|
||||
|
||||
|
||||
## 2.3.1
|
||||
|
||||
@@ -15,7 +15,7 @@ GRDB builds SQLite with [swiftlyfalling/SQLiteLib](https://github.com/swiftlyfal
|
||||
|
||||
```sh
|
||||
cd [GRDB directory]
|
||||
git checkout v2.4.0
|
||||
git checkout v2.4.2
|
||||
git submodule update --init SQLiteCustom/src
|
||||
````
|
||||
|
||||
|
||||
@@ -30,3 +30,6 @@ To release a new GRDB version:
|
||||
- `make doc`, and update index.html in the `gh-pages` branch
|
||||
- Update http://github.com/groue/GRDBDemo
|
||||
- Update http://github.com/groue/WWDCCompanion
|
||||
- Update [performance comparison](https://github.com/groue/GRDB.swift/wiki/Performance):
|
||||
|
||||
`make test_performance | Tests/parsePerformanceTests.rb | Tests/generatePerformanceReport.rb`
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'GRDB.swift'
|
||||
s.version = '2.4.0'
|
||||
s.version = '2.4.2'
|
||||
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
s.summary = 'A Swift application toolkit for SQLite databases.'
|
||||
|
||||
@@ -821,7 +821,6 @@
|
||||
5674A70B1F3087700095F066 /* DatabaseValueConvertibleEncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEncodableTests.swift; sourceTree = "<group>"; };
|
||||
5674A71C1F30A8DF0095F066 /* MutablePersistableEncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MutablePersistableEncodableTests.swift; sourceTree = "<group>"; };
|
||||
5674A7261F30A9090095F066 /* RowConvertibleDecodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RowConvertibleDecodableTests.swift; sourceTree = "<group>"; };
|
||||
5677C2551E68419700D1BDFE /* ReleaseProcess.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = ReleaseProcess.md; path = Documentation/ReleaseProcess.md; sourceTree = "<group>"; };
|
||||
567A80521D41350C00C7DCEC /* IndexInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndexInfoTests.swift; sourceTree = "<group>"; };
|
||||
567DAF141EAB61ED00FC0928 /* grdb_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = grdb_config.h; sourceTree = "<group>"; };
|
||||
567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseLogErrorTests.swift; sourceTree = "<group>"; };
|
||||
@@ -908,8 +907,8 @@
|
||||
56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedRecordsControllerTests.swift; sourceTree = "<group>"; };
|
||||
56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloatTests.swift; sourceTree = "<group>"; };
|
||||
56B7F4391BEB42D500E39BBF /* Migration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Migration.swift; sourceTree = "<group>"; };
|
||||
56B8C2401CA1758F00510325 /* Realm.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Realm.framework; path = "Realm/build/osx/swift-4.0.2/Realm.framework"; sourceTree = "<group>"; };
|
||||
56B8C2411CA1758F00510325 /* RealmSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RealmSwift.framework; path = "Realm/build/osx/swift-4.0.2/RealmSwift.framework"; sourceTree = "<group>"; };
|
||||
56B8C2401CA1758F00510325 /* Realm.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Realm.framework; path = "Realm/build/osx/swift-4.0.3/Realm.framework"; sourceTree = "<group>"; };
|
||||
56B8C2411CA1758F00510325 /* RealmSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RealmSwift.framework; path = "Realm/build/osx/swift-4.0.3/RealmSwift.framework"; sourceTree = "<group>"; };
|
||||
56B8F49A1B4E2F3600C24296 /* GRDB.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = GRDB.xcconfig; sourceTree = "<group>"; };
|
||||
56B9649C1DA51B4C0002DA19 /* FTS5.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5.swift; sourceTree = "<group>"; };
|
||||
56B964B01DA51D010002DA19 /* FTS5TokenizerDescriptor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5TokenizerDescriptor.swift; sourceTree = "<group>"; };
|
||||
@@ -957,7 +956,6 @@
|
||||
56D51CFF1EA789FA0074638A /* RowConvertible+TableMapping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RowConvertible+TableMapping.swift"; sourceTree = "<group>"; };
|
||||
56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCursorTests.swift; sourceTree = "<group>"; };
|
||||
56DAA2DA1DE9C827006E10C8 /* Cursor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cursor.swift; sourceTree = "<group>"; };
|
||||
56DBEC341C19A0020093A2EE /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
|
||||
56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementArgumentsTests.swift; sourceTree = "<group>"; };
|
||||
56DE7B231C412F7E00861EB8 /* InsertPositionalValuesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InsertPositionalValuesTests.swift; sourceTree = "<group>"; };
|
||||
56DE7B251C412FDA00861EB8 /* InsertNamedValuesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InsertNamedValuesTests.swift; sourceTree = "<group>"; };
|
||||
@@ -968,7 +966,6 @@
|
||||
56DE7B341C42B37E00861EB8 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
|
||||
56DE7B361C42BBBB00861EB8 /* PerformanceCoreDataTests.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = PerformanceCoreDataTests.sqlite; sourceTree = "<group>"; };
|
||||
56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.102.0.swift"; sourceTree = "<group>"; };
|
||||
56E1524B1B43FD5B00EE27AA /* TODO.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = TODO.md; sourceTree = "<group>"; };
|
||||
56E5D7CA1B4D3FED00430942 /* GRDB.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GRDB.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
56E5D7D31B4D3FEE00430942 /* GRDBiOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBiOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
56E5D7F91B4D422D00430942 /* GRDBOSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBOSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@@ -993,7 +990,6 @@
|
||||
DC3773F719C8CBB3004FCF85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
DC3773F819C8CBB3004FCF85 /* GRDB.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GRDB.h; sourceTree = "<group>"; };
|
||||
DC37740419C8CBB3004FCF85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
DC37744719C8F50B004FCF85 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -1365,13 +1361,6 @@
|
||||
name = Private;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
569DF96F1DB8E9270003D0CC /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
56A238111B9C74A90082EB20 /* Core */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -1654,14 +1643,9 @@
|
||||
DC3773E919C8CBB3004FCF85 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56DBEC341C19A0020093A2EE /* CHANGELOG.md */,
|
||||
DC37744719C8F50B004FCF85 /* README.md */,
|
||||
56E1524B1B43FD5B00EE27AA /* TODO.md */,
|
||||
5677C2551E68419700D1BDFE /* ReleaseProcess.md */,
|
||||
DC37742D19C8CC90004FCF85 /* GRDB */,
|
||||
DC10500F19C904DD00D8CA30 /* Tests */,
|
||||
DC3773F419C8CBB3004FCF85 /* Products */,
|
||||
569DF96F1DB8E9270003D0CC /* Frameworks */,
|
||||
);
|
||||
indentWidth = 4;
|
||||
sourceTree = "<group>";
|
||||
@@ -2787,8 +2771,7 @@
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(PROJECT_DIR)/Tests/Performance/Realm/build/osx/swift-4.0",
|
||||
"$(PROJECT_DIR)/Tests/Performance/Realm/build/osx/swift-4.0.2",
|
||||
"$(PROJECT_DIR)/Tests/Performance/Realm/build/osx/swift-4.0.3",
|
||||
);
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
INFOPLIST_FILE = Tests/Info.plist;
|
||||
@@ -2810,8 +2793,7 @@
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(PROJECT_DIR)/Tests/Performance/Realm/build/osx/swift-4.0",
|
||||
"$(PROJECT_DIR)/Tests/Performance/Realm/build/osx/swift-4.0.2",
|
||||
"$(PROJECT_DIR)/Tests/Performance/Realm/build/osx/swift-4.0.3",
|
||||
);
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
INFOPLIST_FILE = Tests/Info.plist;
|
||||
@@ -3131,7 +3113,6 @@
|
||||
APPLICATION_EXTENSION_API_ONLY = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
@@ -3152,7 +3133,6 @@
|
||||
APPLICATION_EXTENSION_API_ONLY = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
|
||||
+15
@@ -23,6 +23,21 @@
|
||||
location = "group:MyPlayground.playground">
|
||||
</FileRef>
|
||||
</Group>
|
||||
<FileRef
|
||||
location = "group:CHANGELOG.md">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:README.md">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:TODO.md">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:Documentation/ReleaseProcess.md">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:Makefile">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:GRDB.xcodeproj">
|
||||
</FileRef>
|
||||
|
||||
@@ -14,7 +14,7 @@ extension Database {
|
||||
/// - returns: A SelectStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
public func makeSelectStatement(_ sql: String) throws -> SelectStatement {
|
||||
return try makeStatement(sql, prepFlags: 0)
|
||||
return try makeSelectStatement(sql, prepFlags: 0)
|
||||
}
|
||||
|
||||
/// Returns a new prepared statement that can be reused.
|
||||
@@ -29,7 +29,7 @@ extension Database {
|
||||
/// - returns: A SelectStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
func makeSelectStatement(_ sql: String, prepFlags: Int32) throws -> SelectStatement {
|
||||
return try makeStatement(sql, prepFlags: prepFlags)
|
||||
return try SelectStatement.prepare(sql: sql, prepFlags: prepFlags, in: self)
|
||||
}
|
||||
|
||||
/// Returns a prepared statement that can be reused.
|
||||
@@ -63,7 +63,7 @@ extension Database {
|
||||
/// - returns: An UpdateStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
public func makeUpdateStatement(_ sql: String) throws -> UpdateStatement {
|
||||
return try makeStatement(sql, prepFlags: 0)
|
||||
return try makeUpdateStatement(sql, prepFlags: 0)
|
||||
}
|
||||
|
||||
/// Returns a new prepared statement that can be reused.
|
||||
@@ -78,7 +78,7 @@ extension Database {
|
||||
/// - returns: An UpdateStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
func makeUpdateStatement(_ sql: String, prepFlags: Int32) throws -> UpdateStatement {
|
||||
return try makeStatement(sql, prepFlags: prepFlags)
|
||||
return try UpdateStatement.prepare(sql: sql, prepFlags: prepFlags, in: self)
|
||||
}
|
||||
|
||||
/// Returns a prepared statement that can be reused.
|
||||
@@ -185,41 +185,6 @@ extension Database {
|
||||
// arguments that do not match the statement.
|
||||
try! validateRemainingArguments() // throws if there are remaining arguments.
|
||||
}
|
||||
|
||||
private func makeStatement<Statement: AuthorizedStatement>(_ sql: String, prepFlags: Int32) throws -> Statement {
|
||||
let statementCompilationAuthorizer = StatementCompilationAuthorizer()
|
||||
authorizer = statementCompilationAuthorizer
|
||||
defer { authorizer = nil }
|
||||
|
||||
var statement: Statement? = nil
|
||||
let sqlCodeUnits = sql.utf8CString
|
||||
var remainingSQL = ""
|
||||
try sqlCodeUnits.withUnsafeBufferPointer { codeUnits in
|
||||
let statementStart = UnsafePointer<Int8>(codeUnits.baseAddress)!
|
||||
var statementEnd: UnsafePointer<Int8>? = nil
|
||||
do {
|
||||
statement = try Statement(
|
||||
database: self,
|
||||
statementStart: statementStart,
|
||||
statementEnd: &statementEnd,
|
||||
prepFlags: prepFlags,
|
||||
authorizer: statementCompilationAuthorizer)
|
||||
} catch is EmptyStatementError {
|
||||
throw DatabaseError(resultCode: .SQLITE_ERROR, message: "empty statement", sql: sql, arguments: nil)
|
||||
}
|
||||
let remainingData = Data(
|
||||
bytesNoCopy: UnsafeMutableRawPointer(mutating: statementEnd!),
|
||||
count: statementStart + sqlCodeUnits.count - statementEnd! - 1,
|
||||
deallocator: .none)
|
||||
remainingSQL = String(data: remainingData, encoding: .utf8)!.trimmingCharacters(in: statementSeparatorCharacterSet)
|
||||
}
|
||||
|
||||
guard remainingSQL.isEmpty else {
|
||||
throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "Multiple statements found. To execute multiple statements, use Database.execute() instead.", sql: sql, arguments: nil)
|
||||
}
|
||||
|
||||
return statement!
|
||||
}
|
||||
}
|
||||
|
||||
extension Database {
|
||||
|
||||
+14
-24
@@ -46,7 +46,20 @@ public final class Database {
|
||||
/// > advantage of the error logging facility of SQLite in their products,
|
||||
/// > as it is very low CPU and memory cost but can be a huge aid
|
||||
/// > for debugging.
|
||||
public static var logError: LogErrorFunction? = nil
|
||||
public static var logError: LogErrorFunction? = nil {
|
||||
didSet {
|
||||
if logError != nil {
|
||||
registerErrorLogCallback { (_, code, message) in
|
||||
guard let logError = Database.logError else { return }
|
||||
guard let message = message.map({ String(cString: $0) }) else { return }
|
||||
let resultCode = ResultCode(rawValue: code)
|
||||
logError(resultCode, message)
|
||||
}
|
||||
} else {
|
||||
registerErrorLogCallback(nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The database configuration
|
||||
public let configuration: Configuration
|
||||
@@ -145,9 +158,6 @@ public final class Database {
|
||||
// MARK: - Initializer
|
||||
|
||||
init(path: String, configuration: Configuration, schemaCache: DatabaseSchemaCache) throws {
|
||||
// Setup the global SQLite error log before connecting to the database.
|
||||
Database.setupGlobalErrorLog()
|
||||
|
||||
let sqliteConnection = try Database.openConnection(path: path, flags: configuration.SQLiteOpenFlags)
|
||||
do {
|
||||
try Database.activateExtendedCodes(sqliteConnection)
|
||||
@@ -179,26 +189,6 @@ extension Database {
|
||||
|
||||
// MARK: - Database Opening
|
||||
|
||||
/// Registers the public Database.logError function as the global SQLite
|
||||
/// error log, with sqlite3_config(SQLITE_CONFIG_LOG).
|
||||
///
|
||||
/// See https://sqlite.org/c3ref/c_config_covering_index_scan.html#sqliteconfiglog
|
||||
private static func setupGlobalErrorLog() {
|
||||
// We use a Swift static variable as a way to ensure that the error log
|
||||
// is registered once and only once.
|
||||
struct Impl {
|
||||
static let setupErrorLog: () = {
|
||||
registerErrorLogCallback { (_, code, message) in
|
||||
guard let log = Database.logError else { return }
|
||||
guard let message = message.map({ String(cString: $0) }) else { return }
|
||||
let resultCode = ResultCode(rawValue: code)
|
||||
log(resultCode, message)
|
||||
}
|
||||
}()
|
||||
}
|
||||
Impl.setupErrorLog
|
||||
}
|
||||
|
||||
private static func openConnection(path: String, flags: Int32) throws -> SQLiteConnection {
|
||||
// See https://www.sqlite.org/c3ref/open.html
|
||||
var sqliteConnection: SQLiteConnection? = nil
|
||||
|
||||
@@ -44,14 +44,11 @@ public final class DatabasePool {
|
||||
public init(path: String, configuration: Configuration = Configuration()) throws {
|
||||
GRDBPrecondition(configuration.maximumReaderCount > 0, "configuration.maximumReaderCount must be at least 1")
|
||||
|
||||
// Writer and readers share the same database schema cache
|
||||
let sharedSchemaCache = SharedDatabaseSchemaCache()
|
||||
|
||||
// Writer
|
||||
writer = try SerializedDatabase(
|
||||
path: path,
|
||||
configuration: configuration,
|
||||
schemaCache: sharedSchemaCache)
|
||||
schemaCache: SimpleDatabaseSchemaCache())
|
||||
|
||||
// Activate WAL Mode unless readonly
|
||||
if !configuration.readonly {
|
||||
@@ -84,7 +81,7 @@ public final class DatabasePool {
|
||||
let reader = try SerializedDatabase(
|
||||
path: path,
|
||||
configuration: self.readerConfig,
|
||||
schemaCache: sharedSchemaCache)
|
||||
schemaCache: SimpleDatabaseSchemaCache())
|
||||
|
||||
reader.sync { db in
|
||||
for function in self.functions {
|
||||
@@ -250,6 +247,8 @@ extension DatabasePool : DatabaseReader {
|
||||
// The block isolation comes from the DEFERRED transaction.
|
||||
// See DatabasePoolTests.testReadMethodIsolationOfBlock().
|
||||
try db.inTransaction(.deferred) {
|
||||
// Reset the schema cache before running user code in snapshot isolation
|
||||
db.schemaCache = SimpleDatabaseSchemaCache()
|
||||
result = try block(db)
|
||||
return .commit
|
||||
}
|
||||
@@ -287,7 +286,11 @@ extension DatabasePool : DatabaseReader {
|
||||
public func unsafeRead<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
GRDBPrecondition(currentReader == nil, "Database methods are not reentrant.")
|
||||
return try readerPool.get { reader in
|
||||
try reader.sync(block)
|
||||
try reader.sync { db in
|
||||
// No schema cache when snapshot isolation is not established
|
||||
db.schemaCache = EmptyDatabaseSchemaCache()
|
||||
return try block(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +326,11 @@ extension DatabasePool : DatabaseReader {
|
||||
return try reader.reentrantSync(block)
|
||||
} else {
|
||||
return try readerPool.get { reader in
|
||||
try reader.sync(block)
|
||||
try reader.sync { db in
|
||||
// No schema cache when snapshot isolation is not established
|
||||
db.schemaCache = EmptyDatabaseSchemaCache()
|
||||
return try block(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -504,7 +511,8 @@ extension DatabasePool : DatabaseWriter {
|
||||
/// Asynchronously executes a read-only block in a protected dispatch queue,
|
||||
/// wrapped in a deferred transaction.
|
||||
///
|
||||
/// This method must be called from the writing dispatch queue.
|
||||
/// This method must be called from the writing dispatch queue, outside of a
|
||||
/// transaction. You'll get a fatal error otherwise.
|
||||
///
|
||||
/// The *block* argument is guaranteed to see the database in the last
|
||||
/// committed state at the moment this method is called. Eventual concurrent
|
||||
@@ -570,8 +578,11 @@ extension DatabasePool : DatabaseWriter {
|
||||
// UPDATE ...
|
||||
// Here the change is not visible by GRDB user
|
||||
|
||||
// This method must be called from the writing dispatch queue:
|
||||
writer.preconditionValidQueue()
|
||||
// Check that we're on the writer queue...
|
||||
writer.execute { db in
|
||||
// ... and that no transaction is opened.
|
||||
GRDBPrecondition(!db.isInsideTransaction, "readFromCurrentState must not be called from inside a transaction.")
|
||||
}
|
||||
|
||||
// The semaphore that blocks the writing dispatch queue until snapshot
|
||||
// isolation has been established:
|
||||
@@ -590,7 +601,11 @@ extension DatabasePool : DatabaseWriter {
|
||||
return
|
||||
}
|
||||
semaphore.signal() // We can release the writer queue now that we are isolated for good
|
||||
|
||||
// Reset the schema cache before running user code in snapshot isolation
|
||||
db.schemaCache = SimpleDatabaseSchemaCache()
|
||||
block(db)
|
||||
|
||||
_ = try? db.commit() // Ignore commit error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,20 +296,28 @@ extension DatabaseQueue : DatabaseWriter {
|
||||
/// SQLCipher, attempts to write in the database throw a DatabaseError whose
|
||||
/// resultCode is `SQLITE_READONLY`.
|
||||
///
|
||||
/// This method must be called from the protected database dispatch queue.
|
||||
/// This method must be called from the protected database dispatch queue,
|
||||
/// outside of a transaction. You'll get a fatal error otherwise.
|
||||
///
|
||||
/// See `DatabaseWriter.readFromCurrentState`.
|
||||
public func readFromCurrentState(_ block: @escaping (Database) -> Void) {
|
||||
// query_only pragma was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
|
||||
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
|
||||
#if GRDBCUSTOMSQLITE || GRDBCIPHER
|
||||
serializedDatabase.execute { readOnly($0, block) }
|
||||
#else
|
||||
if #available(iOS 8.2, OSX 10.10, *) {
|
||||
serializedDatabase.execute { readOnly($0, block) }
|
||||
} else {
|
||||
serializedDatabase.execute(block)
|
||||
}
|
||||
#endif
|
||||
// Check that we're on the correct queue...
|
||||
serializedDatabase.execute { db in
|
||||
// ... and that no transaction is opened.
|
||||
GRDBPrecondition(!db.isInsideTransaction, "readFromCurrentState must not be called from inside a transaction.")
|
||||
|
||||
// query_only pragma was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
|
||||
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
|
||||
#if GRDBCUSTOMSQLITE || GRDBCIPHER
|
||||
readOnly(db, block)
|
||||
#else
|
||||
if #available(iOS 8.2, OSX 10.10, *) {
|
||||
readOnly(db, block)
|
||||
} else {
|
||||
block(db)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// Synchronously executes a block in a protected dispatch queue, and
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
/// The protocol for schema cache.
|
||||
///
|
||||
/// This protocol must not contain values that are valid for a single connection
|
||||
/// only, because several connections can share the same schema cache.
|
||||
///
|
||||
/// Statements can't be cached here, for example.
|
||||
/// The protocol for database schema cache.
|
||||
protocol DatabaseSchemaCache {
|
||||
mutating func clear()
|
||||
|
||||
@@ -21,13 +16,13 @@ protocol DatabaseSchemaCache {
|
||||
}
|
||||
|
||||
/// A thread-unsafe database schema cache
|
||||
final class SimpleDatabaseSchemaCache: DatabaseSchemaCache {
|
||||
struct SimpleDatabaseSchemaCache: DatabaseSchemaCache {
|
||||
private var primaryKeys: [String: PrimaryKeyInfo] = [:]
|
||||
private var columns: [String: [ColumnInfo]] = [:]
|
||||
private var indexes: [String: [IndexInfo]] = [:]
|
||||
private var foreignKeys: [String: [ForeignKeyInfo]] = [:]
|
||||
|
||||
func clear() {
|
||||
mutating func clear() {
|
||||
primaryKeys = [:]
|
||||
columns = [:]
|
||||
indexes = [:]
|
||||
@@ -38,7 +33,7 @@ final class SimpleDatabaseSchemaCache: DatabaseSchemaCache {
|
||||
return primaryKeys[table]
|
||||
}
|
||||
|
||||
func set(primaryKey: PrimaryKeyInfo, forTable table: String) {
|
||||
mutating func set(primaryKey: PrimaryKeyInfo, forTable table: String) {
|
||||
primaryKeys[table] = primaryKey
|
||||
}
|
||||
|
||||
@@ -46,7 +41,7 @@ final class SimpleDatabaseSchemaCache: DatabaseSchemaCache {
|
||||
return columns[table]
|
||||
}
|
||||
|
||||
func set(columns: [ColumnInfo], forTable table: String) {
|
||||
mutating func set(columns: [ColumnInfo], forTable table: String) {
|
||||
self.columns[table] = columns
|
||||
}
|
||||
|
||||
@@ -54,7 +49,7 @@ final class SimpleDatabaseSchemaCache: DatabaseSchemaCache {
|
||||
return indexes[table]
|
||||
}
|
||||
|
||||
func set(indexes: [IndexInfo], forTable table: String) {
|
||||
mutating func set(indexes: [IndexInfo], forTable table: String) {
|
||||
self.indexes[table] = indexes
|
||||
}
|
||||
|
||||
@@ -62,48 +57,24 @@ final class SimpleDatabaseSchemaCache: DatabaseSchemaCache {
|
||||
return foreignKeys[table]
|
||||
}
|
||||
|
||||
func set(foreignKeys: [ForeignKeyInfo], forTable table: String) {
|
||||
mutating func set(foreignKeys: [ForeignKeyInfo], forTable table: String) {
|
||||
self.foreignKeys[table] = foreignKeys
|
||||
}
|
||||
}
|
||||
|
||||
/// A thread-safe database schema cache
|
||||
final class SharedDatabaseSchemaCache: DatabaseSchemaCache {
|
||||
private let cache = ReadWriteBox(SimpleDatabaseSchemaCache())
|
||||
/// An always empty database schema cache
|
||||
struct EmptyDatabaseSchemaCache: DatabaseSchemaCache {
|
||||
func clear() { }
|
||||
|
||||
func clear() {
|
||||
cache.write { $0.clear() }
|
||||
}
|
||||
func primaryKey(_ table: String) -> PrimaryKeyInfo? { return nil }
|
||||
mutating func set(primaryKey: PrimaryKeyInfo, forTable table: String) { }
|
||||
|
||||
func primaryKey(_ table: String) -> PrimaryKeyInfo? {
|
||||
return cache.read { $0.primaryKey(table) }
|
||||
}
|
||||
func columns(in table: String) -> [ColumnInfo]? { return nil }
|
||||
mutating func set(columns: [ColumnInfo], forTable table: String) { }
|
||||
|
||||
func set(primaryKey: PrimaryKeyInfo, forTable table: String) {
|
||||
cache.write { $0.set(primaryKey: primaryKey, forTable: table) }
|
||||
}
|
||||
func indexes(on table: String) -> [IndexInfo]? { return nil }
|
||||
mutating func set(indexes: [IndexInfo], forTable table: String) { }
|
||||
|
||||
func columns(in table: String) -> [ColumnInfo]? {
|
||||
return cache.read { $0.columns(in: table) }
|
||||
}
|
||||
|
||||
func set(columns: [ColumnInfo], forTable table: String) {
|
||||
cache.write { $0.set(columns: columns, forTable: table) }
|
||||
}
|
||||
|
||||
func indexes(on table: String) -> [IndexInfo]? {
|
||||
return cache.read { $0.indexes(on: table) }
|
||||
}
|
||||
|
||||
func set(indexes: [IndexInfo], forTable table: String) {
|
||||
cache.write { $0.set(indexes: indexes, forTable: table) }
|
||||
}
|
||||
|
||||
func foreignKeys(on table: String) -> [ForeignKeyInfo]? {
|
||||
return cache.read { $0.foreignKeys(on: table) }
|
||||
}
|
||||
|
||||
func set(foreignKeys: [ForeignKeyInfo], forTable table: String) {
|
||||
cache.write { $0.set(foreignKeys: foreignKeys, forTable: table) }
|
||||
}
|
||||
func foreignKeys(on table: String) -> [ForeignKeyInfo]? { return nil }
|
||||
mutating func set(foreignKeys: [ForeignKeyInfo], forTable table: String) { }
|
||||
}
|
||||
@@ -41,65 +41,23 @@ public protocol DatabaseWriter : DatabaseReader {
|
||||
/// Synchronously or asynchronously executes a read-only block that takes a
|
||||
/// database connection.
|
||||
///
|
||||
/// This method must be called from a writing dispatch queue.
|
||||
/// This method must be called from a writing dispatch queue, outside of any
|
||||
/// transaction. You'll get a fatal error otherwise.
|
||||
///
|
||||
/// The *block* argument is guaranteed to see the database in the state it
|
||||
/// has at the moment this method is called (see below). Eventual concurrent
|
||||
/// The *block* argument is guaranteed to see the database in the last
|
||||
/// committed state at the moment this method is called. Eventual concurrent
|
||||
/// database updates are *not visible* inside the block.
|
||||
///
|
||||
/// What is the "current state" of the database?
|
||||
/// For example:
|
||||
///
|
||||
/// - When this method is called outside of any transaction, the current
|
||||
/// state is the last committed state.
|
||||
///
|
||||
/// try writer.write { db in
|
||||
/// try db.execute("DELETE FROM players")
|
||||
/// try writer.readFromCurrentState { db in
|
||||
/// // Guaranteed to be zero
|
||||
/// try Int.fetchOne(db, "SELECT COUNT(*) FROM players")!
|
||||
/// }
|
||||
/// try db.execute("INSERT INTO players ...")
|
||||
/// try writer.write { db in
|
||||
/// try db.execute("DELETE FROM players")
|
||||
/// try writer.readFromCurrentState { db in
|
||||
/// // Guaranteed to be zero
|
||||
/// try Int.fetchOne(db, "SELECT COUNT(*) FROM players")!
|
||||
/// }
|
||||
///
|
||||
/// - When this method is called inside an uncommitted transation, the
|
||||
/// current state depends on the caller:
|
||||
///
|
||||
/// DatabasePool.readFromCurrentState runs *block* asynchronously in a
|
||||
/// concurrent reader dispatch queue, and release the writing dispatch
|
||||
/// queue early, before the block has finished. In the example below,
|
||||
/// the insertion runs concurrently with the select, and the select sees
|
||||
/// the database in its last committed state.
|
||||
///
|
||||
/// try dbPool.write { db in
|
||||
/// try db.execute("DELETE FROM players")
|
||||
/// db.inTransaction {
|
||||
/// try db.execute("INSERT INTO players ...")
|
||||
/// try dbPool.readFromCurrentState { db in
|
||||
/// // Zero
|
||||
/// try Int.fetchOne(db, "SELECT COUNT(*) FROM players")!
|
||||
/// }
|
||||
/// return .commit
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// DatabaseQueue.readFromCurrentState simply runs *block* synchronously,
|
||||
/// and returns when the block has completed. In the example below, the
|
||||
/// select sees the uncommitted state of the database, and the insertion
|
||||
/// is run after the select.
|
||||
///
|
||||
/// try dbQueue.write { db in
|
||||
/// try db.execute("DELETE FROM players")
|
||||
/// db.inTransaction {
|
||||
/// try db.execute("INSERT INTO players ...")
|
||||
/// try dbQueue.readFromCurrentState { db in
|
||||
/// // One
|
||||
/// try Int.fetchOne(db, "SELECT COUNT(*) FROM players")!
|
||||
/// }
|
||||
/// return .commit
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// This method is *not* reentrant.
|
||||
/// try db.execute("INSERT INTO players ...")
|
||||
/// }
|
||||
func readFromCurrentState(_ block: @escaping (Database) -> Void) throws
|
||||
}
|
||||
|
||||
|
||||
+67
-10
@@ -15,16 +15,6 @@ let statementSeparatorCharacterSet = CharacterSet(charactersIn: ";").union(.whit
|
||||
struct EmptyStatementError : Error {
|
||||
}
|
||||
|
||||
/// A common protocol for UpdateStatement and SelectStatement
|
||||
protocol AuthorizedStatement {
|
||||
init(
|
||||
database: Database,
|
||||
statementStart: UnsafePointer<Int8>,
|
||||
statementEnd: UnsafeMutablePointer<UnsafePointer<Int8>?>,
|
||||
prepFlags: Int32,
|
||||
authorizer: StatementCompilationAuthorizer) throws
|
||||
}
|
||||
|
||||
/// A statement represents an SQL query.
|
||||
///
|
||||
/// It is the base class of UpdateStatement that executes *update statements*,
|
||||
@@ -222,6 +212,73 @@ public class Statement {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - AuthorizedStatement
|
||||
|
||||
/// A common protocol for UpdateStatement and SelectStatement
|
||||
protocol AuthorizedStatement {
|
||||
// This initializer should be a required initializer of Statement.
|
||||
//
|
||||
// But Swift requires this required initializer to be public:
|
||||
// https://bugs.swift.org/browse/SR-2347
|
||||
//
|
||||
// We work around SR-2347 with this internal protocol.
|
||||
init(
|
||||
database: Database,
|
||||
statementStart: UnsafePointer<Int8>,
|
||||
statementEnd: UnsafeMutablePointer<UnsafePointer<Int8>?>,
|
||||
prepFlags: Int32,
|
||||
authorizer: StatementCompilationAuthorizer) throws
|
||||
}
|
||||
|
||||
extension AuthorizedStatement {
|
||||
// Static function instead of an initializer because initializer doesn't
|
||||
// compile due to the "capturing of an uninitialized self" in
|
||||
// `sqlCodeUnits.withUnsafeBufferPointer`.
|
||||
static func prepare(sql: String, prepFlags: Int32, in database: Database) throws -> Self {
|
||||
let authorizer = StatementCompilationAuthorizer()
|
||||
database.authorizer = authorizer
|
||||
defer { database.authorizer = nil }
|
||||
|
||||
let sqlCodeUnits = sql.utf8CString
|
||||
return try sqlCodeUnits.withUnsafeBufferPointer { codeUnits in
|
||||
let statementStart = UnsafePointer<Int8>(codeUnits.baseAddress)!
|
||||
var statementEnd: UnsafePointer<Int8>? = nil
|
||||
let statement: Self
|
||||
do {
|
||||
statement = try self.init(
|
||||
database: database,
|
||||
statementStart: statementStart,
|
||||
statementEnd: &statementEnd,
|
||||
prepFlags: prepFlags,
|
||||
authorizer: authorizer)
|
||||
} catch is EmptyStatementError {
|
||||
throw DatabaseError(
|
||||
resultCode: .SQLITE_ERROR,
|
||||
message: "empty statement",
|
||||
sql: sql,
|
||||
arguments: nil)
|
||||
}
|
||||
|
||||
let remainingData = Data(
|
||||
bytesNoCopy: UnsafeMutableRawPointer(mutating: statementEnd!),
|
||||
count: statementStart + sqlCodeUnits.count - statementEnd! - 1,
|
||||
deallocator: .none)
|
||||
|
||||
let remainingSQL = String(data: remainingData, encoding: .utf8)!
|
||||
.trimmingCharacters(in: statementSeparatorCharacterSet)
|
||||
|
||||
guard remainingSQL.isEmpty else {
|
||||
throw DatabaseError(
|
||||
resultCode: .SQLITE_MISUSE,
|
||||
message: "Multiple statements found. To execute multiple statements, use Database.execute() instead.",
|
||||
sql: sql,
|
||||
arguments: nil)
|
||||
}
|
||||
|
||||
return statement
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - SelectStatement
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'GRDBCipher'
|
||||
s.version = '2.4.0'
|
||||
s.version = '2.4.2'
|
||||
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
s.summary = 'A Swift application toolkit for SQLite databases.'
|
||||
|
||||
@@ -887,7 +887,6 @@
|
||||
5674A70B1F3087700095F066 /* DatabaseValueConvertibleEncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEncodableTests.swift; sourceTree = "<group>"; };
|
||||
5674A71C1F30A8DF0095F066 /* MutablePersistableEncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MutablePersistableEncodableTests.swift; sourceTree = "<group>"; };
|
||||
5674A7261F30A9090095F066 /* RowConvertibleDecodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RowConvertibleDecodableTests.swift; sourceTree = "<group>"; };
|
||||
5677C2551E68419700D1BDFE /* ReleaseProcess.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = ReleaseProcess.md; path = Documentation/ReleaseProcess.md; sourceTree = "<group>"; };
|
||||
567A80521D41350C00C7DCEC /* IndexInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndexInfoTests.swift; sourceTree = "<group>"; };
|
||||
567DAF141EAB61ED00FC0928 /* grdb_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = grdb_config.h; sourceTree = "<group>"; };
|
||||
567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseLogErrorTests.swift; sourceTree = "<group>"; };
|
||||
@@ -1005,10 +1004,8 @@
|
||||
56D51CFF1EA789FA0074638A /* RowConvertible+TableMapping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RowConvertible+TableMapping.swift"; sourceTree = "<group>"; };
|
||||
56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCursorTests.swift; sourceTree = "<group>"; };
|
||||
56DAA2DA1DE9C827006E10C8 /* Cursor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cursor.swift; sourceTree = "<group>"; };
|
||||
56DBEC341C19A0020093A2EE /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
|
||||
56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementArgumentsTests.swift; sourceTree = "<group>"; };
|
||||
56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.102.0.swift"; sourceTree = "<group>"; };
|
||||
56E1524B1B43FD5B00EE27AA /* TODO.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = TODO.md; sourceTree = "<group>"; };
|
||||
56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleFetchTests.swift; sourceTree = "<group>"; };
|
||||
56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementColumnConvertibleFetchTests.swift; sourceTree = "<group>"; };
|
||||
56EA86931C91DFE7002BB4DF /* DatabaseReaderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseReaderTests.swift; sourceTree = "<group>"; };
|
||||
@@ -1029,7 +1026,6 @@
|
||||
DC3773F719C8CBB3004FCF85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
DC3773F819C8CBB3004FCF85 /* GRDB.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GRDB.h; sourceTree = "<group>"; };
|
||||
DC37740419C8CBB3004FCF85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
DC37744719C8F50B004FCF85 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -1391,13 +1387,6 @@
|
||||
name = Private;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
569DF96F1DB8E9270003D0CC /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
56A238111B9C74A90082EB20 /* Core */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -1618,15 +1607,10 @@
|
||||
DC3773E919C8CBB3004FCF85 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56DBEC341C19A0020093A2EE /* CHANGELOG.md */,
|
||||
DC37744719C8F50B004FCF85 /* README.md */,
|
||||
56E1524B1B43FD5B00EE27AA /* TODO.md */,
|
||||
5677C2551E68419700D1BDFE /* ReleaseProcess.md */,
|
||||
DC37742D19C8CC90004FCF85 /* GRDB */,
|
||||
560FC54F1CB0047D0014AA8E /* GRDBCipher */,
|
||||
DC10500F19C904DD00D8CA30 /* Tests */,
|
||||
DC3773F419C8CBB3004FCF85 /* Products */,
|
||||
569DF96F1DB8E9270003D0CC /* Frameworks */,
|
||||
);
|
||||
indentWidth = 4;
|
||||
sourceTree = "<group>";
|
||||
|
||||
@@ -603,7 +603,6 @@
|
||||
5674A70B1F3087700095F066 /* DatabaseValueConvertibleEncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleEncodableTests.swift; sourceTree = "<group>"; };
|
||||
5674A71C1F30A8DF0095F066 /* MutablePersistableEncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MutablePersistableEncodableTests.swift; sourceTree = "<group>"; };
|
||||
5674A7261F30A9090095F066 /* RowConvertibleDecodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RowConvertibleDecodableTests.swift; sourceTree = "<group>"; };
|
||||
5677C2551E68419700D1BDFE /* ReleaseProcess.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = ReleaseProcess.md; path = Documentation/ReleaseProcess.md; sourceTree = "<group>"; };
|
||||
567A80521D41350C00C7DCEC /* IndexInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndexInfoTests.swift; sourceTree = "<group>"; };
|
||||
567DAF141EAB61ED00FC0928 /* grdb_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = grdb_config.h; sourceTree = "<group>"; };
|
||||
567DAF341EAB789800FC0928 /* DatabaseLogErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseLogErrorTests.swift; sourceTree = "<group>"; };
|
||||
@@ -713,10 +712,8 @@
|
||||
56D51CFF1EA789FA0074638A /* RowConvertible+TableMapping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RowConvertible+TableMapping.swift"; sourceTree = "<group>"; };
|
||||
56DAA2D11DE99DAB006E10C8 /* DatabaseCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCursorTests.swift; sourceTree = "<group>"; };
|
||||
56DAA2DA1DE9C827006E10C8 /* Cursor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cursor.swift; sourceTree = "<group>"; };
|
||||
56DBEC341C19A0020093A2EE /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
|
||||
56DE7B101C3D93ED00861EB8 /* StatementArgumentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementArgumentsTests.swift; sourceTree = "<group>"; };
|
||||
56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.102.0.swift"; sourceTree = "<group>"; };
|
||||
56E1524B1B43FD5B00EE27AA /* TODO.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = TODO.md; sourceTree = "<group>"; };
|
||||
56E8CE0C1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertibleFetchTests.swift; sourceTree = "<group>"; };
|
||||
56E8CE0F1BB4FE5B00828BEC /* StatementColumnConvertibleFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementColumnConvertibleFetchTests.swift; sourceTree = "<group>"; };
|
||||
56EA86931C91DFE7002BB4DF /* DatabaseReaderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseReaderTests.swift; sourceTree = "<group>"; };
|
||||
@@ -737,7 +734,6 @@
|
||||
DC3773F719C8CBB3004FCF85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
DC3773F819C8CBB3004FCF85 /* GRDB.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GRDB.h; sourceTree = "<group>"; };
|
||||
DC37740419C8CBB3004FCF85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
DC37744719C8F50B004FCF85 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
||||
EED476F11CFD16FF0026A4EC /* GRDBCustomSQLite-USER.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "GRDBCustomSQLite-USER.h"; path = "SQLiteCustom/GRDBCustomSQLite-USER.h"; sourceTree = "<group>"; };
|
||||
F3BA7FEE1CFB23B7003DC1BA /* GRDB.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = GRDB.xcconfig; path = SQLiteCustom/GRDB.xcconfig; sourceTree = "<group>"; };
|
||||
F3BA7FEF1CFB23BF003DC1BA /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; name = module.modulemap; path = SQLiteCustom/module.modulemap; sourceTree = "<group>"; };
|
||||
@@ -1081,13 +1077,6 @@
|
||||
name = Private;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
569DF96F1DB8E9270003D0CC /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
56A238111B9C74A90082EB20 /* Core */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -1309,15 +1298,10 @@
|
||||
DC3773E919C8CBB3004FCF85 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56DBEC341C19A0020093A2EE /* CHANGELOG.md */,
|
||||
DC37744719C8F50B004FCF85 /* README.md */,
|
||||
56E1524B1B43FD5B00EE27AA /* TODO.md */,
|
||||
5677C2551E68419700D1BDFE /* ReleaseProcess.md */,
|
||||
DC37742D19C8CC90004FCF85 /* GRDB */,
|
||||
F3BA7FED1CFB21F8003DC1BA /* GRDBCustomSQLite */,
|
||||
DC10500F19C904DD00D8CA30 /* Tests */,
|
||||
DC3773F419C8CBB3004FCF85 /* Products */,
|
||||
569DF96F1DB8E9270003D0CC /* Frameworks */,
|
||||
);
|
||||
indentWidth = 4;
|
||||
sourceTree = "<group>";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (C) 2017 Gwendal Roué
|
||||
Copyright (C) 2018 Gwendal Roué
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
@@ -244,10 +244,10 @@ test_performance: Realm FMDB SQLite.swift
|
||||
-scheme GRDBOSXPerformanceComparisonTests \
|
||||
build-for-testing test-without-building
|
||||
|
||||
Realm: Tests/Performance/Realm/build/osx/swift-4.0/RealmSwift.framework
|
||||
Realm: Tests/Performance/Realm/build/osx/swift-4.0.3/RealmSwift.framework
|
||||
|
||||
# Makes sure the Tests/Performance/Realm submodule has been downloaded, and Realm framework has been built.
|
||||
Tests/Performance/Realm/build/osx/swift-4.0/RealmSwift.framework:
|
||||
Tests/Performance/Realm/build/osx/swift-4.0.3/RealmSwift.framework:
|
||||
$(GIT) submodule update --init --recursive Tests/Performance/Realm
|
||||
cd Tests/Performance/Realm && sh build.sh osx-swift
|
||||
|
||||
@@ -296,7 +296,7 @@ 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/v2.4.0 \
|
||||
--github-file-prefix https://github.com/groue/GRDB.swift/tree/v2.4.2 \
|
||||
--module-version 2.4 \
|
||||
--module GRDB \
|
||||
--root-url http://groue.github.io/GRDB.swift/docs/2.4/ \
|
||||
|
||||
@@ -3,7 +3,7 @@ GRDB 2 [](ht
|
||||
|
||||
### A toolkit for SQLite databases, with a focus on application development
|
||||
|
||||
**Latest release**: December 3, 2017 • version 2.4.0 • [CHANGELOG](CHANGELOG.md)
|
||||
**Latest release**: January 5, 2018 • version 2.4.2 • [CHANGELOG](CHANGELOG.md)
|
||||
|
||||
**Requirements**: iOS 8.0+ / OSX 10.9+ / watchOS 2.0+ • Swift 4.0 / Xcode 9+
|
||||
|
||||
@@ -14,7 +14,7 @@ GRDB 2 [](ht
|
||||
| Swift 3 | [v1.0](https://github.com/groue/GRDB.swift/tree/v1.0) |
|
||||
| Swift 3.1 | [v1.3.0](https://github.com/groue/GRDB.swift/tree/v1.3.0) |
|
||||
| Swift 3.2 | [v1.3.0](https://github.com/groue/GRDB.swift/tree/v1.3.0) |
|
||||
| **Swift 4** | **v2.4.0** |
|
||||
| **Swift 4** | **v2.4.2** |
|
||||
|
||||
Follow [@groue](http://twitter.com/groue) on Twitter for release announcements and usage tips.
|
||||
|
||||
@@ -265,7 +265,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: "2.4.0")
|
||||
.package(url: "https://github.com/groue/GRDB.swift.git", from: "2.4.2")
|
||||
]
|
||||
)
|
||||
```
|
||||
@@ -282,7 +282,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/v2.4.0) a copy of GRDB, or clone its repository and make sure you use the latest tagged version with the `git checkout v2.4.0` command.
|
||||
1. [Download](https://github.com/groue/GRDB.swift/releases/tag/v2.4.2) a copy of GRDB, or clone its repository and make sure you use the latest tagged version with the `git checkout v2.4.2` command.
|
||||
|
||||
2. Embed the `GRDB.xcodeproj` project in your own project.
|
||||
|
||||
@@ -5130,7 +5130,7 @@ Alternatively, perform a manual installation of GRDB and SQLCipher:
|
||||
|
||||
```sh
|
||||
cd [GRDB directory]
|
||||
git checkout v2.4.0
|
||||
git checkout v2.4.2
|
||||
git submodule update --init SQLCipher/src
|
||||
```
|
||||
|
||||
@@ -5466,7 +5466,7 @@ See [prepared statements](#prepared-statements) and [DatabaseValue](#databaseval
|
||||
|
||||
**SQLite can be configured to invoke a callback function containing an error code and a terse error message whenever anomalies occur.**
|
||||
|
||||
It is recommended that you setup, early in the lifetime of your application, the error logging callback:
|
||||
This global error callback must be configured early in the lifetime of your application:
|
||||
|
||||
```swift
|
||||
Database.logError = { (resultCode, message) in
|
||||
@@ -5474,6 +5474,8 @@ Database.logError = { (resultCode, message) in
|
||||
}
|
||||
```
|
||||
|
||||
> :warning: **Warning**: Database.logError must be set before any database connection is opened. This includes the connections that your application opens with GRDB, but also connections opened by other tools, such as third-party libraries. Setting it after a connection has been opened is an SQLite misuse, and has no effect.
|
||||
|
||||
See [The Error And Warning Log](https://sqlite.org/errlog.html) for more information.
|
||||
|
||||
|
||||
@@ -5824,7 +5826,6 @@ However, database queues are not database pools, and DatabaseReader and Database
|
||||
|
||||
- Pools are less forgiving than queues when one overlooks a transaction (see [concurrency rule 3](#guarantees-and-rules)).
|
||||
- DatabaseWriter.readFromCurrentState is synchronous, or asynchronous, depending on whether it is run by a queue or a pool (see [advanced DatabasePool](#advanced-databasepool)). It thus requires higher libDispatch skills, and more complex synchronization code.
|
||||
- The definition of "current state" in DatabaseWriter.readFromCurrentState is [delicate](http://groue.github.io/GRDB.swift/docs/2.4/Protocols/DatabaseWriter.html#/s:FP4GRDB14DatabaseWriter20readFromCurrentStateFzFCS_8DatabaseT_T_).
|
||||
|
||||
DatabaseReader and DatabaseWriter are not a tool for applications that hesitate between DatabaseQueue and DatabasePool, and look for a common API. As seen above, the protocols actually make applications harder to write correctly. Instead, they target generic code that has *both* queues and pools in mind. The built-in AnyDatabaseReader and AnyDatabaseWriter type erasers serve the same purpose.
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.4.0</string>
|
||||
<string>2.4.2</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
- [ ] We share the database cache between database pool writers and readers. But what if a writer modifies the database schema within a transaction, and a concurrent reader reads the cache? Bad things, isn't it? Write failing tests first, and fix the bug.
|
||||
- [ ] Attach databases. Interesting question: what happens when one attaches a non-WAL db to a databasePool?
|
||||
- [ ] SQLCipher: sqlite3_rekey is discouraged (https://github.com/ccgus/fmdb/issues/547#issuecomment-259219320)
|
||||
- [ ] What is the behavior inTransaction and inSavepoint behaviors in case of commit error? Code looks like we do not rollback, leaving the app in a weird state (out of Swift transaction block with a SQLite transaction that may still be opened).
|
||||
- [ ] Query builder
|
||||
- [ ] SELECT readers.*, books.* FROM ... JOIN ...
|
||||
- [ ] date functions
|
||||
@@ -21,7 +19,6 @@ GRDB 3.0
|
||||
|
||||
Not sure
|
||||
|
||||
- [ ] Support for resource values (see https://developer.apple.com/library/ios/qa/qa1719/_index.html)
|
||||
- [ ] Think about supporting Cursor's underestimatedCount, which could speed up Array(cursor) and fetchAll()
|
||||
- [ ] Support for OR ROLLBACK, and mismatch between the Swift depth and the SQLite depth of nested transactions/savepoint:
|
||||
|
||||
@@ -63,14 +60,6 @@ Not sure
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] Support for NSColor/UIColor. Beware UIColor components can go beyond [0, 1.0] in iOS10.
|
||||
- [ ] Store dates as timestamp (https://twitter.com/gloparco/status/780948021613912064, https://github.com/groue/GRDB.swift/issues/97)
|
||||
|
||||
|
||||
Require changes in the Swift language:
|
||||
|
||||
- [ ] Specific and optimized Optional<StatementColumnConvertible>.fetch... methods when http://openradar.appspot.com/22852669 is fixed.
|
||||
|
||||
|
||||
Requires recompilation of SQLite:
|
||||
|
||||
@@ -98,3 +87,4 @@ Reading list:
|
||||
- React oddity: http://stackoverflow.com/questions/41721769/realm-update-object-without-updating-lists
|
||||
- File protection: https://github.com/ccgus/fmdb/issues/262
|
||||
- File protection: https://lists.apple.com/archives/cocoa-dev/2012/Aug/msg00527.html
|
||||
- [iOS apps are terminated every time they enter the background if they share an encrypted database with an app extension](https://github.com/sqlcipher/sqlcipher/issues/255)
|
||||
@@ -10,23 +10,11 @@ import XCTest
|
||||
class DatabaseLogErrorTests: GRDBTestCase {
|
||||
|
||||
func testErrorLog() throws {
|
||||
// Remember current log function
|
||||
let currentLogError = Database.logError
|
||||
|
||||
var lastResultCode: ResultCode? = nil
|
||||
var lastMessage: String? = nil
|
||||
Database.logError = { (resultCode, message) in
|
||||
lastResultCode = resultCode
|
||||
lastMessage = message
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.inDatabase { db in
|
||||
_ = try? db.execute("That's not SQL.")
|
||||
}
|
||||
XCTAssertEqual(lastResultCode!, ResultCode.SQLITE_ERROR)
|
||||
XCTAssertEqual(lastMessage!, "near \"That\": syntax error")
|
||||
|
||||
// Restore current log function
|
||||
Database.logError = currentLogError
|
||||
}
|
||||
}
|
||||
@@ -33,28 +33,9 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase {
|
||||
|
||||
try dbPool.read { db in
|
||||
// Warm cache in a reader
|
||||
let primaryKey = try db.primaryKey("items")
|
||||
XCTAssertEqual(primaryKey.rowIDColumn, "id")
|
||||
|
||||
let columns = try db.columns(in: "items")
|
||||
XCTAssertEqual(columns.count, 4)
|
||||
XCTAssertEqual(columns[0].name, "id")
|
||||
XCTAssertEqual(columns[1].name, "email")
|
||||
XCTAssertEqual(columns[2].name, "foo")
|
||||
XCTAssertEqual(columns[3].name, "bar")
|
||||
|
||||
let indexes = try db.indexes(on: "items")
|
||||
XCTAssertEqual(indexes.count, 2)
|
||||
for index in indexes {
|
||||
switch index.name {
|
||||
case "foobar":
|
||||
XCTAssertEqual(index.columns, ["foo", "bar"])
|
||||
XCTAssertFalse(index.isUnique)
|
||||
default:
|
||||
XCTAssertEqual(index.columns, ["email"])
|
||||
XCTAssertTrue(index.isUnique)
|
||||
}
|
||||
}
|
||||
_ = try db.primaryKey("items")
|
||||
_ = try db.columns(in: "items")
|
||||
_ = try db.indexes(on: "items")
|
||||
|
||||
// Assert that reader cache is warmed
|
||||
XCTAssertTrue(db.schemaCache.primaryKey("items") != nil)
|
||||
@@ -62,7 +43,12 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase {
|
||||
XCTAssertTrue(db.schemaCache.indexes(on: "items") != nil)
|
||||
}
|
||||
|
||||
dbPool.write { db in
|
||||
try dbPool.write { db in
|
||||
// Warm cache in the writer
|
||||
_ = try db.primaryKey("items")
|
||||
_ = try db.columns(in: "items")
|
||||
_ = try db.indexes(on: "items")
|
||||
|
||||
// Assert that writer cache is warmed
|
||||
XCTAssertTrue(db.schemaCache.primaryKey("items") != nil)
|
||||
XCTAssertTrue(db.schemaCache.columns(in: "items") != nil)
|
||||
@@ -137,4 +123,95 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase {
|
||||
blocks[index]()
|
||||
}
|
||||
}
|
||||
|
||||
func testCacheSnapshotIsolation() throws {
|
||||
// This test checks that the schema cache follows snapshot isolation.
|
||||
// and that writer and readers do not naively share the same cache.
|
||||
dbConfiguration.trace = { print($0) }
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
// writer reader
|
||||
// CREATE TABLE foo
|
||||
// table exists: true
|
||||
// >
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// table exists: true
|
||||
// <
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// DROP TABLE foo
|
||||
// table exists: false
|
||||
// >
|
||||
let s3 = DispatchSemaphore(value: 0)
|
||||
// table exists: true
|
||||
// <
|
||||
let s4 = DispatchSemaphore(value: 0)
|
||||
// table exists: false
|
||||
|
||||
let block1 = { () in
|
||||
try! dbPool.write { db in
|
||||
try db.execute("CREATE TABLE foo(id INTEGER PRIMARY KEY)")
|
||||
// warm cache
|
||||
_ = try db.primaryKey("foo")
|
||||
// cache contains the primary key
|
||||
XCTAssertNotNil(db.schemaCache.primaryKey("foo"))
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
try db.execute("DROP TABLE foo")
|
||||
// cache does not contain the primary key
|
||||
XCTAssertNil(db.schemaCache.primaryKey("foo"))
|
||||
s3.signal()
|
||||
_ = s4.wait(timeout: .distantFuture)
|
||||
// cache does not contain the primary key
|
||||
XCTAssertNil(db.schemaCache.primaryKey("foo"))
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try! dbPool.read { db in
|
||||
// activate snapshot isolation so that foo table is visible during the whole read. Any read is enough.
|
||||
try db.makeSelectStatement("SELECT * FROM sqlite_master").cursor().next()
|
||||
// warm cache
|
||||
_ = try db.primaryKey("foo")
|
||||
// cache contains the primary key
|
||||
XCTAssertNotNil(db.schemaCache.primaryKey("foo"))
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
// cache contains the primary key
|
||||
XCTAssertNotNil(db.schemaCache.primaryKey("foo"))
|
||||
// warm cache if needed
|
||||
_ = try db.primaryKey("foo")
|
||||
s4.signal()
|
||||
}
|
||||
}
|
||||
let blocks = [block1, block2]
|
||||
DispatchQueue.concurrentPerform(iterations: blocks.count) { index in
|
||||
blocks[index]()
|
||||
}
|
||||
}
|
||||
|
||||
func testUnsafeReaderHasNoDatabaseCache() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.execute("CREATE TABLE items (id INTEGER PRIMARY KEY, email TEXT UNIQUE, foo INT, bar DOUBLE)")
|
||||
try db.execute("CREATE INDEX foobar ON items(foo, bar)")
|
||||
}
|
||||
|
||||
try dbPool.unsafeRead { db in
|
||||
// Assert that a cache is empty
|
||||
XCTAssertTrue(db.schemaCache.primaryKey("items") == nil)
|
||||
XCTAssertTrue(db.schemaCache.columns(in: "items") == nil)
|
||||
XCTAssertTrue(db.schemaCache.indexes(on: "items") == nil)
|
||||
|
||||
// Warm cache in a reader
|
||||
_ = try db.primaryKey("items")
|
||||
_ = try db.columns(in: "items")
|
||||
_ = try db.indexes(on: "items")
|
||||
|
||||
// Assert that a reader cache is still empty
|
||||
XCTAssertTrue(db.schemaCache.primaryKey("items") == nil)
|
||||
XCTAssertTrue(db.schemaCache.columns(in: "items") == nil)
|
||||
XCTAssertTrue(db.schemaCache.indexes(on: "items") == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,10 @@ import XCTest
|
||||
@testable import GRDB // @testable so that we have access to SQLiteConnectionWillClose
|
||||
#endif
|
||||
|
||||
// Support for Database.logError
|
||||
var lastResultCode: ResultCode? = nil
|
||||
var lastMessage: String? = nil
|
||||
|
||||
class GRDBTestCase: XCTestCase {
|
||||
// The default configuration for tests
|
||||
var dbConfiguration: Configuration!
|
||||
@@ -53,6 +57,12 @@ class GRDBTestCase: XCTestCase {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
// Must be set prior to any databaase connection
|
||||
Database.logError = { (resultCode, message) in
|
||||
lastResultCode = resultCode
|
||||
lastMessage = message
|
||||
}
|
||||
|
||||
let dbPoolDirectoryName = "GRDBTestCase-\(ProcessInfo.processInfo.globallyUniqueString)"
|
||||
dbDirectoryPath = (NSTemporaryDirectory() as NSString).appendingPathComponent(dbPoolDirectoryName)
|
||||
do { try FileManager.default.removeItem(atPath: dbDirectoryPath) } catch { }
|
||||
|
||||
@@ -41,7 +41,7 @@ class FetchNamedValuesTests: XCTestCase {
|
||||
#if GRDB_COMPARE
|
||||
func testFMDB() {
|
||||
let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")!
|
||||
let dbQueue = FMDatabaseQueue(path: databasePath)
|
||||
let dbQueue = FMDatabaseQueue(path: databasePath)!
|
||||
|
||||
measure {
|
||||
var count = 0
|
||||
|
||||
@@ -83,7 +83,7 @@ class FetchPositionalValuesTests: XCTestCase {
|
||||
#if GRDB_COMPARE
|
||||
func testFMDB() {
|
||||
let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")!
|
||||
let dbQueue = FMDatabaseQueue(path: databasePath)
|
||||
let dbQueue = FMDatabaseQueue(path: databasePath)!
|
||||
|
||||
measure {
|
||||
var count = 0
|
||||
|
||||
@@ -86,7 +86,7 @@ class FetchRecordStructTests: XCTestCase {
|
||||
// Here we test the loading of an array of Records.
|
||||
|
||||
let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")!
|
||||
let dbQueue = FMDatabaseQueue(path: databasePath)
|
||||
let dbQueue = FMDatabaseQueue(path: databasePath)!
|
||||
|
||||
measure {
|
||||
var items = [ItemStruct]()
|
||||
|
||||
@@ -57,7 +57,7 @@ class InsertNamedValuesTests: XCTestCase {
|
||||
measure {
|
||||
_ = try? FileManager.default.removeItem(atPath: databasePath)
|
||||
|
||||
let dbQueue = FMDatabaseQueue(path: databasePath)
|
||||
let dbQueue = FMDatabaseQueue(path: databasePath)!
|
||||
dbQueue.inDatabase { db in
|
||||
db.executeStatements("CREATE TABLE items (i0 INT, i1 INT, i2 INT, i3 INT, i4 INT, i5 INT, i6 INT, i7 INT, i8 INT, i9 INT)")
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ class InsertPositionalValuesTests: XCTestCase {
|
||||
measure {
|
||||
_ = try? FileManager.default.removeItem(atPath: databasePath)
|
||||
|
||||
let dbQueue = FMDatabaseQueue(path: databasePath)
|
||||
let dbQueue = FMDatabaseQueue(path: databasePath)!
|
||||
dbQueue.inDatabase { db in
|
||||
db.executeStatements("CREATE TABLE items (i0 INT, i1 INT, i2 INT, i3 INT, i4 INT, i5 INT, i6 INT, i7 INT, i8 INT, i9 INT)")
|
||||
}
|
||||
|
||||
+1
-1
Submodule Tests/Performance/Realm updated: 7bc8c82799...13a3cb44c1.
Submodule Tests/Performance/SQLite.swift updated: 3708a962da...1d2eef2570.
+1
-1
Submodule Tests/Performance/fmdb updated: d1fc235264...e0fcde9a0e.
Executable
+123
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env ruby
|
||||
gem 'json'
|
||||
require 'json'
|
||||
require 'date'
|
||||
require 'rexml/document'
|
||||
|
||||
# Extract CFBundleShortVersionString from a plist file
|
||||
def info_plist_version(path)
|
||||
REXML::Document.new(File.read(path))
|
||||
.root
|
||||
.elements["//key[text()='CFBundleShortVersionString']"]
|
||||
.next_element
|
||||
.text
|
||||
end
|
||||
|
||||
def formatted_sample(samples, test, lib)
|
||||
sample = samples["#{test}Tests"]["test#{lib}"]
|
||||
return '¹' unless sample # n/a
|
||||
'%.2f' % sample
|
||||
end
|
||||
|
||||
def formatted_samples(samples, test)
|
||||
libs = %w{GRDB SQLite FMDB SQLiteSwift CoreData Realm}
|
||||
libs.map { |lib| formatted_sample(samples, test, lib) || '¹' }
|
||||
end
|
||||
|
||||
samples = JSON.parse(STDIN.read)
|
||||
grdb_version = info_plist_version('Support/Info.plist')
|
||||
fmdb_version = info_plist_version('Tests/Performance/fmdb/src/fmdb/Info.plist')
|
||||
sqlite_swift_version = info_plist_version('Tests/Performance/SQLite.swift/Sources/SQLite/Info.plist')
|
||||
realm_version = info_plist_version('Tests/Performance/Realm/build/osx/Realm.framework/Versions/A/Resources/Info.plist')
|
||||
|
||||
puts <<-REPORT
|
||||
# Comparing the Performances of Swift SQLite libraries
|
||||
|
||||
*Last updated #{Date.today.strftime('%B %-d, %Y')}*
|
||||
|
||||
Below are performance benchmarks made on for [GRDB #{grdb_version}](https://github.com/groue/GRDB.swift), [FMDB #{fmdb_version}](https://github.com/ccgus/fmdb), and [SQLite.swift #{sqlite_swift_version}](https://github.com/stephencelis/SQLite.swift). They are compared to Core Data, [Realm #{realm_version}](https://realm.io) and the raw use of the SQLite C API from Swift.
|
||||
|
||||
This report was generated on a MacBook Pro (15-inch, Late 2016), with Xcode 9.2, by running the following command:
|
||||
|
||||
```sh
|
||||
make test_performance | Tests/parsePerformanceTests.rb | Tests/generatePerformanceReport.rb
|
||||
```
|
||||
|
||||
All tests use the default settings of each library. For each library, we:
|
||||
|
||||
- Build and consume database rows with raw SQL and column indexes (aiming at the best performance)
|
||||
- Build and consume database rows with column names (sacrificing performance for maintainability)
|
||||
- Build and consume records values to and from database rows (aiming at the shortest code from database to records)
|
||||
- Build and consume records values to and from database rows, with [change tracking](https://github.com/groue/GRDB.swift#changes-tracking) (records know if they have unsaved changes)
|
||||
|
||||
As a bottom line, the raw SQLite C API is used as efficiently as possible, without any error checking.
|
||||
|
||||
| | GRDB | Raw SQLite | FMDB | SQLite.swift | Core Data | Realm |
|
||||
|:-------------------------------- | ----:| ----------:| ----:| ------------:| ---------:| -----:|
|
||||
| **Column indexes** | | | | | | |
|
||||
| Fetch | #{formatted_samples(samples, 'FetchPositionalValues').join(" | ")} |
|
||||
| Insert | #{formatted_samples(samples, 'InsertPositionalValues').join(" | ")} |
|
||||
| **Column names** | | | | | | |
|
||||
| Fetch | #{formatted_samples(samples, 'FetchNamedValues').join(" | ")} |
|
||||
| Insert | #{formatted_samples(samples, 'InsertNamedValues').join(" | ")} |
|
||||
| **Records** | | | | | | |
|
||||
| Fetch | #{formatted_samples(samples, 'FetchRecordStruct').join(" | ")} |
|
||||
| Insert | #{formatted_samples(samples, 'InsertRecordStruct').join(" | ")} |
|
||||
| **Records with change tracking** | | | | | | |
|
||||
| Fetch | #{formatted_samples(samples, 'FetchRecordClass').join(" | ")} |
|
||||
| Insert | #{formatted_samples(samples, 'InsertRecordClass').join(" | ")} |
|
||||
|
||||
¹ Not applicable
|
||||
|
||||
- **Column indexes**:
|
||||
|
||||
- **Fetch** ([source](https://github.com/groue/GRDB.swift/blob/master/Tests/Performance/FetchPositionalValuesTests.swift))
|
||||
|
||||
This test fetches 100000 rows of 10 ints and extracts each int given its position in the row.
|
||||
|
||||
It uses FMDB's `-[FMResultSet longForColumnIndex:]`, GRDB's `Row.value(atIndex:)`, and the low-level SQL API of SQLite.swift.
|
||||
|
||||
- **Insert** ([source](https://github.com/groue/GRDB.swift/blob/master/Tests/Performance/InsertPositionalValuesTests.swift))
|
||||
|
||||
This test inserts 20000 rows of 10 ints, by setting query arguments given their position.
|
||||
|
||||
It uses FMDB's `-[FMDatabase executeUpdate:withArgumentsInArray:]` with statement caching, GRDB's `UpdateStatement.execute(arguments:Array)`, and the low-level SQL API of SQLite.swift.
|
||||
|
||||
- **Column names**:
|
||||
|
||||
- **Fetch** ([source](https://github.com/groue/GRDB.swift/blob/master/Tests/Performance/FetchNamedValuesTests.swift))
|
||||
|
||||
This test fetches 100000 rows of 10 ints and extracts each int given its column name.
|
||||
|
||||
It uses FMDB's `-[FMResultSet longForColumn:]`, GRDB's `Row.value(named:)`, and the high-level query builder of SQLite.swift.
|
||||
|
||||
- **Insert** ([source](https://github.com/groue/GRDB.swift/blob/master/Tests/Performance/InsertNamedValuesTests.swift))
|
||||
|
||||
This test inserts 20000 rows of 10 ints, by setting query arguments given their argument name.
|
||||
|
||||
It uses FMDB's `-[FMDatabase executeUpdate:withParameterDictionary:]` with statement caching, GRDB's `UpdateStatement.execute(arguments:Dictionary)`, and the high-level query builder of SQLite.swift.
|
||||
|
||||
- **Records**:
|
||||
|
||||
- **Fetch** ([source](https://github.com/groue/GRDB.swift/blob/master/Tests/Performance/FetchRecordStructTests.swift))
|
||||
|
||||
This test fetches an array of 100000 record objects initiated from rows of 10 ints.
|
||||
|
||||
It builds records from FMDB's `-[FMResultSet resultDictionary]`, GRDB's built-in [RowConvertible](https://github.com/groue/GRDB.swift#rowconvertible-protocol) protocol, and the values returned by the high-level query builder of SQLite.swift.
|
||||
|
||||
- **Insert** ([source](https://github.com/groue/GRDB.swift/blob/master/Tests/Performance/InsertRecordStructTests.swift))
|
||||
|
||||
This tests inserts 20000 records with the persistence method provided by GRDB's [Persistable](https://github.com/groue/GRDB.swift#persistable-protocol) protocol.
|
||||
|
||||
- **Records with change tracking**:
|
||||
|
||||
- **Fetch** ([source](https://github.com/groue/GRDB.swift/blob/master/Tests/Performance/FetchRecordClassTests.swift))
|
||||
|
||||
This test fetches an array of 100000 record objects initiated from rows of 10 ints.
|
||||
|
||||
It builds records from FMDB's `-[FMResultSet resultDictionary]`, GRDB's built-in [Record](https://github.com/groue/GRDB.swift#record-class) class.
|
||||
|
||||
- **Insert** ([source](https://github.com/groue/GRDB.swift/blob/master/Tests/Performance/InsertRecordClassTests.swift))
|
||||
|
||||
This tests inserts 20000 records with the persistence method provided by GRDB's [Record](https://github.com/groue/GRDB.swift#record-class) class.
|
||||
REPORT
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env ruby
|
||||
gem 'json'
|
||||
require 'json'
|
||||
|
||||
tests = {}
|
||||
STDIN.each do |line|
|
||||
if line =~ /\.([^ ]*) ([^ ]*)\]' measured \[Time, seconds\] average: ([\d.]+)/
|
||||
class_name = $1
|
||||
test_name = $2
|
||||
time = $3
|
||||
tests[class_name] ||= {}
|
||||
tests[class_name][test_name] = time.to_f
|
||||
end
|
||||
end
|
||||
|
||||
puts tests.to_json
|
||||
@@ -1,10 +0,0 @@
|
||||
#/bin/sh
|
||||
#
|
||||
# Outputs the compilation time of all methods.
|
||||
# To get the 20 slowest methods, run ./slow_methods.sh | head -20
|
||||
set -e
|
||||
|
||||
PROJECT=GRDB.xcodeproj
|
||||
TARGET=GRDBiOS
|
||||
|
||||
OTHER_SWIFT_FLAGS='-Xfrontend -debug-time-function-bodies' xcodebuild -project $PROJECT -target $TARGET 2>&1 clean build | grep '^[0-9][0-9.]*.*\t' | sort -nr
|
||||
Reference in new issue
Block a user