diff --git a/CHANGELOG.md b/CHANGELOG.md index cf6e2efb7..032d67986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,28 @@ Release Notes ============= +## 0.71.0 + +Released June 5, 2016 + +**Fixed** + +- Fix a crash that would sometimes happen when a FetchedRecordsController's callbacks avoid retain cycles by capturing unowned references. +- Improved handling of numeric overflows. Fixes [#68](https://github.com/groue/GRDB.swift/issues/68). + + +**New** + +- GRDB can now use a custom SQLite build ([documentation](https://github.com/groue/GRDB.swift/tree/master/SQLiteCustom)). Merged [#62](https://github.com/groue/GRDB.swift/pull/62) by [@swiftlyfalling](https://github.com/swiftlyfalling). +- With a custom SQLite build, transaction observers can observe individual column values in the rows modified by a transaction ([documentation](https://github.com/groue/GRDB.swift#support-for-sqlite-pre-update-hooks)). Merged [#63](https://github.com/groue/GRDB.swift/pull/63) by [@swiftlyfalling](https://github.com/swiftlyfalling). +- FetchedRecordsController can now fetch other values alongside the fetched records. This grants you the ability to fetch values that are consistent with the notified changes. ([documentation](https://github.com/groue/GRDB.swift#the-changes-notifications)) + + +**Breaking Changes** + +- iOS7 is no longer supported. + + ## 0.70.1 Released May 30, 2016 diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Database.swift b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Database.swift index 30c6cf2ce..dd012292f 100644 --- a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Database.swift +++ b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Database.swift @@ -27,7 +27,7 @@ func setupDatabase(_ application: UIApplication) { migrator.registerMigration("createPersons") { db in // Have person names compared in a localized case insensitive fashion - // See https://github.com/groue/GRDB.swift/#unicide + // See https://github.com/groue/GRDB.swift/#unicode let collation = DatabaseCollation.localizedCaseInsensitiveCompare try db.execute( "CREATE TABLE persons (" + diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonsViewController.swift b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonsViewController.swift index e594164a6..8f1d04832 100644 --- a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonsViewController.swift +++ b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonsViewController.swift @@ -3,7 +3,7 @@ import GRDB class PersonsViewController: UITableViewController { var personsController: FetchedRecordsController! - + override func viewDidLoad() { super.viewDidLoad() @@ -187,8 +187,7 @@ extension PersonsViewController { @IBAction func stressTest() { setEditing(false, animated: true) - // Spawn some concurrent background jobs - for _ in 0..<20 { + for _ in 0..<1000 { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { try! dbQueue.inTransaction { db in if Person.fetchCount(db) == 0 { diff --git a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7.xcodeproj/project.pbxproj b/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7.xcodeproj/project.pbxproj deleted file mode 100644 index 788336347..000000000 --- a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7.xcodeproj/project.pbxproj +++ /dev/null @@ -1,590 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 560A37E01C91391800949E71 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37B31C91391800949E71 /* Configuration.swift */; }; - 560A37E11C91391800949E71 /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37B41C91391800949E71 /* Database.swift */; }; - 560A37E21C91391800949E71 /* DatabaseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37B51C91391800949E71 /* DatabaseError.swift */; }; - 560A37E31C91391800949E71 /* DatabasePool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37B61C91391800949E71 /* DatabasePool.swift */; }; - 560A37E41C91391800949E71 /* DatabaseQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37B71C91391800949E71 /* DatabaseQueue.swift */; }; - 560A37E51C91391800949E71 /* DatabaseSchemaCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37B81C91391800949E71 /* DatabaseSchemaCache.swift */; }; - 560A37E61C91391800949E71 /* DatabaseValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37B91C91391800949E71 /* DatabaseValue.swift */; }; - 560A37E71C91391800949E71 /* DatabaseValueConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37BA1C91391800949E71 /* DatabaseValueConvertible.swift */; }; - 560A37E81C91391800949E71 /* Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37BB1C91391800949E71 /* Row.swift */; }; - 560A37E91C91391800949E71 /* SerializedDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37BC1C91391800949E71 /* SerializedDatabase.swift */; }; - 560A37EA1C91391800949E71 /* Statement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37BD1C91391800949E71 /* Statement.swift */; }; - 560A37EB1C91391800949E71 /* StatementColumnConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37BE1C91391800949E71 /* StatementColumnConvertible.swift */; }; - 560A37EC1C91391800949E71 /* CGFloat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37C11C91391800949E71 /* CGFloat.swift */; }; - 560A37ED1C91391800949E71 /* DatabaseCoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37C31C91391800949E71 /* DatabaseCoder.swift */; }; - 560A37EE1C91391800949E71 /* DatabaseDateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37C41C91391800949E71 /* DatabaseDateComponents.swift */; }; - 560A37EF1C91391800949E71 /* DatabaseValue+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37C51C91391800949E71 /* DatabaseValue+Foundation.swift */; }; - 560A37F01C91391800949E71 /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37C61C91391800949E71 /* NSData.swift */; }; - 560A37F11C91391800949E71 /* NSDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37C71C91391800949E71 /* NSDate.swift */; }; - 560A37F21C91391800949E71 /* NSNull.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37C81C91391800949E71 /* NSNull.swift */; }; - 560A37F31C91391800949E71 /* NSNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37C91C91391800949E71 /* NSNumber.swift */; }; - 560A37F41C91391800949E71 /* NSString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37CA1C91391800949E71 /* NSString.swift */; }; - 560A37F51C91391800949E71 /* NSURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37CB1C91391800949E71 /* NSURL.swift */; }; - 560A37F61C91391800949E71 /* Row+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37CC1C91391800949E71 /* Row+Foundation.swift */; }; - 560A37F71C91391800949E71 /* StatementArguments+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37CD1C91391800949E71 /* StatementArguments+Foundation.swift */; }; - 560A37F81C91391800949E71 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37CF1C91391800949E71 /* RawRepresentable.swift */; }; - 560A37F91C91391800949E71 /* StandardLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37D01C91391800949E71 /* StandardLibrary.swift */; }; - 560A37FA1C91391800949E71 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37D11C91391800949E71 /* Utils.swift */; }; - 560A37FB1C91391800949E71 /* FetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37D31C91391800949E71 /* FetchRequest.swift */; }; - 560A37FC1C91391800949E71 /* SQLCollation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37D41C91391800949E71 /* SQLCollation.swift */; }; - 560A37FD1C91391800949E71 /* SQLFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37D51C91391800949E71 /* SQLFunction.swift */; }; - 560A37FE1C91391800949E71 /* SQLOperator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37D61C91391800949E71 /* SQLOperator.swift */; }; - 560A37FF1C91391800949E71 /* SQLSelectQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37D71C91391800949E71 /* SQLSelectQuery.swift */; }; - 560A38001C91391800949E71 /* DatabaseMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37D91C91391800949E71 /* DatabaseMigrator.swift */; }; - 560A38011C91391800949E71 /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37DA1C91391800949E71 /* Migration.swift */; }; - 560A38021C91391800949E71 /* Persistable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37DC1C91391800949E71 /* Persistable.swift */; }; - 560A38031C91391800949E71 /* Record.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37DD1C91391800949E71 /* Record.swift */; }; - 560A38041C91391800949E71 /* RowConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37DE1C91391800949E71 /* RowConvertible.swift */; }; - 560A38051C91391800949E71 /* TableMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37DF1C91391800949E71 /* TableMapping.swift */; }; - 562FF9951BCE8FA400759400 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9941BCE8FA400759400 /* AppDelegate.swift */; }; - 562FF9971BCE8FA400759400 /* PersonsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9961BCE8FA400759400 /* PersonsViewController.swift */; }; - 562FF99A1BCE8FA400759400 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 562FF9981BCE8FA400759400 /* Main.storyboard */; }; - 562FF99C1BCE8FA400759400 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 562FF99B1BCE8FA400759400 /* Assets.xcassets */; }; - 562FF99F1BCE8FA400759400 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 562FF99D1BCE8FA400759400 /* LaunchScreen.storyboard */; }; - 562FF9EC1BCE903D00759400 /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 562FF9EB1BCE903D00759400 /* libsqlite3.tbd */; }; - 562FF9EF1BCE912C00759400 /* PersonEditionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9EE1BCE912C00759400 /* PersonEditionViewController.swift */; }; - 562FF9F21BCE914E00759400 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9F11BCE914E00759400 /* Person.swift */; }; - 563363C81C942CAE000BE133 /* DatabaseReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363C71C942CAE000BE133 /* DatabaseReader.swift */; }; - 563363CA1C942CB4000BE133 /* DatabaseWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363C91C942CB4000BE133 /* DatabaseWriter.swift */; }; - 563363F01C95A41B000BE133 /* DatabaseStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363EF1C95A41B000BE133 /* DatabaseStore.swift */; }; - 566A20F31C58A4B300C5A218 /* AppDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A20F21C58A4B300C5A218 /* AppDatabase.swift */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 560A37B31C91391800949E71 /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = ""; }; - 560A37B41C91391800949E71 /* Database.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Database.swift; sourceTree = ""; }; - 560A37B51C91391800949E71 /* DatabaseError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseError.swift; sourceTree = ""; }; - 560A37B61C91391800949E71 /* DatabasePool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePool.swift; sourceTree = ""; }; - 560A37B71C91391800949E71 /* DatabaseQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueue.swift; sourceTree = ""; }; - 560A37B81C91391800949E71 /* DatabaseSchemaCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSchemaCache.swift; sourceTree = ""; }; - 560A37B91C91391800949E71 /* DatabaseValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValue.swift; sourceTree = ""; }; - 560A37BA1C91391800949E71 /* DatabaseValueConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertible.swift; sourceTree = ""; }; - 560A37BB1C91391800949E71 /* Row.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Row.swift; sourceTree = ""; }; - 560A37BC1C91391800949E71 /* SerializedDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SerializedDatabase.swift; sourceTree = ""; }; - 560A37BD1C91391800949E71 /* Statement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Statement.swift; sourceTree = ""; }; - 560A37BE1C91391800949E71 /* StatementColumnConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementColumnConvertible.swift; sourceTree = ""; }; - 560A37C11C91391800949E71 /* CGFloat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloat.swift; sourceTree = ""; }; - 560A37C31C91391800949E71 /* DatabaseCoder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCoder.swift; sourceTree = ""; }; - 560A37C41C91391800949E71 /* DatabaseDateComponents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateComponents.swift; sourceTree = ""; }; - 560A37C51C91391800949E71 /* DatabaseValue+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DatabaseValue+Foundation.swift"; sourceTree = ""; }; - 560A37C61C91391800949E71 /* NSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSData.swift; sourceTree = ""; }; - 560A37C71C91391800949E71 /* NSDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDate.swift; sourceTree = ""; }; - 560A37C81C91391800949E71 /* NSNull.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSNull.swift; sourceTree = ""; }; - 560A37C91C91391800949E71 /* NSNumber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSNumber.swift; sourceTree = ""; }; - 560A37CA1C91391800949E71 /* NSString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSString.swift; sourceTree = ""; }; - 560A37CB1C91391800949E71 /* NSURL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSURL.swift; sourceTree = ""; }; - 560A37CC1C91391800949E71 /* Row+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Row+Foundation.swift"; sourceTree = ""; }; - 560A37CD1C91391800949E71 /* StatementArguments+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StatementArguments+Foundation.swift"; sourceTree = ""; }; - 560A37CF1C91391800949E71 /* RawRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentable.swift; sourceTree = ""; }; - 560A37D01C91391800949E71 /* StandardLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardLibrary.swift; sourceTree = ""; }; - 560A37D11C91391800949E71 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; - 560A37D31C91391800949E71 /* FetchRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequest.swift; sourceTree = ""; }; - 560A37D41C91391800949E71 /* SQLCollation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollation.swift; sourceTree = ""; }; - 560A37D51C91391800949E71 /* SQLFunction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLFunction.swift; sourceTree = ""; }; - 560A37D61C91391800949E71 /* SQLOperator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLOperator.swift; sourceTree = ""; }; - 560A37D71C91391800949E71 /* SQLSelectQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLSelectQuery.swift; sourceTree = ""; }; - 560A37D91C91391800949E71 /* DatabaseMigrator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseMigrator.swift; sourceTree = ""; }; - 560A37DA1C91391800949E71 /* Migration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Migration.swift; sourceTree = ""; }; - 560A37DC1C91391800949E71 /* Persistable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Persistable.swift; sourceTree = ""; }; - 560A37DD1C91391800949E71 /* Record.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Record.swift; sourceTree = ""; }; - 560A37DE1C91391800949E71 /* RowConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowConvertible.swift; sourceTree = ""; }; - 560A37DF1C91391800949E71 /* TableMapping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableMapping.swift; sourceTree = ""; }; - 562FF9911BCE8FA400759400 /* GRDBDemoiOS7.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GRDBDemoiOS7.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 562FF9941BCE8FA400759400 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 562FF9961BCE8FA400759400 /* PersonsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonsViewController.swift; sourceTree = ""; }; - 562FF9991BCE8FA400759400 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; - 562FF99B1BCE8FA400759400 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 562FF99E1BCE8FA400759400 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; - 562FF9A01BCE8FA400759400 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 562FF9EB1BCE903D00759400 /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; }; - 562FF9EE1BCE912C00759400 /* PersonEditionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersonEditionViewController.swift; sourceTree = ""; }; - 562FF9F11BCE914E00759400 /* Person.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; }; - 562FF9F41BCE930C00759400 /* GRDBDemoiOS7-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "GRDBDemoiOS7-Bridging-Header.h"; sourceTree = ""; }; - 563363C71C942CAE000BE133 /* DatabaseReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseReader.swift; sourceTree = ""; }; - 563363C91C942CB4000BE133 /* DatabaseWriter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseWriter.swift; sourceTree = ""; }; - 563363EF1C95A41B000BE133 /* DatabaseStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseStore.swift; sourceTree = ""; }; - 566A20F21C58A4B300C5A218 /* AppDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDatabase.swift; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 562FF98E1BCE8FA400759400 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 562FF9EC1BCE903D00759400 /* libsqlite3.tbd in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 560A37B21C91391800949E71 /* Core */ = { - isa = PBXGroup; - children = ( - 560A37B31C91391800949E71 /* Configuration.swift */, - 560A37B41C91391800949E71 /* Database.swift */, - 560A37B51C91391800949E71 /* DatabaseError.swift */, - 560A37B61C91391800949E71 /* DatabasePool.swift */, - 560A37B71C91391800949E71 /* DatabaseQueue.swift */, - 563363C71C942CAE000BE133 /* DatabaseReader.swift */, - 560A37B81C91391800949E71 /* DatabaseSchemaCache.swift */, - 563363EF1C95A41B000BE133 /* DatabaseStore.swift */, - 560A37B91C91391800949E71 /* DatabaseValue.swift */, - 560A37BA1C91391800949E71 /* DatabaseValueConvertible.swift */, - 563363C91C942CB4000BE133 /* DatabaseWriter.swift */, - 560A37BB1C91391800949E71 /* Row.swift */, - 560A37BC1C91391800949E71 /* SerializedDatabase.swift */, - 560A37BD1C91391800949E71 /* Statement.swift */, - 560A37BE1C91391800949E71 /* StatementColumnConvertible.swift */, - 560A37BF1C91391800949E71 /* Support */, - 560A37D11C91391800949E71 /* Utils.swift */, - ); - path = Core; - sourceTree = ""; - }; - 560A37BF1C91391800949E71 /* Support */ = { - isa = PBXGroup; - children = ( - 560A37C01C91391800949E71 /* CoreGraphics */, - 560A37C21C91391800949E71 /* Foundation */, - 560A37CE1C91391800949E71 /* StandardLibrary */, - ); - path = Support; - sourceTree = ""; - }; - 560A37C01C91391800949E71 /* CoreGraphics */ = { - isa = PBXGroup; - children = ( - 560A37C11C91391800949E71 /* CGFloat.swift */, - ); - path = CoreGraphics; - sourceTree = ""; - }; - 560A37C21C91391800949E71 /* Foundation */ = { - isa = PBXGroup; - children = ( - 560A37C31C91391800949E71 /* DatabaseCoder.swift */, - 560A37C41C91391800949E71 /* DatabaseDateComponents.swift */, - 560A37C51C91391800949E71 /* DatabaseValue+Foundation.swift */, - 560A37C61C91391800949E71 /* NSData.swift */, - 560A37C71C91391800949E71 /* NSDate.swift */, - 560A37C81C91391800949E71 /* NSNull.swift */, - 560A37C91C91391800949E71 /* NSNumber.swift */, - 560A37CA1C91391800949E71 /* NSString.swift */, - 560A37CB1C91391800949E71 /* NSURL.swift */, - 560A37CC1C91391800949E71 /* Row+Foundation.swift */, - 560A37CD1C91391800949E71 /* StatementArguments+Foundation.swift */, - ); - path = Foundation; - sourceTree = ""; - }; - 560A37CE1C91391800949E71 /* StandardLibrary */ = { - isa = PBXGroup; - children = ( - 560A37CF1C91391800949E71 /* RawRepresentable.swift */, - 560A37D01C91391800949E71 /* StandardLibrary.swift */, - ); - path = StandardLibrary; - sourceTree = ""; - }; - 560A37D21C91391800949E71 /* FetchRequest */ = { - isa = PBXGroup; - children = ( - 560A37D31C91391800949E71 /* FetchRequest.swift */, - 560A37D41C91391800949E71 /* SQLCollation.swift */, - 560A37D51C91391800949E71 /* SQLFunction.swift */, - 560A37D61C91391800949E71 /* SQLOperator.swift */, - 560A37D71C91391800949E71 /* SQLSelectQuery.swift */, - ); - path = FetchRequest; - sourceTree = ""; - }; - 560A37D81C91391800949E71 /* Migrations */ = { - isa = PBXGroup; - children = ( - 560A37D91C91391800949E71 /* DatabaseMigrator.swift */, - 560A37DA1C91391800949E71 /* Migration.swift */, - ); - path = Migrations; - sourceTree = ""; - }; - 560A37DB1C91391800949E71 /* Record */ = { - isa = PBXGroup; - children = ( - 560A37DC1C91391800949E71 /* Persistable.swift */, - 560A37DD1C91391800949E71 /* Record.swift */, - 560A37DE1C91391800949E71 /* RowConvertible.swift */, - 560A37DF1C91391800949E71 /* TableMapping.swift */, - ); - path = Record; - sourceTree = ""; - }; - 562FF9881BCE8FA400759400 = { - isa = PBXGroup; - children = ( - 562FF9931BCE8FA400759400 /* GRDBDemoiOS7 */, - 562FF9921BCE8FA400759400 /* Products */, - ); - sourceTree = ""; - }; - 562FF9921BCE8FA400759400 /* Products */ = { - isa = PBXGroup; - children = ( - 562FF9911BCE8FA400759400 /* GRDBDemoiOS7.app */, - ); - name = Products; - sourceTree = ""; - }; - 562FF9931BCE8FA400759400 /* GRDBDemoiOS7 */ = { - isa = PBXGroup; - children = ( - 562FF9941BCE8FA400759400 /* AppDelegate.swift */, - 566A20F21C58A4B300C5A218 /* AppDatabase.swift */, - 562FF9F01BCE913900759400 /* Controllers */, - 562FF9F31BCE915B00759400 /* Models */, - 562FF9A61BCE8FB000759400 /* Resources */, - 562FF9ED1BCE904D00759400 /* GRDB */, - 562FF9A71BCE8FB600759400 /* Supporting Files */, - ); - path = GRDBDemoiOS7; - sourceTree = ""; - }; - 562FF9A61BCE8FB000759400 /* Resources */ = { - isa = PBXGroup; - children = ( - 562FF9981BCE8FA400759400 /* Main.storyboard */, - 562FF99B1BCE8FA400759400 /* Assets.xcassets */, - 562FF99D1BCE8FA400759400 /* LaunchScreen.storyboard */, - ); - name = Resources; - sourceTree = ""; - }; - 562FF9A71BCE8FB600759400 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 562FF9A01BCE8FA400759400 /* Info.plist */, - 562FF9F41BCE930C00759400 /* GRDBDemoiOS7-Bridging-Header.h */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - 562FF9ED1BCE904D00759400 /* GRDB */ = { - isa = PBXGroup; - children = ( - 562FF9EB1BCE903D00759400 /* libsqlite3.tbd */, - 566A20F41C58A54F00C5A218 /* GRDB */, - ); - name = GRDB; - sourceTree = ""; - }; - 562FF9F01BCE913900759400 /* Controllers */ = { - isa = PBXGroup; - children = ( - 562FF9EE1BCE912C00759400 /* PersonEditionViewController.swift */, - 562FF9961BCE8FA400759400 /* PersonsViewController.swift */, - ); - name = Controllers; - sourceTree = ""; - }; - 562FF9F31BCE915B00759400 /* Models */ = { - isa = PBXGroup; - children = ( - 562FF9F11BCE914E00759400 /* Person.swift */, - ); - name = Models; - sourceTree = ""; - }; - 566A20F41C58A54F00C5A218 /* GRDB */ = { - isa = PBXGroup; - children = ( - 560A37B21C91391800949E71 /* Core */, - 560A37D21C91391800949E71 /* FetchRequest */, - 560A37D81C91391800949E71 /* Migrations */, - 560A37DB1C91391800949E71 /* Record */, - ); - name = GRDB; - path = ../../../GRDB; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 562FF9901BCE8FA400759400 /* GRDBDemoiOS7 */ = { - isa = PBXNativeTarget; - buildConfigurationList = 562FF9A31BCE8FA400759400 /* Build configuration list for PBXNativeTarget "GRDBDemoiOS7" */; - buildPhases = ( - 562FF98D1BCE8FA400759400 /* Sources */, - 562FF98E1BCE8FA400759400 /* Frameworks */, - 562FF98F1BCE8FA400759400 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = GRDBDemoiOS7; - productName = GRDBDemoiOS7; - productReference = 562FF9911BCE8FA400759400 /* GRDBDemoiOS7.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 562FF9891BCE8FA400759400 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0700; - ORGANIZATIONNAME = "Gwendal Roué"; - TargetAttributes = { - 562FF9901BCE8FA400759400 = { - CreatedOnToolsVersion = 7.0; - }; - }; - }; - buildConfigurationList = 562FF98C1BCE8FA400759400 /* Build configuration list for PBXProject "GRDBDemoiOS7" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 562FF9881BCE8FA400759400; - productRefGroup = 562FF9921BCE8FA400759400 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 562FF9901BCE8FA400759400 /* GRDBDemoiOS7 */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 562FF98F1BCE8FA400759400 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 562FF99F1BCE8FA400759400 /* LaunchScreen.storyboard in Resources */, - 562FF99C1BCE8FA400759400 /* Assets.xcassets in Resources */, - 562FF99A1BCE8FA400759400 /* Main.storyboard in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 562FF98D1BCE8FA400759400 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 560A37FB1C91391800949E71 /* FetchRequest.swift in Sources */, - 560A37EC1C91391800949E71 /* CGFloat.swift in Sources */, - 560A38011C91391800949E71 /* Migration.swift in Sources */, - 560A37EB1C91391800949E71 /* StatementColumnConvertible.swift in Sources */, - 560A37EF1C91391800949E71 /* DatabaseValue+Foundation.swift in Sources */, - 560A37E01C91391800949E71 /* Configuration.swift in Sources */, - 560A37E91C91391800949E71 /* SerializedDatabase.swift in Sources */, - 562FF9EF1BCE912C00759400 /* PersonEditionViewController.swift in Sources */, - 563363F01C95A41B000BE133 /* DatabaseStore.swift in Sources */, - 560A38051C91391800949E71 /* TableMapping.swift in Sources */, - 560A37E71C91391800949E71 /* DatabaseValueConvertible.swift in Sources */, - 560A37E31C91391800949E71 /* DatabasePool.swift in Sources */, - 562FF9971BCE8FA400759400 /* PersonsViewController.swift in Sources */, - 560A37E51C91391800949E71 /* DatabaseSchemaCache.swift in Sources */, - 560A37E41C91391800949E71 /* DatabaseQueue.swift in Sources */, - 560A37F11C91391800949E71 /* NSDate.swift in Sources */, - 562FF9F21BCE914E00759400 /* Person.swift in Sources */, - 560A37F01C91391800949E71 /* NSData.swift in Sources */, - 562FF9951BCE8FA400759400 /* AppDelegate.swift in Sources */, - 560A37FC1C91391800949E71 /* SQLCollation.swift in Sources */, - 560A37F71C91391800949E71 /* StatementArguments+Foundation.swift in Sources */, - 560A37EE1C91391800949E71 /* DatabaseDateComponents.swift in Sources */, - 560A37ED1C91391800949E71 /* DatabaseCoder.swift in Sources */, - 560A37E61C91391800949E71 /* DatabaseValue.swift in Sources */, - 560A37F31C91391800949E71 /* NSNumber.swift in Sources */, - 560A37FF1C91391800949E71 /* SQLSelectQuery.swift in Sources */, - 560A37F41C91391800949E71 /* NSString.swift in Sources */, - 560A37E21C91391800949E71 /* DatabaseError.swift in Sources */, - 560A38041C91391800949E71 /* RowConvertible.swift in Sources */, - 560A37F91C91391800949E71 /* StandardLibrary.swift in Sources */, - 563363CA1C942CB4000BE133 /* DatabaseWriter.swift in Sources */, - 560A37FA1C91391800949E71 /* Utils.swift in Sources */, - 560A37F61C91391800949E71 /* Row+Foundation.swift in Sources */, - 560A37FD1C91391800949E71 /* SQLFunction.swift in Sources */, - 560A37FE1C91391800949E71 /* SQLOperator.swift in Sources */, - 560A37F21C91391800949E71 /* NSNull.swift in Sources */, - 560A37E11C91391800949E71 /* Database.swift in Sources */, - 560A37E81C91391800949E71 /* Row.swift in Sources */, - 560A38021C91391800949E71 /* Persistable.swift in Sources */, - 560A37F51C91391800949E71 /* NSURL.swift in Sources */, - 560A37F81C91391800949E71 /* RawRepresentable.swift in Sources */, - 560A38001C91391800949E71 /* DatabaseMigrator.swift in Sources */, - 566A20F31C58A4B300C5A218 /* AppDatabase.swift in Sources */, - 560A37EA1C91391800949E71 /* Statement.swift in Sources */, - 560A38031C91391800949E71 /* Record.swift in Sources */, - 563363C81C942CAE000BE133 /* DatabaseReader.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXVariantGroup section */ - 562FF9981BCE8FA400759400 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 562FF9991BCE8FA400759400 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; - 562FF99D1BCE8FA400759400 /* LaunchScreen.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 562FF99E1BCE8FA400759400 /* Base */, - ); - name = LaunchScreen.storyboard; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - 562FF9A11BCE8FA400759400 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - 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; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - 562FF9A21BCE8FA400759400 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - 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; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - 562FF9A41BCE8FA400759400 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - INFOPLIST_FILE = GRDBDemoiOS7/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS7; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = "GRDBDemoiOS7/GRDBDemoiOS7-Bridging-Header.h"; - }; - name = Debug; - }; - 562FF9A51BCE8FA400759400 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - INFOPLIST_FILE = GRDBDemoiOS7/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoiOS7; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = "GRDBDemoiOS7/GRDBDemoiOS7-Bridging-Header.h"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 562FF98C1BCE8FA400759400 /* Build configuration list for PBXProject "GRDBDemoiOS7" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 562FF9A11BCE8FA400759400 /* Debug */, - 562FF9A21BCE8FA400759400 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 562FF9A31BCE8FA400759400 /* Build configuration list for PBXNativeTarget "GRDBDemoiOS7" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 562FF9A41BCE8FA400759400 /* Debug */, - 562FF9A51BCE8FA400759400 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 562FF9891BCE8FA400759400 /* Project object */; -} diff --git a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 94d4a737b..000000000 --- a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/AppDelegate.swift b/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/AppDelegate.swift deleted file mode 100644 index d5b26ac98..000000000 --- a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/AppDelegate.swift +++ /dev/null @@ -1,13 +0,0 @@ -import UIKit - -@UIApplicationMain -class AppDelegate: UIResponder, UIApplicationDelegate { - - var window: UIWindow? - - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - setupDatabase() - return true - } -} - diff --git a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Assets.xcassets/AppIcon.appiconset/Contents.json b/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 118c98f74..000000000 --- a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "images" : [ - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "3x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Base.lproj/LaunchScreen.storyboard b/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Base.lproj/LaunchScreen.storyboard deleted file mode 100644 index 2e721e183..000000000 --- a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Base.lproj/LaunchScreen.storyboard +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Base.lproj/Main.storyboard b/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Base.lproj/Main.storyboard deleted file mode 100644 index d1c6ca434..000000000 --- a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Base.lproj/Main.storyboard +++ /dev/null @@ -1,190 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/GRDBDemoiOS7-Bridging-Header.h b/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/GRDBDemoiOS7-Bridging-Header.h deleted file mode 100644 index 167fbb6c4..000000000 --- a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/GRDBDemoiOS7-Bridging-Header.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// GRDBDemoiOS7-Bridging-Header.h -// GRDBDemoiOS7 -// -// Created by Gwendal Roué on 14/10/2015. -// Copyright © 2015 Gwendal Roué. All rights reserved. -// - -#ifndef GRDBDemoiOS7_Bridging_Header_h -#define GRDBDemoiOS7_Bridging_Header_h - -#import "sqlite3.h" - -#endif /* GRDBDemoiOS7_Bridging_Header_h */ diff --git a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Info.plist b/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Info.plist deleted file mode 100644 index 6905cc67b..000000000 --- a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Info.plist +++ /dev/null @@ -1,40 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - LSRequiresIPhoneOS - - UILaunchStoryboardName - LaunchScreen - UIMainStoryboardFile - Main - UIRequiredDeviceCapabilities - - armv7 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - - diff --git a/DemoApps/GRDBDemoiOS7/README.md b/DemoApps/GRDBDemoiOS7/README.md deleted file mode 100644 index cdd71112d..000000000 --- a/DemoApps/GRDBDemoiOS7/README.md +++ /dev/null @@ -1,18 +0,0 @@ -GRDBDemoiOS7 -============ - -This application runs an application that displays an editable list of persons and targets iOS7. - -**To integrate GRDB in your iOS7 application:** - -1. Drag all Swift files contained in the [GRDB folder](../../GRDB/) in your project. - -2. In the **Build Phase** tab of your target, add `libsqlite3.tbd` in the **Link Binary With Libraries** section. - -3. [Add a Bridging header to your project](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html) in which you add: - - ```objc - #import "sqlite3.h" - ``` - -4. Run diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index ec122415a..08f30d2c9 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDB.swift' - s.version = '0.70.1' + s.version = '0.71.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A versatile SQLite toolkit for Swift, with WAL mode support.' s.homepage = 'https://github.com/groue/GRDB.swift' diff --git a/GRDB.xcodeproj/project.pbxproj b/GRDB.xcodeproj/project.pbxproj index 68c157484..b9114eaf9 100755 --- a/GRDB.xcodeproj/project.pbxproj +++ b/GRDB.xcodeproj/project.pbxproj @@ -250,6 +250,14 @@ 565D5D721BBC694D00DC9BD4 /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */; }; 565D5D741BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */; }; 565D5D751BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */; }; + 565EFAEE1D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; + 565EFAEF1D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; + 565EFAF01D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; + 565EFAF11D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; + 565EFAF21D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; + 565EFAF31D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; + 565EFAF41D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; + 565EFAF51D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */; }; 565F03C31CE5D3AA00DE108F /* AdapterRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565F03C11CE5D3AA00DE108F /* AdapterRowTests.swift */; }; 565F03C41CE5D3AA00DE108F /* AdapterRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565F03C11CE5D3AA00DE108F /* AdapterRowTests.swift */; }; 565F03C71CE5D3AA00DE108F /* AdapterRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565F03C11CE5D3AA00DE108F /* AdapterRowTests.swift */; }; @@ -1267,6 +1275,7 @@ 565B0FEE1BBC7D980098DE03 /* RowConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowConvertibleTests.swift; sourceTree = ""; }; 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Row+FoundationTests.swift"; sourceTree = ""; }; 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StatementArguments+FoundationTests.swift"; sourceTree = ""; }; + 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumericOverflowTests.swift; sourceTree = ""; }; 565F03C11CE5D3AA00DE108F /* AdapterRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdapterRowTests.swift; sourceTree = ""; }; 567156151CB142AA007DC145 /* ReadOnlyDatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReadOnlyDatabaseTests.swift; sourceTree = ""; }; 5671566C1CB16729007DC145 /* GRDBCipherOSXEncryptedTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBCipherOSXEncryptedTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1861,6 +1870,7 @@ EED6C2BC1D00B6A100F8E701 /* NSStringTests.swift */, EED6C2BD1D00B6A100F8E701 /* NSURLTests.swift */, EED6C2DF1D00C0D800F8E701 /* NSNullTests.swift */, + 565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */, ); path = DatabaseValueConvertible; sourceTree = ""; @@ -3020,6 +3030,7 @@ 560FC5921CB00B880014AA8E /* RowConvertibleTests.swift in Sources */, 560FC5931CB00B880014AA8E /* DatabaseQueueReleaseMemoryTests.swift in Sources */, 560FC5941CB00B880014AA8E /* DatabaseValueConvertibleSubclassTests.swift in Sources */, + 565EFAEF1D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, 560FC5951CB00B880014AA8E /* DatabasePoolSchemaCacheTests.swift in Sources */, 560FC5961CB00B880014AA8E /* DatabaseValueConvertibleFetchTests.swift in Sources */, 560FC5971CB00B880014AA8E /* DatabaseErrorTests.swift in Sources */, @@ -3126,6 +3137,7 @@ 567156521CB16729007DC145 /* DatabaseQueueReleaseMemoryTests.swift in Sources */, 567156531CB16729007DC145 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, 567156541CB16729007DC145 /* DatabasePoolSchemaCacheTests.swift in Sources */, + 565EFAF01D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, 567156551CB16729007DC145 /* DatabaseValueConvertibleFetchTests.swift in Sources */, 567156561CB16729007DC145 /* DatabaseErrorTests.swift in Sources */, 567156571CB16729007DC145 /* MinimalPrimaryKeySingleTests.swift in Sources */, @@ -3268,6 +3280,7 @@ 56AFCA641CB1AA9900F48B96 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, 56AFCA651CB1AA9900F48B96 /* DatabaseErrorTests.swift in Sources */, 56AFCA661CB1AA9900F48B96 /* DatabaseQueueReleaseMemoryTests.swift in Sources */, + 565EFAF31D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, 56AFCA671CB1AA9900F48B96 /* DatabasePoolReleaseMemoryTests.swift in Sources */, 56AFCA681CB1AA9900F48B96 /* MinimalPrimaryKeySingleTests.swift in Sources */, 56AFCA691CB1AA9900F48B96 /* DatabaseQueueFileAttributesTests.swift in Sources */, @@ -3378,6 +3391,7 @@ 56AFCACE1CB1ABC800F48B96 /* CGFloatTests.swift in Sources */, 56AFCACF1CB1ABC800F48B96 /* StatementInformationTests.swift in Sources */, 56AFCAD01CB1ABC800F48B96 /* GRDBTestCase.swift in Sources */, + 565EFAF41D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, 5634B0781CF22BEF005360B9 /* FetchRequestTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -3501,6 +3515,7 @@ 56A238401B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, 56A2383C1B9C74A90082EB20 /* DatabaseErrorTests.swift in Sources */, 563363D61C94484E000BE133 /* DatabaseQueueReleaseMemoryTests.swift in Sources */, + 565EFAF21D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, 563363D11C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift in Sources */, 56A238521B9C74A90082EB20 /* MinimalPrimaryKeySingleTests.swift in Sources */, 563363DD1C95891E000BE133 /* DatabaseQueueFileAttributesTests.swift in Sources */, @@ -3590,6 +3605,7 @@ 569531291C908A5B00CF1A2B /* DatabasePoolSchemaCacheTests.swift in Sources */, 56E8CE0D1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift in Sources */, 56A2383B1B9C74A90082EB20 /* DatabaseErrorTests.swift in Sources */, + 565EFAEE1D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, 56E8CE101BB4FE5B00828BEC /* SQLiteStatementConvertibleFetchTests.swift in Sources */, 56A238511B9C74A90082EB20 /* MinimalPrimaryKeySingleTests.swift in Sources */, 56CA21BA1BB3FCF7009A04C5 /* NSDataTests.swift in Sources */, @@ -3784,6 +3800,7 @@ F3BA812B1CFB3063003DC1BA /* RecordWithColumnNameManglingTests.swift in Sources */, F3BA80B11CFB2FC4003DC1BA /* DatabaseTests.swift in Sources */, F3BA804F1CFB2B59003DC1BA /* DatabasePoolReleaseMemoryTests.swift in Sources */, + 565EFAF51D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, F3BA81231CFB3063003DC1BA /* PrimaryKeySingleTests.swift in Sources */, F3BA80541CFB2B59003DC1BA /* StatementInformationTests.swift in Sources */, F3BA81171CFB305E003DC1BA /* SQLSupportTests.swift in Sources */, @@ -3925,6 +3942,7 @@ F3BA80E11CFB300F003DC1BA /* DatabaseValueConversionTests.swift in Sources */, F3BA80ED1CFB3017003DC1BA /* DictionaryRowTests.swift in Sources */, F3BA80B61CFB2FCA003DC1BA /* ReadOnlyDatabaseTests.swift in Sources */, + 565EFAF11D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */, F3BA812E1CFB3064003DC1BA /* PrimaryKeyMultipleTests.swift in Sources */, F3BA81021CFB3032003DC1BA /* CGFloatTests.swift in Sources */, F3BA80AA1CFB2FA6003DC1BA /* DatabasePoolSchemaCacheTests.swift in Sources */, diff --git a/GRDB.xcodeproj/xcshareddata/xcschemes/GRDBCustomSQLiteOSX.xcscheme b/GRDB.xcodeproj/xcshareddata/xcschemes/GRDBCustomSQLiteOSX.xcscheme deleted file mode 100644 index 966e57296..000000000 --- a/GRDB.xcodeproj/xcshareddata/xcschemes/GRDBCustomSQLiteOSX.xcscheme +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/GRDB.xcodeproj/xcshareddata/xcschemes/GRDBCustomSQLiteiOS.xcscheme b/GRDB.xcodeproj/xcshareddata/xcschemes/GRDBCustomSQLiteiOS.xcscheme deleted file mode 100644 index 420467b93..000000000 --- a/GRDB.xcodeproj/xcshareddata/xcschemes/GRDBCustomSQLiteiOS.xcscheme +++ /dev/null @@ -1,113 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/GRDB.xcworkspace/contents.xcworkspacedata b/GRDB.xcworkspace/contents.xcworkspacedata index a4181869b..f4af6ae62 100644 --- a/GRDB.xcworkspace/contents.xcworkspacedata +++ b/GRDB.xcworkspace/contents.xcworkspacedata @@ -32,7 +32,4 @@ - - diff --git a/GRDB/Core/DatabaseValue.swift b/GRDB/Core/DatabaseValue.swift index 6d3bb2c14..d43eea100 100644 --- a/GRDB/Core/DatabaseValue.swift +++ b/GRDB/Core/DatabaseValue.swift @@ -87,7 +87,7 @@ public struct DatabaseValue { return value } guard isNull else { - fatalError("could not convert \(self) to \(Value.self).") + fatalError("could not convert database value \(self) to \(Value.self)") } return nil } @@ -100,7 +100,7 @@ public struct DatabaseValue { /// - returns: A *Value*. public func value() -> Value { guard let value = Value.fromDatabaseValue(self) as Value? else { - fatalError("could not convert \(self) to \(Value.self).") + fatalError("could not convert database value \(self) to \(Value.self)") } return value } diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 0b121e4c0..a9a8aaf3c 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -372,7 +372,7 @@ extension Row { private static func statementColumnConvertible(atUncheckedIndex index: Int, in sqliteStatement: SQLiteStatement) -> Value { guard sqlite3_column_type(sqliteStatement, Int32(index)) != SQLITE_NULL else { - fatalError("could not convert NULL to \(Value.self).") + fatalError("could not convert database NULL value to \(Value.self)") } return Value.init(sqliteStatement: sqliteStatement, index: Int32(index)) } diff --git a/GRDB/Core/StatementColumnConvertible.swift b/GRDB/Core/StatementColumnConvertible.swift index 52f4f5578..6a9316a32 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -71,7 +71,7 @@ public extension DatabaseValueConvertible where Self: StatementColumnConvertible let sqliteStatement = statement.sqliteStatement return statement.fetchSequence(arguments: arguments) { guard sqlite3_column_type(sqliteStatement, 0) != SQLITE_NULL else { - fatalError("could not convert NULL to \(Self.self).") + fatalError("could not convert database NULL value to \(Self.self)") } return Self.init(sqliteStatement: sqliteStatement, index: 0) } diff --git a/GRDB/Core/Support/Foundation/NSNumber.swift b/GRDB/Core/Support/Foundation/NSNumber.swift index 5455fec2a..6e047d4da 100644 --- a/GRDB/Core/Support/Foundation/NSNumber.swift +++ b/GRDB/Core/Support/Foundation/NSNumber.swift @@ -6,19 +6,33 @@ extension NSNumber: DatabaseValueConvertible { /// Returns a value that can be stored in the database. public var databaseValue: DatabaseValue { switch String(cString: objCType) { - case "c", - "C", - "s", - "S", - "i", - "I", - "l", - "L", - "q", - "Q": - return int64Value.databaseValue - case "f", - "d": + case "c": + return Int64(int8Value).databaseValue + case "C": + return Int64(uint8Value).databaseValue + case "s": + return Int64(int16Value).databaseValue + case "S": + return Int64(uint16Value).databaseValue + case "i": + return Int64(int32Value).databaseValue + case "I": + return Int64(uint32Value).databaseValue + case "l": + return Int64(intValue).databaseValue + case "L": + let uint = uintValue + GRDBPrecondition(UInt64(uint) <= UInt64(Int64.max), "could not convert \(uint) to an Int64 that can be stored in the database") + return Int64(uint).databaseValue + case "q": + return Int64(int64Value).databaseValue + case "Q": + let uint64 = uint64Value + GRDBPrecondition(uint64 <= UInt64(Int64.max), "could not convert \(uint64) to an Int64 that can be stored in the database") + return Int64(uint64).databaseValue + case "f": + return Double(floatValue).databaseValue + case "d": return doubleValue.databaseValue case "B": return boolValue.databaseValue diff --git a/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift b/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift index 2e6dccba5..3496b2bed 100644 --- a/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift +++ b/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift @@ -108,7 +108,9 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible { /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. public init(sqliteStatement: SQLiteStatement, index: Int32) { - self = Int(sqlite3_column_int64(sqliteStatement, index)) + let int64 = sqlite3_column_int64(sqliteStatement, index) + GRDBPrecondition(int64 >= Int64(Int.min) && int64 <= Int64(Int.max), "could not convert database value \(int64) to Int") + self = Int(int64) } /// Returns a value that can be stored in the database. @@ -120,9 +122,20 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible { public static func fromDatabaseValue(_ databaseValue: DatabaseValue) -> Int? { switch databaseValue.storage { case .int64(let int64): + guard int64 >= Int64(Int.min) else { return nil } + guard int64 <= Int64(Int.max) else { return nil } return Int(int64) case .double(let double): - return Int(double) + // Cast from Double to Int64 to Int + // Why? Because on 32-bits platforms we'll convert more values this way (Swift bug?) + // - Int(Int64(-2147483648.999999)) // -2147483648 + // - Int(-2147483648.999999) // fatal error + guard double >= Double(Int64.min) else { return nil } + guard double < Double(Int64.max) else { return nil } + let int64 = Int64(double) + guard int64 >= Int64(Int.min) else { return nil } + guard int64 <= Int64(Int.max) else { return nil } + return Int(int64) default: return nil } @@ -138,7 +151,9 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible { /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. public init(sqliteStatement: SQLiteStatement, index: Int32) { - self = Int32(sqlite3_column_int64(sqliteStatement, index)) + let int64 = sqlite3_column_int64(sqliteStatement, index) + GRDBPrecondition(int64 >= Int64(Int32.min) && int64 <= Int64(Int32.max), "could not convert database value \(int64) to Int32") + self = Int32(int64) } /// Returns a value that can be stored in the database. @@ -150,9 +165,20 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible { public static func fromDatabaseValue(_ databaseValue: DatabaseValue) -> Int32? { switch databaseValue.storage { case .int64(let int64): + guard int64 >= Int64(Int32.min) else { return nil } + guard int64 <= Int64(Int32.max) else { return nil } return Int32(int64) case .double(let double): - return Int32(double) + // Cast from Double to Int64 to Int32 + // Why? Because we'll convert more values this way (Swift bug?) + // - Int32(Int64(-2147483648.999999)) // -2147483648 + // - Int32(-2147483648.999999) // fatal error + guard double >= Double(Int64.min) else { return nil } + guard double < Double(Int64.max) else { return nil } + let int64 = Int64(double) + guard int64 >= Int64(Int32.min) else { return nil } + guard int64 <= Int64(Int32.max) else { return nil } + return Int32(int64) default: return nil } @@ -182,6 +208,8 @@ extension Int64: DatabaseValueConvertible, StatementColumnConvertible { case .int64(let int64): return int64 case .double(let double): + guard double >= Double(Int64.min) else { return nil } + guard double < Double(Int64.max) else { return nil } return Int64(double) default: return nil diff --git a/GRDB/Record/FetchedRecordsController.swift b/GRDB/Record/FetchedRecordsController.swift index 17c257503..76a7da970 100644 --- a/GRDB/Record/FetchedRecordsController.swift +++ b/GRDB/Record/FetchedRecordsController.swift @@ -85,8 +85,12 @@ public final class FetchedRecordsController { /// After executing this method, you can access the the fetched objects with /// the property fetchedRecords. public func performFetch() { - // If some changes are currently processed, make sure they are discarded. + // If some changes are currently processed, make sure they are + // discarded. But preserve eventual changes processing for future + // changes. + let checkForChanges = observer?.checkForChanges observer?.invalidate() + observer = nil // Fetch items on the writing dispatch queue, so that the transaction // observer is added on the same serialized queue as transaction @@ -94,18 +98,16 @@ public final class FetchedRecordsController { databaseWriter.write { db in let statement = try! self.request.selectStatement(db) let adapter = try! self.request.adapter(statement) - let items = Item.fetchAll(statement, adapter: adapter) - self.fetchedItems = items + let initialItems = Item.fetchAll(statement, adapter: adapter) + self.fetchedItems = initialItems self.isSameItem = self.isSameItemFactory(db) - if self.hasChangesCallbacks { - // Setup a new transaction observer. + if let checkForChanges = checkForChanges { let observer = FetchedRecordsObserver( - controller: self, - initialItems: items, observedTables: statement.sourceTables, - isSameItem: self.isSameItem) + checkForChanges: checkForChanges) self.observer = observer + observer.items = initialItems db.add(transactionObserver: observer) } } @@ -141,71 +143,180 @@ public final class FetchedRecordsController { setRequest(SQLFetchRequest(sql: sql, arguments: arguments, adapter: adapter)) } - public typealias WillChangeCallback = (FetchedRecordsController) -> () - public typealias DidChangeCallback = (FetchedRecordsController) -> () - - private var willChangeCallback: WillChangeCallback? - private var didChangeCallback: DidChangeCallback? - #if os(iOS) - public typealias TableViewEventCallback = (controller: FetchedRecordsController, record: Record, event: TableViewEvent) -> () - private var tableViewEventCallback: TableViewEventCallback? - /// Registers changes notification callbacks (iOS only). /// /// - parameters: - /// - willChangeCallback: Invoked before records are updated. - /// - tableViewEventCallback: Invoked for each record that has been - /// added, removed, moved, or updated. - /// - didChangeCallback: Invoked after records have been updated. - public func trackChanges(recordsWillChange willChangeCallback: WillChangeCallback? = nil, tableViewEvent tableViewEventCallback: TableViewEventCallback? = nil, recordsDidChange didChangeCallback: DidChangeCallback? = nil) { - self.willChangeCallback = willChangeCallback - self.tableViewEventCallback = tableViewEventCallback - self.didChangeCallback = didChangeCallback - self.hasChangesCallbacks = (willChangeCallback != nil) || (tableViewEventCallback != nil) || (didChangeCallback != nil) + /// - recordsWillChange: Invoked before records are updated. + /// - tableViewEvent: Invoked for each record that has been added, + /// removed, moved, or updated. + /// - recordsDidChange: Invoked after records have been updated. + public func trackChanges( + recordsWillChange: ((controller: FetchedRecordsController) -> ())? = nil, + tableViewEvent: ((controller: FetchedRecordsController, record: Record, event: TableViewEvent) -> ())? = nil, + recordsDidChange: ((controller: FetchedRecordsController) -> ())? = nil) + { + let recordsWillChangeWithVoidAlongside: ((controller: FetchedRecordsController, fetchedAlongside: Void) -> ())? + if let recordsWillChange = recordsWillChange { + recordsWillChangeWithVoidAlongside = { (controller, _) in recordsWillChange(controller: controller) } + } else { + recordsWillChangeWithVoidAlongside = nil + } + + let recordsDidChangeWithVoidAlongside: ((controller: FetchedRecordsController, fetchedAlongside: Void) -> ())? + if let recordsDidChange = recordsDidChange { + recordsDidChangeWithVoidAlongside = { (controller, _) in recordsDidChange(controller: controller) } + } else { + recordsDidChangeWithVoidAlongside = nil + } + + trackChanges( + fetchAlongside: { _ in }, + recordsWillChange: recordsWillChangeWithVoidAlongside, + tableViewEvent: tableViewEvent, + recordsDidChange: recordsDidChangeWithVoidAlongside) } #else /// Registers changes notification callbacks. /// /// - parameters: - /// - willChangeCallback: Invoked before records are updated. - /// - didChangeCallback: Invoked after records have been updated. - public func trackChanges(recordsWillChange willChangeCallback: WillChangeCallback? = nil, recordsDidChange didChangeCallback: DidChangeCallback? = nil) { - self.willChangeCallback = willChangeCallback - self.didChangeCallback = didChangeCallback - self.hasChangesCallbacks = (willChangeCallback != nil) || (didChangeCallback != nil) + /// - recordsWillChange: Invoked before records are updated. + /// - recordsDidChange: Invoked after records have been updated. + public func trackChanges( + recordsWillChange: ((controller: FetchedRecordsController) -> ())? = nil, + recordsDidChange: ((controller: FetchedRecordsController) -> ())? = nil) + { + let recordsWillChangeWithVoidAlongside: ((controller: FetchedRecordsController, fetchedAlongside: Void) -> ())? + if let recordsWillChange = recordsWillChange { + recordsWillChangeWithVoidAlongside = { (controller, _) in recordsWillChange(controller: controller) } + } else { + recordsWillChangeWithVoidAlongside = nil + } + + let recordsDidChangeWithVoidAlongside: ((controller: FetchedRecordsController, fetchedAlongside: Void) -> ())? + if let recordsDidChange = recordsDidChange { + recordsDidChangeWithVoidAlongside = { (controller, _) in recordsDidChange(controller: controller) } + } else { + recordsDidChangeWithVoidAlongside = nil + } + + trackChanges( + fetchAlongside: { _ in }, + recordsWillChange: recordsWillChangeWithVoidAlongside, + recordsDidChange: recordsDidChangeWithVoidAlongside) } #endif - private var hasChangesCallbacks: Bool = false { - didSet { - // Setting hasChangesCallbacks to false *will* stop database changes - // observation only after last changes are processed, in - // FetchedRecordsObserver.databaseDidCommit. This allows user code - // to change callbacks multiple times: tracking will stop if and - // only if the last set callbacks are nil. - // - // Conversely, setting hasChangesCallbacks to true must make - // sure that database changes are observed. But only if - // performFetch() has been called. - if let items = fetchedItems where hasChangesCallbacks && observer == nil { - // Setup a new transaction observer. Use - // database.write, so that the transaction observer is added on the - // same serialized queue as transaction callbacks. - databaseWriter.write { db in - let statement = try! self.request.selectStatement(db) - let observer = FetchedRecordsObserver( - controller: self, - initialItems: items, - observedTables: statement.sourceTables, - isSameItem: self.isSameItemFactory(db)) - self.observer = observer - db.add(transactionObserver: observer) - observer.checkForChanges(in: db) - } + #if os(iOS) + /// Registers changes notification callbacks (iOS only). + /// + /// - parameters: + /// - fetchAlongside: The value returned from this closure is given to + /// recordsWillChange and recordsDidChange callbacks, as their + /// `fetchedAlongside` argument. The closure is guaranteed to see the + /// database in the state it has just after eventual changes to the + /// fetched records have been performed. Use it in order to fetch + /// values that must be consistent with the fetched records. + /// - recordsWillChange: Invoked before records are updated. + /// - tableViewEvent: Invoked for each record that has been added, + /// removed, moved, or updated. + /// - recordsDidChange: Invoked after records have been updated. + public func trackChanges( + fetchAlongside: (Database) -> T, + recordsWillChange: ((controller: FetchedRecordsController, fetchedAlongside: T) -> ())? = nil, + tableViewEvent: ((controller: FetchedRecordsController, record: Record, event: TableViewEvent) -> ())? = nil, + recordsDidChange: ((controller: FetchedRecordsController, fetchedAlongside: T) -> ())? = nil) + { + // If some changes are currently processed, make sure they are + // discarded because they would trigger previously set callbacks. + observer?.invalidate() + observer = nil + + guard (recordsWillChange != nil) || (tableViewEvent != nil) || (recordsDidChange != nil) else { + // Stop tracking + return + } + + let initialItems = fetchedItems + databaseWriter.write { db in + let fetchedChangesController = FetchedChangesController( + controller: self, + isSameItem: self.isSameItemFactory(db), + fetchAlongside: fetchAlongside, + recordsWillChange: recordsWillChange, + tableViewEvent: tableViewEvent, + recordsDidChange: recordsDidChange) + + // This closure erases the generic type T of data fetched alongside. + let checkForChanges = { (observer: FetchedRecordsObserver) -> () in + fetchedChangesController.checkForChanges(observer) + } + + let statement = try! self.request.selectStatement(db) + let observer = FetchedRecordsObserver( + observedTables: statement.sourceTables, + checkForChanges: checkForChanges) + self.observer = observer + if let initialItems = initialItems { + observer.items = initialItems + db.add(transactionObserver: observer) + observer.performChangesChecking() } } } + #else + /// Registers changes notification callbacks. + /// + /// - parameters: + /// - fetchAlongside: The value returned from this closure is given to + /// recordsWillChange and recordsDidChange callbacks, as their + /// `fetchedAlongside` argument. The closure is guaranteed to see the + /// database in the state it has just after eventual changes to the + /// fetched records have been performed. Use it in order to fetch + /// values that must be consistent with the fetched records. + /// - recordsWillChange: Invoked before records are updated. + /// - recordsDidChange: Invoked after records have been updated. + public func trackChanges( + fetchAlongside: (Database) -> T, + recordsWillChange: ((controller: FetchedRecordsController, fetchedAlongside: T) -> ())? = nil, + recordsDidChange: ((controller: FetchedRecordsController, fetchedAlongside: T) -> ())? = nil) + { + // If some changes are currently processed, make sure they are + // discarded because they would trigger previously set callbacks. + observer?.invalidate() + observer = nil + + guard (recordsWillChange != nil) || (recordsDidChange != nil) else { + // Stop tracking + return + } + + let initialItems = fetchedItems + databaseWriter.write { db in + let fetchedChangesController = FetchedChangesController( + controller: self, + fetchAlongside: fetchAlongside, + recordsWillChange: recordsWillChange, + recordsDidChange: recordsDidChange) + + // This closure erases the generic type T of data fetched alongside. + let checkForChanges = { (observer: FetchedRecordsObserver) -> () in + fetchedChangesController.checkForChanges(observer) + } + + let statement = try! self.request.selectStatement(db) + let observer = FetchedRecordsObserver( + observedTables: statement.sourceTables, + checkForChanges: checkForChanges) + self.observer = observer + if let initialItems = initialItems { + observer.items = initialItems + db.add(transactionObserver: observer) + observer.performChangesChecking() + } + } + } + #endif // MARK: - Accessing Records @@ -232,7 +343,7 @@ public final class FetchedRecordsController { private var fetchedItems: [Item]? // The record comparator - private var isSameItem: ((Item, Item) -> Bool) + private var isSameItem: (Item, Item) -> Bool // The record comparator builder. It helps us supporting types that adopt // MutablePersistable: we just have to wait for a database connection, in @@ -244,19 +355,14 @@ public final class FetchedRecordsController { private var request: FetchRequest { didSet { guard let observer = observer else { return } - databaseWriter.write { db in - observer.checkForChanges(in: db) + databaseWriter.write { _ in + observer.performChangesChecking() } } } // The eventual current database observer private var observer: FetchedRecordsObserver? - - private func stopTrackingChanges() { - observer?.invalidate() - observer = nil - } } @@ -330,69 +436,63 @@ extension FetchedRecordsController where Record: TableMapping { } -// MARK: - FetchedRecordsObserver +// MARK: - FetchedChangesController -/// FetchedRecordsController adopts TransactionObserver so that it can -/// monitor changes to its fetched records. -private final class FetchedRecordsObserver : TransactionObserver { - weak var controller: FetchedRecordsController? // If nil, self is invalidated. - let observedTables: Set +/// FetchedChangesController computes and notifies changes +private class FetchedChangesController { + // THIS WEAK REFERENCE MUST NEVER BECOME STRONG if we want to allow user + // callbacks to avoid retain cycle with unowned references: + // + // controller.trackChanges { [unowned self] ... } + // + // Should controller become strong at any point before callbacks are + // called, such unowned reference would have an opportunity to crash. + weak var controller: FetchedRecordsController? + let fetchAlongside: (Database) -> T + let recordsWillChange: ((controller: FetchedRecordsController, fetchedAlongside: T) -> ())? + let recordsDidChange: ((controller: FetchedRecordsController, fetchedAlongside: T) -> ())? + + #if os(iOS) let isSameItem: (Item, Item) -> Bool - var needsComputeChanges: Bool - var items: [Item] - let queue: dispatch_queue_t // protects items + var tableViewEvent: ((controller: FetchedRecordsController, record: Record, event: TableViewEvent) -> ())? - init(controller: FetchedRecordsController, initialItems: [Item], observedTables: Set, isSameItem: (Item, Item) -> Bool) { + init( + controller: FetchedRecordsController, + isSameItem: (Item, Item) -> Bool, + fetchAlongside: (Database) -> T, + recordsWillChange: ((controller: FetchedRecordsController, fetchedAlongside: T) -> ())?, + tableViewEvent: ((controller: FetchedRecordsController, record: Record, event: TableViewEvent) -> ())?, + recordsDidChange: ((controller: FetchedRecordsController, fetchedAlongside: T) -> ())?) + { self.controller = controller - self.items = initialItems - self.observedTables = observedTables self.isSameItem = isSameItem - self.needsComputeChanges = false - self.queue = dispatch_queue_create("GRDB.FetchedRecordsObserver", DISPATCH_QUEUE_SERIAL) + self.fetchAlongside = fetchAlongside + self.recordsWillChange = recordsWillChange + self.tableViewEvent = tableViewEvent + self.recordsDidChange = recordsDidChange } - - func invalidate() { - controller = nil + #else + init( + controller: FetchedRecordsController, + fetchAlongside: (Database) -> T, + recordsWillChange: ((controller: FetchedRecordsController, fetchedAlongside: T) -> ())?, + recordsDidChange: ((controller: FetchedRecordsController, fetchedAlongside: T) -> ())?) + { + self.controller = controller + self.fetchAlongside = fetchAlongside + self.recordsWillChange = recordsWillChange + self.recordsDidChange = recordsDidChange } - - #if SQLITE_ENABLE_PREUPDATE_HOOK - /// Part of the TransactionObserverType protocol - func databaseWillChange(with event: DatabasePreUpdateEvent) { } #endif - /// Part of the TransactionObserver protocol - func databaseDidChange(with event: DatabaseEvent) { - if !needsComputeChanges && observedTables.contains(event.tableName) { - needsComputeChanges = true - } - } - - /// Part of the TransactionObserver protocol - func databaseWillCommit() throws { } - - /// Part of the TransactionObserver protocol - func databaseDidRollback(_ db: Database) { - needsComputeChanges = false - } - - /// Part of the TransactionObserver protocol - func databaseDidCommit(_ db: Database) { - // The databaseDidCommit callback is called in the database writer - // dispatch queue, which is serialized: it is guaranteed to process the - // last database transaction. - - // Were observed tables modified? - guard needsComputeChanges else { return } - needsComputeChanges = false - - checkForChanges(in: db) - } - // Precondition: this method must be called from the database writer's // serialized dispatch queue. - func checkForChanges(in db: Database) { - // Invalidated? - guard let controller = self.controller else { return } + func checkForChanges(_ observer: FetchedRecordsObserver) { + // Observer invalidated? + guard observer.isValid else { return } + + // Controller alive? + guard let request = controller?.request, databaseWriter = controller?.databaseWriter else { return } // Fetch items. // @@ -417,9 +517,11 @@ private final class FetchedRecordsObserver : Transaction // with a semaphore: let semaphore = dispatch_semaphore_create(0)! var fetchedItems: [Item]! = nil + var fetchedAlongside: T! = nil - controller.databaseWriter.readFromWrite { db in - fetchedItems = Item.fetchAll(db, controller.request) + databaseWriter.readFromWrite { db in + fetchedItems = Item.fetchAll(db, request) + fetchedAlongside = self.fetchAlongside(db) // Fetch is complete: dispatch_semaphore_signal(semaphore) @@ -428,58 +530,70 @@ private final class FetchedRecordsObserver : Transaction // Process the fetched items - dispatch_async(queue) { + dispatch_async(observer.queue) { [weak observer] in // Wait for the fetch to complete: dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER) assert(fetchedItems != nil) + assert(fetchedAlongside != nil) - // Invalidated? - guard let controller = self.controller else { return } + // Observer invalidated? + guard let strongObserver = observer else { return } + guard strongObserver.isValid else { return } + // Controller alive? + guard let controllerQueue = self.controller?.queue else { return } + // Changes? #if os(iOS) let tableViewChanges: [TableViewChange]? - if controller.tableViewEventCallback != nil { + if self.tableViewEvent != nil { // Compute table view changes - let changes = self.computeTableViewChanges(from: self.items, to: fetchedItems) + let changes = self.computeTableViewChanges(from: strongObserver.items, to: fetchedItems) guard !changes.isEmpty else { return } tableViewChanges = changes } else { // Look for a row difference - guard fetchedItems.count != self.items.count || zip(fetchedItems, self.items).any({ (fetchedItem, item) in fetchedItem.row != item.row }) else { + guard fetchedItems.count != strongObserver.items.count || zip(fetchedItems, strongObserver.items).any({ (fetchedItem, item) in fetchedItem.row != item.row }) else { return } tableViewChanges = nil } #else // Look for a row difference - guard fetchedItems.count != self.items.count || zip(fetchedItems, self.items).any({ (fetchedItem, item) in fetchedItem.row != item.row }) else { + guard fetchedItems.count != strongObserver.items.count || zip(fetchedItems, strongObserver.items).any({ (fetchedItem, item) in fetchedItem.row != item.row }) else { return } #endif // Ready for next check - self.items = fetchedItems + strongObserver.items = fetchedItems - dispatch_async(controller.queue) { - // Invalidated? + dispatch_async(controllerQueue) { + // Observer invalidated? + guard let strongObserver = observer else { return } + guard strongObserver.isValid else { return } + + // Now we can retain controller. guard let controller = self.controller else { return } - if controller.hasChangesCallbacks { - controller.willChangeCallback?(controller) - controller.fetchedItems = fetchedItems - #if os(iOS) - if let tableViewEventCallback = controller.tableViewEventCallback, let tableViewChanges = tableViewChanges { - for change in tableViewChanges { - tableViewEventCallback(controller: controller, record: change.record, event: change.event) - } + if let recordsWillChange = self.recordsWillChange { + recordsWillChange(controller: controller, fetchedAlongside: fetchedAlongside) + } + + controller.fetchedItems = fetchedItems + + #if os(iOS) + if let tableViewEvent = self.tableViewEvent, let tableViewChanges = tableViewChanges { + for change in tableViewChanges { + tableViewEvent(controller: controller, record: change.record, event: change.event) } - #endif - controller.didChangeCallback?(controller) - } else { - controller.stopTrackingChanges() + } + #endif + + if let recordsDidChange = self.recordsDidChange { + recordsDidChange(controller: controller, fetchedAlongside: fetchedAlongside) } } } @@ -487,6 +601,72 @@ private final class FetchedRecordsObserver : Transaction } +// MARK: - FetchedRecordsObserver + +/// FetchedRecordsController adopts TransactionObserverType so that it can +/// monitor changes to its fetched records. +private final class FetchedRecordsObserver : TransactionObserver { + var isValid: Bool + let observedTables: Set + var needsComputeChanges: Bool + var items: [Item]! // ought to be not nil when observer has started tracking transactions + let queue: dispatch_queue_t // protects items + var checkForChanges: (FetchedRecordsObserver) -> () + + init(observedTables: Set, checkForChanges: (FetchedRecordsObserver) -> ()) { + self.isValid = true + self.items = nil + self.observedTables = observedTables + self.needsComputeChanges = false + self.queue = dispatch_queue_create("GRDB.FetchedRecordsObserver", DISPATCH_QUEUE_SERIAL) + self.checkForChanges = checkForChanges + } + + func invalidate() { + isValid = false + } + + #if SQLITE_ENABLE_PREUPDATE_HOOK + /// Part of the TransactionObserverType protocol + func databaseWillChange(with event: DatabasePreUpdateEvent) { } + #endif + + /// Part of the TransactionObserverType protocol + func databaseDidChange(with event: DatabaseEvent) { + if !needsComputeChanges && observedTables.contains(event.tableName) { + needsComputeChanges = true + } + } + + /// Part of the TransactionObserverType protocol + func databaseWillCommit() throws { } + + /// Part of the TransactionObserverType protocol + func databaseDidRollback(_ db: Database) { + needsComputeChanges = false + } + + /// Part of the TransactionObserverType protocol + func databaseDidCommit(_ db: Database) { + // The databaseDidCommit callback is called in the database writer + // dispatch queue, which is serialized: it is guaranteed to process the + // last database transaction. + + // Were observed tables modified? + guard needsComputeChanges else { return } + needsComputeChanges = false + + performChangesChecking() + } + + // Precondition: this method must be called from the database writer's + // serialized dispatch queue. + func performChangesChecking() { + checkForChanges(self) + } +} + + // MARK: UITableView Support #if os(iOS) @@ -531,11 +711,11 @@ private final class FetchedRecordsObserver : Transaction guard let fetchedItems = fetchedItems, let index = fetchedItems.index(where: { isSameItem($0, item) }) else { return nil } - return makeIndexPath(forRow: index, inSection: 0) + return NSIndexPath(forRow: index, inSection: 0) } } - extension FetchedRecordsObserver { + extension FetchedChangesController { private func computeTableViewChanges(from s: [Item], to t: [Item]) -> [TableViewChange] { let m = s.count @@ -547,14 +727,14 @@ private final class FetchedRecordsObserver : Transaction var changes = [TableViewChange]() for (row, item) in s.enumerated() { - let deletion = TableViewChange.deletion(item: item, indexPath: makeIndexPath(forRow: row, inSection: 0)) + let deletion = TableViewChange.deletion(item: item, indexPath: NSIndexPath(forRow: row, inSection: 0)) changes.append(deletion) d[row + 1][0] = changes } changes.removeAll() for (col, item) in t.enumerated() { - let insertion = TableViewChange.insertion(item: item, indexPath: makeIndexPath(forRow: col, inSection: 0)) + let insertion = TableViewChange.insertion(item: item, indexPath: NSIndexPath(forRow: col, inSection: 0)) changes.append(insertion) d[0][col + 1] = changes } @@ -577,16 +757,16 @@ private final class FetchedRecordsObserver : Transaction // Record operation. let minimumCount = min(del.count, ins.count, sub.count) if del.count == minimumCount { - let deletion = TableViewChange.deletion(item: s[sx], indexPath: makeIndexPath(forRow: sx, inSection: 0)) + let deletion = TableViewChange.deletion(item: s[sx], indexPath: NSIndexPath(forRow: sx, inSection: 0)) del.append(deletion) d[sx+1][tx+1] = del } else if ins.count == minimumCount { - let insertion = TableViewChange.insertion(item: t[tx], indexPath: makeIndexPath(forRow: tx, inSection: 0)) + let insertion = TableViewChange.insertion(item: t[tx], indexPath: NSIndexPath(forRow: tx, inSection: 0)) ins.append(insertion) d[sx+1][tx+1] = ins } else { - let deletion = TableViewChange.deletion(item: s[sx], indexPath: makeIndexPath(forRow: sx, inSection: 0)) - let insertion = TableViewChange.insertion(item: t[tx], indexPath: makeIndexPath(forRow: tx, inSection: 0)) + let deletion = TableViewChange.deletion(item: s[sx], indexPath: NSIndexPath(forRow: sx, inSection: 0)) + let insertion = TableViewChange.insertion(item: t[tx], indexPath: NSIndexPath(forRow: tx, inSection: 0)) sub.append(deletion) sub.append(insertion) d[sx+1][tx+1] = sub @@ -794,7 +974,7 @@ private final class FetchedRecordsObserver : Transaction private final class Item : RowConvertible, Equatable { let row: Row - // TODO: Is is a good idea to lazily load records? + // Records are lazily loaded lazy var record: T = { var record = T(row: self.row) record.awakeFromFetch(row: self.row) @@ -813,12 +993,6 @@ private func ==(lhs: Item, rhs: Item) -> Bool { // MARK: - Utils -/// Same as NSIndexPath(forRow:inSection:); works when UIKit is not available. -private func makeIndexPath(forRow row:Int, inSection section: Int) -> NSIndexPath { - return [section, row].withUnsafeBufferPointer { buffer in NSIndexPath(indexes: buffer.baseAddress, length: buffer.count) } -} - - /// Returns a function that returns the primary key of a row /// /// dbQueue.inDatabase { db in diff --git a/README.md b/README.md index 99f2a5cc6..962b7be24 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ It ships with a **low-level SQLite API**, and high-level tools that help dealing - **Database Changes Observation**: perform post-commit and post-rollback actions - **Fetched Records Controller**: automated tracking of changes in a query results, and UITableView animations - **Encryption** with SQLCipher +- **Support for custom SQLite builds** More than a set of tools that leverage SQLite abilities, GRDB is also: @@ -24,7 +25,7 @@ You should give it a try. --- -**May 30, 2016: GRDB.swift 0.70.1 is out** ([changelog](CHANGELOG.md)). Follow [@groue](http://twitter.com/groue) on Twitter for release announcements and usage tips. +**June 5, 2016: GRDB.swift 0.71.0 is out** ([changelog](CHANGELOG.md)). Follow [@groue](http://twitter.com/groue) on Twitter for release announcements and usage tips. **Requirements**: iOS 7.0+ / OSX 10.9+, Xcode 7.3+ @@ -142,7 +143,7 @@ Documentation **Reference** -- [GRDB Reference](http://cocoadocs.org/docsets/GRDB.swift/0.70.1/index.html) (on cocoadocs.org) +- [GRDB Reference](http://cocoadocs.org/docsets/GRDB.swift/0.71.0/index.html) (on cocoadocs.org) **Getting started** @@ -178,11 +179,6 @@ Documentation ### Installation -#### iOS7 - -You can use GRDB in a project targetting iOS7. See [GRDBDemoiOS7](DemoApps/GRDBDemoiOS7) for more information. - - #### CocoaPods [CocoaPods](http://cocoapods.org/) is a dependency manager for Xcode projects. @@ -193,9 +189,11 @@ To use GRDB with CocoaPods, specify in your Podfile: source 'https://github.com/CocoaPods/Specs.git' use_frameworks! -pod 'GRDB.swift', '~> 0.70.1' +pod 'GRDB.swift', '~> 0.71.0' ``` +> :point_up: **Note**: [SQLCipher](#encryption) and [custom SQLite builds](#custom-sqlite-builds) are not available via CocoaPods. + #### Carthage @@ -204,9 +202,11 @@ pod 'GRDB.swift', '~> 0.70.1' To use GRDB with Carthage, specify in your Cartfile: ``` -github "groue/GRDB.swift" ~> 0.70.1 +github "groue/GRDB.swift" ~> 0.71.0 ``` +> :point_up: **Note**: [custom SQLite builds](#custom-sqlite-builds) are not available via Carthage. + #### Manually @@ -218,6 +218,11 @@ github "groue/GRDB.swift" ~> 0.70.1 See [GRDBDemoiOS](DemoApps/GRDBDemoiOS) for an example of such integration. +#### Custom SQLite builds + +**By default, GRDB uses the SQLite library that ships with the operating system.** You can build GRDB with custom SQLite sources and options, through [swiftlyfalling/SQLiteLib](https://github.com/swiftlyfalling/SQLiteLib). See [installation instructions](SQLiteCustom/README.md). + + Database Connections ==================== @@ -306,7 +311,7 @@ let dbQueue = try DatabaseQueue( configuration: config) ``` -See [Configuration](http://cocoadocs.org/docsets/GRDB.swift/0.70.1/Structs/Configuration.html) for more details. +See [Configuration](http://cocoadocs.org/docsets/GRDB.swift/0.71.0/Structs/Configuration.html) for more details. ## Database Pools @@ -386,7 +391,7 @@ let dbPool = try DatabasePool( configuration: config) ``` -See [Configuration](http://cocoadocs.org/docsets/GRDB.swift/0.70.1/Structs/Configuration.html) for more details. +See [Configuration](http://cocoadocs.org/docsets/GRDB.swift/0.71.0/Structs/Configuration.html) for more details. Database pools are more memory-hungry than database queues. See [Memory Management](#memory-management) for more information. @@ -955,7 +960,9 @@ dbComponents.dateComponents // NSDateComponents ### NSNumber and NSDecimalNumber -While NSNumber deserves no special discussion, NSDecimalNumber does. +**NSNumber** can be stored and fetched from the database just like other [values](#values). Floating point NSNumbers are stored as Double. Integer and boolean, as Int64. Integers that don't fit Int64 won't be stored: you'll get a fatal error instead. Be cautious when an NSNumber contains an UInt64, for example. + +NSDecimalNumber deserves a longer discussion: **SQLite has no support for decimal numbers.** Given the table below, SQLite will actually store integers or doubles: @@ -1049,7 +1056,7 @@ try dbQueue.inTransaction { db in } ``` -The transaction is rollbacked if an error is thrown within the transaction body, and that error is rethrown by the inTransaction method. +If an error is thrown within the transaction body, the transaction is rollbacked and the error is rethrown by the `inTransaction` method. If you return `.Rollback` from your closure, the transaction is also rollbacked, but no error is thrown. If you want to insert a transaction between other database statements, you can use the Database.inTransaction() function: @@ -1102,7 +1109,7 @@ try dbQueue.inTransaction { db in } ``` -The savepoint is rollbacked if an error is thrown within the savepoint body, and that error is rethrown by the inSavepoint method. +If an error is thrown within the savepoint body, the savepoint is rollbacked and the error is rethrown by the `inSavepoint` method. If you return `.Rollback` from your closure, the body is also rollbacked, but no error is thrown. **Unlike transactions, savepoints can be nested.** They implicitly open a transaction if no one was opened when the savepoint begins. As such, they behave just like nested transactions. Yet the database changes are only committed to disk when the outermost savepoint is committed: @@ -1690,7 +1697,7 @@ See [fetching methods](#fetching-methods) for information about the `fetch`, `fe #### RowConvertible and Row Adapters -RowConvertible consume row columns by name: +RowConvertible types usually consume rows by column name: ```swift extension PointOfInterest : RowConvertible { @@ -2623,6 +2630,25 @@ do { See also [TableChangeObserver.swift](https://gist.github.com/groue/2e21172719e634657dfd), which shows a transaction observer that notifies of modified database tables with NSNotificationCenter. +### Support for SQLite Pre-Update Hooks + +A [custom SQLite build](#custom-sqlite-builds) can activate [SQLite "preupdate hooks"](http://www.sqlite.org/sessions/c3ref/preupdate_count.html). In this case, TransactionObserverType gets an extra callback which lets you observe individual column values in the rows modified by a transaction: + +```swift +public protocol TransactionObserverType : class { + #if SQLITE_ENABLE_PREUPDATE_HOOK + /// Notifies before a database change (insert, update, or delete) + /// with change information (initial / final values for the row's + /// columns). + /// + /// The event is only valid for the duration of this method call. If you + /// need to keep it longer, store a copy: event.copy(). + func databaseWillChangeWithEvent(event: DatabasePreUpdateEvent) + #endif +} +``` + + ## FetchedRecordsController **You use FetchedRecordsController to track changes in the results of an SQLite request.** @@ -2735,7 +2761,7 @@ See [Implementing Table View Updates](#implementing-table-view-updates) for more ```swift controller.trackChanges { controller in - let persons = controller.fetchedRecords! // [Person] + let newPersons = controller.fetchedRecords! // [Person] } ``` @@ -2766,6 +2792,25 @@ try dbQueue.inDatabase { db in When you need to take immediate action, force the controller to refresh immediately with its `performFetch` method. In this case, changes callbacks are *not* called. +**Values fetched from inside callbacks may be inconsistent with the controller's records.** This is because after database has changed, and before the controller had the opportunity to invoke callbacks in the main thread, other database changes can happen. + +To avoid inconsistencies, provide a `fetchAlongside` argument to the `trackChanges` method, as below: + +```swift +controller.trackChanges( + fetchAlongside: { db in + // Fetch any extra value, for example the number of fetched records: + return Person.fetchCount(db) + }, + recordsDidChange: { (controller, count) in + // The extra value is the second argument. + let recordsCount = controller.fetchedRecords!.count + assert(count == recordsCount) // guaranteed + }) +``` + + + ### Modifying the Fetch Request You can change a fetched records controller's fetch request or SQL query. @@ -2879,6 +2924,8 @@ self.controller.trackChanges( See [GRDBDemoiOS](DemoApps/GRDBDemoiOS) for an sample app that uses FetchedRecordsController. +> :point_up: **Note**: our sample code above uses `unowned` references to the table view controller. This is a safe pattern as long as the table view controller owns the fetched records controller, and is deallocated from the main thread (this is usually the case). In other situations, prefer weak references. + ### FetchedRecordsController Concurrency @@ -3228,7 +3275,7 @@ let count2 = dbQueue.inDatabase { db in SQLite concurrency is a wiiide topic. -First have a detailed look at the full API of [DatabaseQueue](http://cocoadocs.org/docsets/GRDB.swift/0.70.1/Classes/DatabaseQueue.html) and [DatabasePool](http://cocoadocs.org/docsets/GRDB.swift/0.70.1/Classes/DatabasePool.html). Both adopt the [DatabaseReader](http://cocoadocs.org/docsets/GRDB.swift/0.70.1/Protocols/DatabaseReader.html) and [DatabaseWriter](http://cocoadocs.org/docsets/GRDB.swift/0.70.1/Protocols/DatabaseWriter.html) protocols, so that you can write code that targets both classes. +First have a detailed look at the full API of [DatabaseQueue](http://cocoadocs.org/docsets/GRDB.swift/0.71.0/Classes/DatabaseQueue.html) and [DatabasePool](http://cocoadocs.org/docsets/GRDB.swift/0.71.0/Classes/DatabasePool.html). Both adopt the [DatabaseReader](http://cocoadocs.org/docsets/GRDB.swift/0.71.0/Protocols/DatabaseReader.html) and [DatabaseWriter](http://cocoadocs.org/docsets/GRDB.swift/0.71.0/Protocols/DatabaseWriter.html) protocols, so that you can write code that targets both classes. If the built-in queues and pools do not fit your needs, or if you can not guarantee that a single queue or pool is accessing your database file, you may have a look at: @@ -3324,7 +3371,6 @@ Sample Code - The [Documentation](#documentation) is full of GRDB snippets. - [GRDBDemoiOS](DemoApps/GRDBDemoiOS): A sample iOS application. -- [GRDBDemoiOS7](DemoApps/GRDBDemoiOS7): A sample iOS7 application. - Check `GRDB.xcworkspace`: it contains GRDB-enabled playgrounds to play with. - How to read and write NSDate as timestamp: [DatabaseTimestamp.playground](Playgrounds/DatabaseTimestamp.playground/Contents.swift) - How to synchronize a database table with a JSON payload: [JSONSynchronization.playground](Playgrounds/JSONSynchronization.playground/Contents.swift) @@ -3337,6 +3383,6 @@ Sample Code **Thanks** - [Pierlis](http://pierlis.com), where we write great software. -- [Vladimir Babin](https://github.com/Chiliec), [Pascal Edmond](https://github.com/pakko972), [@peter-ss](https://github.com/peter-ss), [Pierre-Loïc Raynaud](https://github.com/pierlo) and [@swiftlyfalling](https://github.com/swiftlyfalling) for their contributions, help, and feedback on GRDB. +- [Vladimir Babin](https://github.com/Chiliec), [Pascal Edmond](https://github.com/pakko972), [@peter-ss](https://github.com/peter-ss), [Pierre-Loïc Raynaud](https://github.com/pierlo), [Steven Schveighoffer](https://github.com/schveiguy) and [@swiftlyfalling](https://github.com/swiftlyfalling) for their contributions, help, and feedback on GRDB. - [@aymerick](https://github.com/aymerick) and [Mathieu "Kali" Poumeyrol](https://github.com/kali) because SQL. - [ccgus/fmdb](https://github.com/ccgus/fmdb) for its excellency. diff --git a/Support/Info.plist b/Support/Info.plist index 7c9dbe242..3357adebc 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.70.1 + 0.71.0 CFBundleSignature ???? CFBundleVersion diff --git a/TODO.md b/TODO.md index 7758e08e9..49aa56935 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,3 @@ -- [ ] FetchedRecordsController: let the user provide an "fetch along" block that allows fetching from a known state of the database: right after changes have been found. The problem today is that when one fetches from the didChange callback, the database may have changed since changes have been computed. - [ ] FetchedRecordsController: see if we can replace identity comparison function with a function that returns an Equatable value (beware the generics trouble). See if this can help optimize memory use, and use a sortedMerge() algorithm. - [ ] GRDBCipher: remove limitations on iOS or OS X versions - [ ] FetchedRecordsController: take inspiration from https://github.com/jflinter/Dwifft diff --git a/Tests/Public/Core/DatabaseValueConvertible/NSNumberTests.swift b/Tests/Public/Core/DatabaseValueConvertible/NSNumberTests.swift index 52a5f31cb..d7b2ae6cd 100644 --- a/Tests/Public/Core/DatabaseValueConvertible/NSNumberTests.swift +++ b/Tests/Public/Core/DatabaseValueConvertible/NSNumberTests.swift @@ -11,48 +11,91 @@ class NSNumberTests: GRDBTestCase { func testNSNumberDatabaseValueToSwiftType() { // case "c": - let number_char = NSNumber(value: Int8.min + 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_char), Int64(Int8.min + 1)) + let number_char = NSNumber(value: Int8.min + 1) + XCTAssertEqual(String(cString: number_char.objCType), "c") + let dbv_char = number_char.databaseValue + XCTAssertEqual(Int64.fromDatabaseValue(dbv_char), Int64(Int8.min + 1)) + // case "C": - let number_unsignedChar = NSNumber(value: UInt8.max - 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_unsignedChar), Int64(UInt8.max - 1)) + let number_unsignedChar = NSNumber(value: UInt8.max - 1) +// XCTAssertEqual(String(cString: number_unsignedChar.objCType), "C") // get "s" instead of "C" + let dbv_unsignedChar = number_unsignedChar.databaseValue + XCTAssertEqual(Int64.fromDatabaseValue(dbv_unsignedChar), Int64(UInt8.max - 1)) + // case "s": - let number_short = NSNumber(value: Int16.min + 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_short), Int64(Int16.min + 1)) + let number_short = NSNumber(value: Int16.min + 1) + XCTAssertEqual(String(cString: number_short.objCType), "s") + let dbv_short = number_short.databaseValue + XCTAssertEqual(Int64.fromDatabaseValue(dbv_short), Int64(Int16.min + 1)) + // case "S": - let number_unsignedShort = NSNumber(value: UInt16.max - 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_unsignedShort), Int64(UInt16.max - 1)) + let number_unsignedShort = NSNumber(value: UInt16.max - 1) +// XCTAssertEqual(String(cString: number_unsignedShort.objCType), "S") // get "i" instead of "S" + let dbv_unsignedShort = number_unsignedShort.databaseValue + XCTAssertEqual(Int64.fromDatabaseValue(dbv_unsignedShort), Int64(UInt16.max - 1)) + // case "i": - let number_int = NSNumber(value: Int32.min + 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_int), Int64(Int32.min + 1)) + let number_int = NSNumber(value: Int32.min + 1) + XCTAssertEqual(String(cString: number_int.objCType), "i") + let dbv_int = number_int.databaseValue + XCTAssertEqual(Int64.fromDatabaseValue(dbv_int), Int64(Int32.min + 1)) + // case "I": - let number_unsignedInt = NSNumber(value: UInt32.max - 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_unsignedInt), Int64(UInt32.max - 1)) + let number_unsignedInt = NSNumber(value: UInt32.max - 1) +// XCTAssertEqual(String(cString: number_unsignedInt.objCType), "I") // get "q" instead of "I" + let dbv_unsignedInt = number_unsignedInt.databaseValue + XCTAssertEqual(Int64.fromDatabaseValue(dbv_unsignedInt), Int64(UInt32.max - 1)) + // case "l": - let number_long = NSNumber(value: Int.min + 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_long), Int64(Int.min + 1)) + let number_long = NSNumber(value: Int.min + 1) +// XCTAssertEqual(String(cString: number_long.objCType), "l") // get "q" instead of "l" + let dbv_long = number_long.databaseValue + XCTAssertEqual(Int64.fromDatabaseValue(dbv_long), Int64(Int.min + 1)) + // case "L": - // TODO: Fails with fatalError: - //let number_unsignedLong = NSNumber(unsignedLong: UInt.max - 1).databaseValue - //XCTAssertEqual(Int64.fromDatabaseValue(number_unsignedLong), Int64(UInt.max - 1)) + let number_unsignedLong = NSNumber(value: UInt(UInt32.max)) +// XCTAssertEqual(String(cString: number_unsignedLong.objCType), "L") // get "q" instead of "L" + let dbv_unsignedLong = number_unsignedLong.databaseValue + XCTAssertEqual(Int64.fromDatabaseValue(dbv_unsignedLong), Int64(UInt32.max)) + // fatal error: value can not be converted to Int64 because it is greater than Int64.max + // _ dbv_unsignedLong = NSNumber(value: UInt.max - 1).databaseValue + // case "q": - let number_longLong = NSNumber(value: Int64.min + 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_longLong), Int64(Int64.min + 1)) + let number_longLong = NSNumber(value: Int64.min + 1) + XCTAssertEqual(String(cString: number_longLong.objCType), "q") + let dbv_longLong = number_longLong.databaseValue + XCTAssertEqual(Int64.fromDatabaseValue(dbv_longLong), Int64(Int64.min + 1)) + // case "Q": - // TODO: Fails with fatalError: - //let number_unsignedLongLong = NSNumber(unsignedLongLong: UInt64.max - 1).databaseValue - //XCTAssertEqual(Int64.fromDatabaseValue(number_unsignedLongLong), Int64(UInt64.max - 1)) + let number_unsignedLongLong = NSNumber(value: UInt64(Int64.max)) +// XCTAssertEqual(String(cString: number_unsignedLongLong.objCType), "Q") // get "q" instead of "Q" + let dbv_unsignedLongLong = number_unsignedLongLong.databaseValue + XCTAssertEqual(Int64.fromDatabaseValue(dbv_unsignedLongLong), Int64.max) + // fatal error: value can not be converted to Int64 because it is greater than Int64.max + // _ = NSNumber(value: UInt64.max - 1).databaseValue + // case "f": - let number_float = NSNumber(value: Float(3.14159)).databaseValue - XCTAssertEqual(Float.fromDatabaseValue(number_float), Float(3.14159)) + let number_float = NSNumber(value: Float(3.14159)) + XCTAssertEqual(String(cString: number_float.objCType), "f") + let dbv_float = number_float.databaseValue + XCTAssertEqual(Float.fromDatabaseValue(dbv_float), Float(3.14159)) + // case "d": - let number_double = NSNumber(value: Double(10000000.01)).databaseValue - XCTAssertEqual(Double.fromDatabaseValue(number_double), Double(10000000.01)) + let number_double = NSNumber(value: Double(10000000.01)) + XCTAssertEqual(String(cString: number_double.objCType), "d") + let dbv_double = number_double.databaseValue + XCTAssertEqual(Double.fromDatabaseValue(dbv_double), Double(10000000.01)) + // case "B": - let number_bool_true = NSNumber(value: true).databaseValue - XCTAssertEqual(Bool.fromDatabaseValue(number_bool_true), true) - let number_bool_false = NSNumber(value: false).databaseValue - XCTAssertEqual(Bool.fromDatabaseValue(number_bool_false), false) + let number_bool_true = NSNumber(value: true) + XCTAssertEqual(String(cString: number_bool_true.objCType), "c") + let dbv_bool_true = number_bool_true.databaseValue + XCTAssertEqual(Bool.fromDatabaseValue(dbv_bool_true), true) + + let number_bool_false = NSNumber(value: false) + XCTAssertEqual(String(cString: number_bool_false.objCType), "c") + let dbv_bool_false = number_bool_false.databaseValue + XCTAssertEqual(Bool.fromDatabaseValue(dbv_bool_false), false) } func testNSNumberDatabaseValueRoundTrip() { diff --git a/Tests/Public/Core/DatabaseValueConvertible/NumericOverflowTests.swift b/Tests/Public/Core/DatabaseValueConvertible/NumericOverflowTests.swift new file mode 100644 index 000000000..acd7eb59d --- /dev/null +++ b/Tests/Public/Core/DatabaseValueConvertible/NumericOverflowTests.swift @@ -0,0 +1,74 @@ +import XCTest +#if USING_SQLCIPHER + import GRDBCipher +#elseif USING_CUSTOMSQLITE + import GRDBCustomSQLite +#else + import GRDB +#endif + +// I think those there is no double between those two, and this is the exact threshold: +private let maxInt64ConvertibleDouble = Double(9223372036854775295 as Int64) +private let minInt64NonConvertibleDouble = Double(9223372036854775296 as Int64) + +// Not sure about the exact threshold +private let minInt64ConvertibleDouble = Double(Int64.min) +private let maxInt64NonConvertibleDouble: Double = -9.223372036854777e+18 + +// Not sure about the exact threshold +private let maxInt32ConvertibleDouble: Double = 2147483647.999999 +private let minInt32NonConvertibleDouble: Double = 2147483648 + +// Not sure about the exact threshold +private let minInt32ConvertibleDouble: Double = -2147483648.999999 +private let maxInt32NonConvertibleDouble: Double = -2147483649 + +class NumericOverflowTests: GRDBTestCase { + + func testHighInt64FromDoubleOverflows() { + XCTAssertEqual(Int64.fromDatabaseValue(maxInt64ConvertibleDouble.databaseValue)!, 9223372036854774784) + XCTAssertTrue(Int64.fromDatabaseValue((minInt64NonConvertibleDouble).databaseValue) == nil) + } + + func testLowInt64FromDoubleOverflows() { + XCTAssertEqual(Int64.fromDatabaseValue(minInt64ConvertibleDouble.databaseValue)!, Int64.min) + XCTAssertTrue(Int64.fromDatabaseValue(maxInt64NonConvertibleDouble.databaseValue) == nil) + } + + func testHighInt32FromDoubleOverflows() { + XCTAssertEqual(Int32.fromDatabaseValue(maxInt32ConvertibleDouble.databaseValue)!, Int32.max) + XCTAssertTrue(Int32.fromDatabaseValue(minInt32NonConvertibleDouble.databaseValue) == nil) + } + + func testLowInt32FromDoubleOverflows() { + XCTAssertEqual(Int32.fromDatabaseValue(minInt32ConvertibleDouble.databaseValue)!, Int32.min) + XCTAssertTrue(Int32.fromDatabaseValue(maxInt32NonConvertibleDouble.databaseValue) == nil) + } + + func testHighIntFromDoubleOverflows() { + if Int64(Int.max) == Int64.max { + // 64 bits Int + XCTAssertEqual(Int64(Int.fromDatabaseValue(maxInt64ConvertibleDouble.databaseValue)!), 9223372036854774784) + XCTAssertTrue(Int.fromDatabaseValue((minInt64NonConvertibleDouble).databaseValue) == nil) + } else { + // 32 bits Int + XCTAssertEqual(Int.max, Int(Int32.max)) + XCTAssertEqual(Int.fromDatabaseValue(maxInt32ConvertibleDouble.databaseValue)!, Int.max) + XCTAssertTrue(Int.fromDatabaseValue(minInt32NonConvertibleDouble.databaseValue) == nil) + } + } + + func testLowIntFromDoubleOverflows() { + if Int64(Int.max) == Int64.max { + // 64 bits Int + XCTAssertEqual(Int.fromDatabaseValue(minInt64ConvertibleDouble.databaseValue)!, Int.min) + XCTAssertTrue(Int.fromDatabaseValue(maxInt64NonConvertibleDouble.databaseValue) == nil) + } else { + // 32 bits Int + XCTAssertEqual(Int.max, Int(Int32.max)) + XCTAssertEqual(Int.fromDatabaseValue(minInt32ConvertibleDouble.databaseValue)!, Int.min) + XCTAssertTrue(Int.fromDatabaseValue(maxInt32NonConvertibleDouble.databaseValue) == nil) + } + } + +} diff --git a/Tests/Public/FetchedRecordsController/FetchedRecordsControllerTests.swift b/Tests/Public/FetchedRecordsController/FetchedRecordsControllerTests.swift index bd8540538..f7886e25c 100644 --- a/Tests/Public/FetchedRecordsController/FetchedRecordsControllerTests.swift +++ b/Tests/Public/FetchedRecordsController/FetchedRecordsControllerTests.swift @@ -10,20 +10,26 @@ import XCTest private class ChangesRecorder { var recordsBeforeChanges: [Record]! var recordsAfterChanges: [Record]! + var countBeforeChanges: Int? + var countAfterChanges: Int? var transactionExpectation: XCTestExpectation? { didSet { recordsBeforeChanges = nil recordsAfterChanges = nil + countBeforeChanges = nil + countAfterChanges = nil } } - func controllerWillChange(_ controller: FetchedRecordsController) { + func controllerWillChange(_ controller: FetchedRecordsController, count: Int? = nil) { recordsBeforeChanges = controller.fetchedRecords + countBeforeChanges = count } /// The default implementation does nothing. - func controllerDidChange(_ controller: FetchedRecordsController) { + func controllerDidChange(_ controller: FetchedRecordsController, count: Int? = nil) { recordsAfterChanges = controller.fetchedRecords + countAfterChanges = count if let transactionExpectation = transactionExpectation { transactionExpectation.fulfill() } @@ -505,6 +511,51 @@ class FetchedRecordsControllerTests: GRDBTestCase { XCTAssertEqual(persons.map { $0.name }, ["Arthur"]) } } + + func testFetchAlongside() { + assertNoError { + let dbQueue = try makeDatabaseQueue() + let controller = FetchedRecordsController(dbQueue, request: Person.order(SQLColumn("id")), compareRecordsByPrimaryKey: true) + let recorder = ChangesRecorder() + controller.trackChanges( + fetchAlongside: { db in Person.fetchCount(db) }, + recordsWillChange: { (controller, count) in recorder.controllerWillChange(controller, count: count) }, + recordsDidChange: { (controller, count) in recorder.controllerDidChange(controller, count: count) }) + controller.performFetch() + + // First insert + recorder.transactionExpectation = expectation(withDescription: "expectation") + try dbQueue.inTransaction { db in + try synchronizePersons(db, [ + Person(id: 1, name: "Arthur")]) + return .commit + } + waitForExpectations(withTimeout: 1, handler: nil) + + XCTAssertEqual(recorder.recordsBeforeChanges.count, 0) + XCTAssertEqual(recorder.recordsAfterChanges.count, 1) + XCTAssertEqual(recorder.recordsAfterChanges.map { $0.name }, ["Arthur"]) + XCTAssertEqual(recorder.countBeforeChanges!, 1) + XCTAssertEqual(recorder.countAfterChanges!, 1) + + // Second insert + recorder.transactionExpectation = expectation(withDescription: "expectation") + try dbQueue.inTransaction { db in + try synchronizePersons(db, [ + Person(id: 1, name: "Arthur"), + Person(id: 2, name: "Barbara")]) + return .commit + } + waitForExpectations(withTimeout: 1, handler: nil) + + XCTAssertEqual(recorder.recordsBeforeChanges.count, 1) + XCTAssertEqual(recorder.recordsBeforeChanges.map { $0.name }, ["Arthur"]) + XCTAssertEqual(recorder.recordsAfterChanges.count, 2) + XCTAssertEqual(recorder.recordsAfterChanges.map { $0.name }, ["Arthur", "Barbara"]) + XCTAssertEqual(recorder.countBeforeChanges!, 2) + XCTAssertEqual(recorder.countAfterChanges!, 2) + } + } }