From a8f04a1ba5390ea7aa4ab2ccec113705c618a07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 4 Jun 2016 18:22:18 +0200 Subject: [PATCH 01/23] GRDBDemoiOS: stress fetched records controller longer, so that we can check what happens when one leaves the table view controller as transactions are still running. Answer: we crash due to [unowned self] references being used after table view controller has been deallocated. --- DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonsViewController.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonsViewController.swift b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonsViewController.swift index 5b9249bad..15f54c1f4 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 { From c9ebb6da00e8bd766885a8fb4eab371b3f279389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 4 Jun 2016 18:24:49 +0200 Subject: [PATCH 02/23] =?UTF-8?q?FetchedRecordsController:=20-=20make=20un?= =?UTF-8?q?owned=20references=20in=20the=20callbacks=20safe,=20as=20long?= =?UTF-8?q?=20as=20the=20unowned=20object=20is=20deallocated=20in=20the=20?= =?UTF-8?q?fetched=20records=20controller=E2=80=99s=20queue=20(usually=20t?= =?UTF-8?q?he=20main=20queue).=20-=20FetchedRecordsController.trackChanges?= =?UTF-8?q?(fetchAlong:=20{=20db=20in=20=E2=80=A6=20},=20=E2=80=A6)=20allo?= =?UTF-8?q?ws=20the=20user=20to=20fetch=20values=20that=20are=20consistent?= =?UTF-8?q?=20with=20the=20fetched=20records.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GRDB/Record/FetchedRecordsController.swift | 540 ++++++++++++++------- TODO.md | 3 +- 2 files changed, 359 insertions(+), 184 deletions(-) diff --git a/GRDB/Record/FetchedRecordsController.swift b/GRDB/Record/FetchedRecordsController.swift index d404c8e36..128eb601f 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.addTransactionObserver(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 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 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.addTransactionObserver(observer) - observer.checkForChangesInDatabase(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 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.addTransactionObserver(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 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.addTransactionObserver(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.checkForChangesInDatabase(db) + databaseWriter.write { _ in + observer.performChangesChecking() } } } // The eventual current database observer private var observer: FetchedRecordsObserver? - - private func stopTrackingChanges() { - observer?.invalidate() - observer = nil - } } @@ -330,29 +436,194 @@ extension FetchedRecordsController where Record: TableMapping { } +// MARK: - FetchedChangesController + +/// 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 tableViewEvent: ((controller: FetchedRecordsController, record: Record, event: TableViewEvent) -> ())? + + 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.isSameItem = isSameItem + self.fetchAlongside = fetchAlongside + self.recordsWillChange = recordsWillChange + self.tableViewEvent = tableViewEvent + self.recordsDidChange = recordsDidChange + } + #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 + } + #endif + + // Precondition: this method must be called from the database writer's + // serialized dispatch queue. + 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. + // + // This method is called from the database writer's serialized queue, so + // that we can fetch items before other writes have the opportunity to + // modify the database. + // + // However, we don't have to block the writer queue for all the duration + // of the fetch. We just need to block the writer queue until we can + // perform a fetch in isolation. This is the role of the readFromWrite + // method (see below). + // + // However, our fetch will last for an unknown duration. And since we + // release the writer queue early, the next database modification will + // triggers this callback while our fetch is, maybe, still running. This + // next callback will also perform its own fetch, that will maybe end + // before our own fetch. + // + // We have to make sure that our fetch is processed *before* the next + // fetch: let's immediately dispatch the processing task in our + // serialized FIFO queue, but have it wait for our fetch to complete, + // with a semaphore: + let semaphore = dispatch_semaphore_create(0) + var fetchedItems: [Item]! = nil + var fetchedAlongside: T! = nil + + databaseWriter.readFromWrite { db in + fetchedItems = Item.fetchAll(db, request) + fetchedAlongside = self.fetchAlongside(db) + + // Fetch is complete: + dispatch_semaphore_signal(semaphore) + } + + + // Process the fetched items + + 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) + + // 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 self.tableViewEvent != nil { + // Compute table view changes + 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 != 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 != strongObserver.items.count || zip(fetchedItems, strongObserver.items).any({ (fetchedItem, item) in fetchedItem.row != item.row }) else { + return + } + #endif + + // Ready for next check + strongObserver.items = fetchedItems + + 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 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 + + if let recordsDidChange = self.recordsDidChange { + recordsDidChange(controller: controller, fetchedAlongside: fetchedAlongside) + } + } + } + } +} + + // MARK: - FetchedRecordsObserver /// FetchedRecordsController adopts TransactionObserverType so that it can /// monitor changes to its fetched records. private final class FetchedRecordsObserver : TransactionObserverType { - weak var controller: FetchedRecordsController? // If nil, self is invalidated. + var isValid: Bool let observedTables: Set - let isSameItem: (Item, Item) -> Bool var needsComputeChanges: Bool - var items: [Item] + 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(controller: FetchedRecordsController, initialItems: [Item], observedTables: Set, isSameItem: (Item, Item) -> Bool) { - self.controller = controller - self.items = initialItems + init(observedTables: Set, checkForChanges: (FetchedRecordsObserver) -> ()) { + self.isValid = true + self.items = nil self.observedTables = observedTables - self.isSameItem = isSameItem self.needsComputeChanges = false self.queue = dispatch_queue_create("GRDB.FetchedRecordsObserver", DISPATCH_QUEUE_SERIAL) + self.checkForChanges = checkForChanges } func invalidate() { - controller = nil + isValid = false } #if SQLITE_ENABLE_PREUPDATE_HOOK @@ -385,104 +656,13 @@ private final class FetchedRecordsObserver : Transaction guard needsComputeChanges else { return } needsComputeChanges = false - checkForChangesInDatabase(db) + performChangesChecking() } // Precondition: this method must be called from the database writer's // serialized dispatch queue. - func checkForChangesInDatabase(db: Database) { - // Invalidated? - guard let controller = self.controller else { return } - - // Fetch items. - // - // This method is called from the database writer's serialized queue, so - // that we can fetch items before other writes have the opportunity to - // modify the database. - // - // However, we don't have to block the writer queue for all the duration - // of the fetch. We just need to block the writer queue until we can - // perform a fetch in isolation. This is the role of the readFromWrite - // method (see below). - // - // However, our fetch will last for an unknown duration. And since we - // release the writer queue early, the next database modification will - // triggers this callback while our fetch is, maybe, still running. This - // next callback will also perform its own fetch, that will maybe end - // before our own fetch. - // - // We have to make sure that our fetch is processed *before* the next - // fetch: let's immediately dispatch the processing task in our - // serialized FIFO queue, but have it wait for our fetch to complete, - // with a semaphore: - let semaphore = dispatch_semaphore_create(0) - var fetchedItems: [Item]! = nil - - controller.databaseWriter.readFromWrite { db in - fetchedItems = Item.fetchAll(db, controller.request) - - // Fetch is complete: - dispatch_semaphore_signal(semaphore) - } - - - // Process the fetched items - - dispatch_async(queue) { - // Wait for the fetch to complete: - dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER) - assert(fetchedItems != nil) - - // Invalidated? - guard let controller = self.controller else { return } - - // Changes? - #if os(iOS) - let tableViewChanges: [TableViewChange]? - if controller.tableViewEventCallback != nil { - // Compute table view changes - let changes = self.computeTableViewChanges(from: self.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 { - 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 { - return - } - #endif - - // Ready for next check - self.items = fetchedItems - - dispatch_async(controller.queue) { - // Invalidated? - 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) - } - } - #endif - controller.didChangeCallback?(controller) - } else { - controller.stopTrackingChanges() - } - } - } + func performChangesChecking() { + checkForChanges(self) } } @@ -531,11 +711,11 @@ private final class FetchedRecordsObserver : Transaction guard let fetchedItems = fetchedItems, let index = fetchedItems.indexOf({ 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.enumerate() { - 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.enumerate() { - 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(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/TODO.md b/TODO.md index 7758e08e9..3d6451cfc 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,5 @@ -- [ ] 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. +- [X] 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. +- [ ] Document FetchedRecordsController.trackChanges(fetchAlong: { db in ... }, ...) - [ ] 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 From adc3f6d1849eef1fbe76e1108368eb873e1cffd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 4 Jun 2016 18:41:07 +0200 Subject: [PATCH 03/23] TODO.md --- TODO.md | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO.md b/TODO.md index 3d6451cfc..deef05d42 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,6 @@ - [X] 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. - [ ] Document FetchedRecordsController.trackChanges(fetchAlong: { db in ... }, ...) +- [ ] Document when it is safe to use unowned references in a FetchedRecordsController's callbacks (answer: when the reference is deallocated from the controller's queue - usually the main queue) - [ ] 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 From 280955801c90c27ccc04125521f7bc4255026a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 4 Jun 2016 18:41:11 +0200 Subject: [PATCH 04/23] CHANGELOG.md --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf6e2efb7..faa5cbf63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,19 @@ Release Notes ============= +## Next Release + +**Fixed** + +- Fix a crash that would sometimes happen when a FetchedRecordsController's callbacks avoid retain cycles by capturing unowned references. + +**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. 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. + + ## 0.70.1 Released May 30, 2016 From aa5c6283a74c13cec3b3a3b171d3f0d2c2320d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 4 Jun 2016 19:09:51 +0200 Subject: [PATCH 05/23] #68: document NSNumber limits --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 837ce5e02..f5bc879ef 100644 --- a/README.md +++ b/README.md @@ -955,7 +955,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: From a5760a7462780bcd7c147e025023cb01695fb7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 5 Jun 2016 12:16:37 +0200 Subject: [PATCH 06/23] =?UTF-8?q?#68:=20NSNumber.databaseValue=20raises=20?= =?UTF-8?q?explicit=20fatal=20error=20when=20value=20doesn=E2=80=99t=20fit?= =?UTF-8?q?=20Int64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GRDB/Core/Support/Foundation/NSNumber.swift | 8 +- .../NSNumberTests.swift | 103 +++++++++++++----- 2 files changed, 79 insertions(+), 32 deletions(-) diff --git a/GRDB/Core/Support/Foundation/NSNumber.swift b/GRDB/Core/Support/Foundation/NSNumber.swift index 70ef3401f..2bc78fe37 100644 --- a/GRDB/Core/Support/Foundation/NSNumber.swift +++ b/GRDB/Core/Support/Foundation/NSNumber.swift @@ -21,11 +21,15 @@ extension NSNumber: DatabaseValueConvertible { case "l": return Int64(longValue).databaseValue case "L": - return Int64(unsignedLongValue).databaseValue + let uint = unsignedLongValue + GRDBPrecondition(UInt64(uint) <= UInt64(Int64.max), "value can not be converted to Int64 because it is greater than Int64.max") + return Int64(uint).databaseValue case "q": return Int64(longLongValue).databaseValue case "Q": - return Int64(unsignedLongLongValue).databaseValue + let uint64 = unsignedLongLongValue + GRDBPrecondition(uint64 <= UInt64(Int64.max), "value can not be converted to Int64 because it is greater than Int64.max") + return Int64(uint64).databaseValue case "f": return Double(floatValue).databaseValue case "d": diff --git a/Tests/Public/Core/DatabaseValueConvertible/NSNumberTests.swift b/Tests/Public/Core/DatabaseValueConvertible/NSNumberTests.swift index 0dfc9223b..176007983 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(char: Int8.min + 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_char), Int64(Int8.min + 1)) + let number_char = NSNumber(char: Int8.min + 1) + XCTAssertEqual(String.fromCString(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(unsignedChar: UInt8.max - 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_unsignedChar), Int64(UInt8.max - 1)) + let number_unsignedChar = NSNumber(unsignedChar: UInt8.max - 1) +// XCTAssertEqual(String.fromCString(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(short: Int16.min + 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_short), Int64(Int16.min + 1)) + let number_short = NSNumber(short: Int16.min + 1) + XCTAssertEqual(String.fromCString(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(unsignedShort: UInt16.max - 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_unsignedShort), Int64(UInt16.max - 1)) + let number_unsignedShort = NSNumber(unsignedShort: UInt16.max - 1) +// XCTAssertEqual(String.fromCString(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(int: Int32.min + 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_int), Int64(Int32.min + 1)) + let number_int = NSNumber(int: Int32.min + 1) + XCTAssertEqual(String.fromCString(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(unsignedInt: UInt32.max - 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_unsignedInt), Int64(UInt32.max - 1)) + let number_unsignedInt = NSNumber(unsignedInt: UInt32.max - 1) +// XCTAssertEqual(String.fromCString(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(long: Int.min + 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_long), Int64(Int.min + 1)) + let number_long = NSNumber(long: Int.min + 1) +// XCTAssertEqual(String.fromCString(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(unsignedLong: UInt(UInt32.max)) +// XCTAssertEqual(String.fromCString(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(unsignedLong: UInt.max - 1).databaseValue + // case "q": - let number_longLong = NSNumber(longLong: Int64.min + 1).databaseValue - XCTAssertEqual(Int64.fromDatabaseValue(number_longLong), Int64(Int64.min + 1)) + let number_longLong = NSNumber(longLong: Int64.min + 1) + XCTAssertEqual(String.fromCString(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(unsignedLongLong: UInt64(Int64.max)) +// XCTAssertEqual(String.fromCString(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(unsignedLongLong: UInt64.max - 1).databaseValue + // case "f": - let number_float = NSNumber(float: Float(3.14159)).databaseValue - XCTAssertEqual(Float.fromDatabaseValue(number_float), Float(3.14159)) + let number_float = NSNumber(float: Float(3.14159)) + XCTAssertEqual(String.fromCString(number_float.objCType)!, "f") + let dbv_float = number_float.databaseValue + XCTAssertEqual(Float.fromDatabaseValue(dbv_float), Float(3.14159)) + // case "d": - let number_double = NSNumber(double: Double(10000000.01)).databaseValue - XCTAssertEqual(Double.fromDatabaseValue(number_double), Double(10000000.01)) + let number_double = NSNumber(double: Double(10000000.01)) + XCTAssertEqual(String.fromCString(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(bool: true).databaseValue - XCTAssertEqual(Bool.fromDatabaseValue(number_bool_true), true) - let number_bool_false = NSNumber(bool: false).databaseValue - XCTAssertEqual(Bool.fromDatabaseValue(number_bool_false), false) + let number_bool_true = NSNumber(bool: true) + XCTAssertEqual(String.fromCString(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(bool: false) + XCTAssertEqual(String.fromCString(number_bool_false.objCType)!, "c") + let dbv_bool_false = number_bool_false.databaseValue + XCTAssertEqual(Bool.fromDatabaseValue(dbv_bool_false), false) } func testNSNumberDatabaseValueRoundTrip() { From 7186c9a3a0cea5c024ae21c49c3677c45b074eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 5 Jun 2016 13:49:47 +0200 Subject: [PATCH 07/23] #68: take care of Int, Int32 and Int64 overflow when converting from database values --- GRDB.xcodeproj/project.pbxproj | 18 +++++ .../StandardLibrary/StandardLibrary.swift | 38 +++++++++- .../NumericOverflowTests.swift | 74 +++++++++++++++++++ 3 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 Tests/Public/Core/DatabaseValueConvertible/NumericOverflowTests.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/Core/Support/StandardLibrary/StandardLibrary.swift b/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift index 2fe58cef2..1c6d7c3f6 100644 --- a/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift +++ b/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift @@ -108,7 +108,10 @@ 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), "value cannot be converted to Int because it is less than Int.min") + GRDBPrecondition(int64 <= Int64(Int.max), "value can not be converted to Int because it is greater than Int.max") + self = Int(int64) } /// Returns a value that can be stored in the database. @@ -120,9 +123,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 +152,10 @@ 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), "value cannot be converted to Int32 because it is less than Int32.min") + GRDBPrecondition(int64 <= Int64(Int32.max), "value can not be converted to Int32 because it is greater than Int32.max") + self = Int32(int64) } /// Returns a value that can be stored in the database. @@ -150,9 +167,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 +210,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/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) + } + } + +} From 7b492fe7ed710457ee5fe73036b2a4ebce538a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 5 Jun 2016 13:52:46 +0200 Subject: [PATCH 08/23] CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index faa5cbf63..82199f01f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Release Notes **Fixed** - Fix a crash that would sometimes happen when a FetchedRecordsController's callbacks avoid retain cycles by capturing unowned references. +- Robust handling of numeric overflows. Fixes [#68](https://github.com/groue/GRDB.swift/issues/68). **New** From 30864a16a2f00cad4a56835c942cbd8690a4fa5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 5 Jun 2016 14:02:28 +0200 Subject: [PATCH 09/23] #68: numeric overflow error messages contain the faulty value --- GRDB/Core/Support/Foundation/NSNumber.swift | 4 ++-- GRDB/Core/Support/StandardLibrary/StandardLibrary.swift | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/GRDB/Core/Support/Foundation/NSNumber.swift b/GRDB/Core/Support/Foundation/NSNumber.swift index 2bc78fe37..a694dc3f9 100644 --- a/GRDB/Core/Support/Foundation/NSNumber.swift +++ b/GRDB/Core/Support/Foundation/NSNumber.swift @@ -22,13 +22,13 @@ extension NSNumber: DatabaseValueConvertible { return Int64(longValue).databaseValue case "L": let uint = unsignedLongValue - GRDBPrecondition(UInt64(uint) <= UInt64(Int64.max), "value can not be converted to Int64 because it is greater than Int64.max") + GRDBPrecondition(UInt64(uint) <= UInt64(Int64.max), "could not convert \(uint) to Int64") return Int64(uint).databaseValue case "q": return Int64(longLongValue).databaseValue case "Q": let uint64 = unsignedLongLongValue - GRDBPrecondition(uint64 <= UInt64(Int64.max), "value can not be converted to Int64 because it is greater than Int64.max") + GRDBPrecondition(uint64 <= UInt64(Int64.max), "could not convert \(uint64) to Int64") return Int64(uint64).databaseValue case "f": return Double(floatValue).databaseValue diff --git a/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift b/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift index 1c6d7c3f6..8c56a4511 100644 --- a/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift +++ b/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift @@ -109,8 +109,7 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible { /// - index: The column index. public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) - GRDBPrecondition(int64 >= Int64(Int.min), "value cannot be converted to Int because it is less than Int.min") - GRDBPrecondition(int64 <= Int64(Int.max), "value can not be converted to Int because it is greater than Int.max") + GRDBPrecondition(int64 >= Int64(Int.min) && int64 <= Int64(Int.max), "could not convert \(int64) to Int") self = Int(int64) } @@ -153,8 +152,7 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible { /// - index: The column index. public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) - GRDBPrecondition(int64 >= Int64(Int32.min), "value cannot be converted to Int32 because it is less than Int32.min") - GRDBPrecondition(int64 <= Int64(Int32.max), "value can not be converted to Int32 because it is greater than Int32.max") + GRDBPrecondition(int64 >= Int64(Int32.min) && int64 <= Int64(Int32.max), "could not convert \(int64) to Int32") self = Int32(int64) } From 1d4bff1adde130ef2a1eabad0a247fc1f979822e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 5 Jun 2016 14:57:07 +0200 Subject: [PATCH 10/23] #68: conversion error messages contain the "database" word. --- GRDB/Core/DatabaseValue.swift | 4 ++-- GRDB/Core/Row.swift | 2 +- GRDB/Core/StatementColumnConvertible.swift | 2 +- GRDB/Core/Support/Foundation/NSNumber.swift | 4 ++-- GRDB/Core/Support/StandardLibrary/StandardLibrary.swift | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/GRDB/Core/DatabaseValue.swift b/GRDB/Core/DatabaseValue.swift index f6e6b70c2..1bac1aca1 100644 --- a/GRDB/Core/DatabaseValue.swift +++ b/GRDB/Core/DatabaseValue.swift @@ -88,7 +88,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 } @@ -102,7 +102,7 @@ public struct DatabaseValue { @warn_unused_result 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 034dee9a2..936d7037c 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -385,7 +385,7 @@ extension Row { return impl.databaseValue(atIndex: index).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 2a5a41b8c..5f6b42667 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -72,7 +72,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 a694dc3f9..973edc558 100644 --- a/GRDB/Core/Support/Foundation/NSNumber.swift +++ b/GRDB/Core/Support/Foundation/NSNumber.swift @@ -22,13 +22,13 @@ extension NSNumber: DatabaseValueConvertible { return Int64(longValue).databaseValue case "L": let uint = unsignedLongValue - GRDBPrecondition(UInt64(uint) <= UInt64(Int64.max), "could not convert \(uint) to Int64") + 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(longLongValue).databaseValue case "Q": let uint64 = unsignedLongLongValue - GRDBPrecondition(uint64 <= UInt64(Int64.max), "could not convert \(uint64) to Int64") + 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 diff --git a/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift b/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift index 8c56a4511..da31cb58a 100644 --- a/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift +++ b/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift @@ -109,7 +109,7 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible { /// - index: The column index. public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) - GRDBPrecondition(int64 >= Int64(Int.min) && int64 <= Int64(Int.max), "could not convert \(int64) to Int") + GRDBPrecondition(int64 >= Int64(Int.min) && int64 <= Int64(Int.max), "could not convert database value \(int64) to Int") self = Int(int64) } @@ -152,7 +152,7 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible { /// - index: The column index. public init(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) - GRDBPrecondition(int64 >= Int64(Int32.min) && int64 <= Int64(Int32.max), "could not convert \(int64) to Int32") + GRDBPrecondition(int64 >= Int64(Int32.min) && int64 <= Int64(Int32.max), "could not convert database value \(int64) to Int32") self = Int32(int64) } From 25476f29735dcaefd280df7feeb95b6695ac7342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 5 Jun 2016 15:06:51 +0200 Subject: [PATCH 11/23] Drop the unmaintained GRDBDemoiOS7 app --- CHANGELOG.md | 6 +- .../GRDBDemoiOS7.xcodeproj/project.pbxproj | 590 ------------------ .../contents.xcworkspacedata | 7 - .../GRDBDemoiOS7/AppDatabase.swift | 64 -- .../GRDBDemoiOS7/AppDelegate.swift | 13 - .../AppIcon.appiconset/Contents.json | 38 -- .../Base.lproj/LaunchScreen.storyboard | 27 - .../GRDBDemoiOS7/Base.lproj/Main.storyboard | 190 ------ .../GRDBDemoiOS7-Bridging-Header.h | 14 - DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Info.plist | 40 -- .../GRDBDemoiOS7/GRDBDemoiOS7/Person.swift | 40 -- .../PersonEditionViewController.swift | 61 -- .../GRDBDemoiOS7/PersonsViewController.swift | 85 --- DemoApps/GRDBDemoiOS7/README.md | 18 - GRDB.xcworkspace/contents.xcworkspacedata | 3 - 15 files changed, 5 insertions(+), 1191 deletions(-) delete mode 100644 DemoApps/GRDBDemoiOS7/GRDBDemoiOS7.xcodeproj/project.pbxproj delete mode 100644 DemoApps/GRDBDemoiOS7/GRDBDemoiOS7.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/AppDatabase.swift delete mode 100644 DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/AppDelegate.swift delete mode 100644 DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Assets.xcassets/AppIcon.appiconset/Contents.json delete mode 100644 DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Base.lproj/LaunchScreen.storyboard delete mode 100644 DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Base.lproj/Main.storyboard delete mode 100644 DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/GRDBDemoiOS7-Bridging-Header.h delete mode 100644 DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Info.plist delete mode 100644 DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Person.swift delete mode 100644 DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/PersonEditionViewController.swift delete mode 100644 DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/PersonsViewController.swift delete mode 100644 DemoApps/GRDBDemoiOS7/README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 82199f01f..707c89b54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Release Notes **Fixed** - Fix a crash that would sometimes happen when a FetchedRecordsController's callbacks avoid retain cycles by capturing unowned references. -- Robust handling of numeric overflows. Fixes [#68](https://github.com/groue/GRDB.swift/issues/68). +- Improved handling of numeric overflows. Fixes [#68](https://github.com/groue/GRDB.swift/issues/68). **New** @@ -14,6 +14,10 @@ Release Notes - With a custom SQLite build, transaction observers can observe individual column values in the rows modified by a transaction. 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. +**Breaking Changes** + +- iOS7 is no longer supported. + ## 0.70.1 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/AppDatabase.swift b/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/AppDatabase.swift deleted file mode 100644 index 6b2d82832..000000000 --- a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/AppDatabase.swift +++ /dev/null @@ -1,64 +0,0 @@ -import Foundation - - -// The columns for the GRDB Query Interface -// -// See https://github.com/groue/GRDB.swift/#the-query-interface - -struct Col { - static let id = SQLColumn("id") - static let firstName = SQLColumn("firstName") - static let lastName = SQLColumn("lastName") -} - - -// The shared database queue, stored in a global. -// It is initialized in setupDatabase() - -var dbQueue: DatabaseQueue! - -func setupDatabase() { - - // Connect to the database - // - // See https://github.com/groue/GRDB.swift/#database-queues - - let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first! as NSString - let databasePath = documentsPath.stringByAppendingPathComponent("db.sqlite") - dbQueue = try! DatabaseQueue(path: databasePath) - - - // SQLite does not support Unicode: let's add a custom collation which will - // allow us to sort persons by name. - // - // See https://github.com/groue/GRDB.swift/#string-comparison - - let collation = DatabaseCollation("localized_case_insensitive") { (lhs, rhs) in - return (lhs as NSString).localizedCaseInsensitiveCompare(rhs) - } - - dbQueue.inDatabase { db in - db.addCollation(collation) - } - - - // Use DatabaseMigrator to setup the database - // - // See https://github.com/groue/GRDB.swift/#migrations - - var migrator = DatabaseMigrator() - migrator.registerMigration("createPersons") { db in - try db.execute( - "CREATE TABLE persons (" + - "id INTEGER PRIMARY KEY, " + - "firstName TEXT COLLATE localized_case_insensitive, " + - "lastName TEXT COLLATE localized_case_insensitive" + - ")") - } - migrator.registerMigration("addPersons") { db in - try Person(firstName: "Arthur", lastName: "Miller").insert(db) - try Person(firstName: "Barbra", lastName: "Streisand").insert(db) - try Person(firstName: "Cinderella").insert(db) - } - try! migrator.migrate(dbQueue) -} \ No newline at end of file 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/GRDBDemoiOS7/Person.swift b/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Person.swift deleted file mode 100644 index b6e2ef5f0..000000000 --- a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/Person.swift +++ /dev/null @@ -1,40 +0,0 @@ -class Person : Record { - var id: Int64! - var firstName: String? - var lastName: String? - var fullName: String { - return [firstName, lastName].flatMap { $0 }.filter { !$0.isEmpty }.joinWithSeparator(" ") - } - - init(firstName: String? = nil, lastName: String? = nil) { - self.firstName = firstName - self.lastName = lastName - super.init() - } - - - // MARK: - Record - - override class func databaseTableName() -> String { - return "persons" - } - - required init(_ row: Row) { - id = row.value(named: "id") - firstName = row.value(named: "firstName") - lastName = row.value(named: "lastName") - super.init(row) - - } - - override var persistentDictionary: [String: DatabaseValueConvertible?] { - return [ - "id": id, - "firstName": firstName, - "lastName": lastName] - } - - override func didInsertWithRowID(rowID: Int64, forColumn column: String?) { - id = rowID - } -} diff --git a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/PersonEditionViewController.swift b/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/PersonEditionViewController.swift deleted file mode 100644 index 2d45d20af..000000000 --- a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/PersonEditionViewController.swift +++ /dev/null @@ -1,61 +0,0 @@ -import UIKit - -class PersonEditionViewController: UITableViewController, UITextFieldDelegate { - @IBOutlet weak var firstNameTableViewCell: UITableViewCell! - @IBOutlet weak var firstNameTextField: UITextField! - @IBOutlet weak var lastNameTableViewCell: UITableViewCell! - @IBOutlet weak var lastNameTextField: UITextField! - - // The edited person - var person: Person! - - override func viewDidLoad() { - super.viewDidLoad() - - // Initializes textFields with the person's names - firstNameTextField.text = person.firstName - lastNameTextField.text = person.lastName - } - - override func viewWillAppear(animated: Bool) { - super.viewWillAppear(animated) - - // Auto focus firstName - firstNameTextField.becomeFirstResponder() - } - - override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { - // Tapping a cell selects its text fields. - if indexPath == tableView.indexPathForCell(firstNameTableViewCell) { - firstNameTextField.becomeFirstResponder() - } else if indexPath == tableView.indexPathForCell(lastNameTableViewCell) { - lastNameTextField.becomeFirstResponder() - } - } - - func textFieldShouldReturn(textField: UITextField) -> Bool { - // Tapping Return key focuses next text field. - if textField == firstNameTextField { - lastNameTextField.becomeFirstResponder() - } else { - textField.resignFirstResponder() - } - return false - } - - func textFieldDidEndEditing(textField: UITextField) { - // Update person when text field ends editing. - if textField == firstNameTextField { - person.firstName = textField.text - } else if textField == lastNameTextField { - person.lastName = textField.text - } - } - - override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { - // About to cancel or commit: end editing. - // This dismisses the keyboard early, and apply pending changes through - // textFieldDidEndEditing(_). - view.endEditing(true) - } -} diff --git a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/PersonsViewController.swift b/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/PersonsViewController.swift deleted file mode 100644 index 4882240ed..000000000 --- a/DemoApps/GRDBDemoiOS7/GRDBDemoiOS7/PersonsViewController.swift +++ /dev/null @@ -1,85 +0,0 @@ -import UIKit - -class PersonsViewController: UITableViewController { - var persons: [Person] = [] - - override func viewWillAppear(animated: Bool) { - // Reload persons, and the tableView - reloadPersons() - tableView.reloadData() - - self.navigationItem.leftBarButtonItem = self.editButtonItem() - super.viewWillAppear(animated) - } - - func reloadPersons() { - persons = dbQueue.inDatabase { db in - Person.order(Col.firstName, Col.lastName).fetchAll(db) - } - } - - - // MARK: - Segues - - override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { - if segue.identifier == "editNewPerson" { - let personEditionViewController = (segue.destinationViewController as! UINavigationController).topViewController as! PersonEditionViewController - personEditionViewController.person = Person() - } - } - - // Unwind action: commit person edition - @IBAction func commitPersonEdition(segue: UIStoryboardSegue) { - let personEditionViewController = segue.sourceViewController as! PersonEditionViewController - let person = personEditionViewController.person - - // Ignore person with no name - guard (person.firstName ?? "").characters.count > 0 || (person.lastName ?? "").characters.count > 0 else { - return - } - - // Save person - try! dbQueue.inDatabase { db in - try person.save(db) - } - - // Reload persons, and insert a cell. - reloadPersons() - let index = persons.indexOf { $0.id == person.id }! - tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: index, inSection: 0)], withRowAnimation: .Automatic) - } - - - // MARK: - Table View - - override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return persons.count - } - - override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) - - let person = persons[indexPath.row] - cell.textLabel!.text = person.fullName - cell.selectionStyle = .None - return cell - } - - override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { - // Delete the person - let person = persons[indexPath.row] - try! dbQueue.inTransaction { db in - try person.delete(db) - return .Commit - } - persons.removeAtIndex(indexPath.row) - tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic) - } - - override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { - tableView.deselectRowAtIndexPath(indexPath, animated: true) - } - - -} - 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.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 @@ - - From f92d433a3ea73c43f6f25912050a1497ad5032c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 5 Jun 2016 15:35:05 +0200 Subject: [PATCH 12/23] Test for FetchedRecordsController.trackChanges(fetchAlongside:) --- .../FetchedRecordsControllerTests.swift | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/Tests/Public/FetchedRecordsController/FetchedRecordsControllerTests.swift b/Tests/Public/FetchedRecordsController/FetchedRecordsControllerTests.swift index 09a7e6952..957fe8cf4 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 = expectationWithDescription("expectation") + try dbQueue.inTransaction { db in + try synchronizePersons(db, [ + Person(id: 1, name: "Arthur")]) + return .Commit + } + waitForExpectationsWithTimeout(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 = expectationWithDescription("expectation") + try dbQueue.inTransaction { db in + try synchronizePersons(db, [ + Person(id: 1, name: "Arthur"), + Person(id: 2, name: "Barbara")]) + return .Commit + } + waitForExpectationsWithTimeout(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) + } + } } From 01bf13189c854cebbfa5078b061223e77210ef14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 5 Jun 2016 15:59:41 +0200 Subject: [PATCH 13/23] Documentation --- CHANGELOG.md | 6 ++++-- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++------- TODO.md | 2 +- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 707c89b54..1ba2bb7b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,13 @@ Release Notes - 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. 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. +- 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** diff --git a/README.md b/README.md index f5bc879ef..3050e80d4 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: @@ -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. @@ -196,6 +192,8 @@ use_frameworks! pod 'GRDB.swift', '~> 0.70.1' ``` +> :point_up: **Note**: [SQLCipher](#encryption) and [custom SQLite builds](#custom-sqlite-builds) are not available via CocoaPods. + #### Carthage @@ -207,6 +205,8 @@ To use GRDB with Carthage, specify in your Cartfile: github "groue/GRDB.swift" ~> 0.70.1 ``` +> :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 ==================== @@ -2629,6 +2634,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 of its properties. + func databaseWillChangeWithEvent(event: DatabasePreUpdateEvent) + #endif +} +``` + + ## FetchedRecordsController **You use FetchedRecordsController to track changes in the results of an SQLite request.** @@ -2741,7 +2765,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] } ``` @@ -2772,6 +2796,27 @@ 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. +**Changes notified in callbacks may not reflect the current database state.** This is because after a transaction has committed, and before the fetched records controller had the opportunity to notify changes in the main thread, other database transactions can modify the database. + +*This means that values fetched from inside the controller's callbacks may be inconsistent with the controller's records.* + +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. @@ -3330,7 +3375,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) diff --git a/TODO.md b/TODO.md index deef05d42..90032c8a7 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,5 @@ - [X] 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. -- [ ] Document FetchedRecordsController.trackChanges(fetchAlong: { db in ... }, ...) +- [X] Document FetchedRecordsController.trackChanges(fetchAlongside: { db in ... }, ...) - [ ] Document when it is safe to use unowned references in a FetchedRecordsController's callbacks (answer: when the reference is deallocated from the controller's queue - usually the main queue) - [ ] 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 From 2c885cb347821493ceb9dd5e32747c8e473864c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 5 Jun 2016 16:03:40 +0200 Subject: [PATCH 14/23] Document when it is safe to use unowned references in a FetchedRecordsController's callbacks --- README.md | 2 ++ TODO.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3050e80d4..ad9c8a3d4 100644 --- a/README.md +++ b/README.md @@ -2930,6 +2930,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 diff --git a/TODO.md b/TODO.md index 90032c8a7..e2b00f45d 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,6 @@ - [X] 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. - [X] Document FetchedRecordsController.trackChanges(fetchAlongside: { db in ... }, ...) -- [ ] Document when it is safe to use unowned references in a FetchedRecordsController's callbacks (answer: when the reference is deallocated from the controller's queue - usually the main queue) +- [X] Document when it is safe to use unowned references in a FetchedRecordsController's callbacks (answer: when the reference is deallocated from the controller's queue - usually the main queue) - [ ] 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 From d0382279413a572d896aa98ae69e7b3ee58e5603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 5 Jun 2016 16:43:00 +0200 Subject: [PATCH 15/23] =?UTF-8?q?#62:=20Don=E2=80=99t=20share=20GRDBCustom?= =?UTF-8?q?SQLite=20schemes=20(avoid=20messing=20with=20Carthage)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcschemes/GRDBCustomSQLiteOSX.xcscheme | 99 --------------- .../xcschemes/GRDBCustomSQLiteiOS.xcscheme | 113 ------------------ 2 files changed, 212 deletions(-) delete mode 100644 GRDB.xcodeproj/xcshareddata/xcschemes/GRDBCustomSQLiteOSX.xcscheme delete mode 100644 GRDB.xcodeproj/xcshareddata/xcschemes/GRDBCustomSQLiteiOS.xcscheme 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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 9376f048be1355e9844a4218550a25e5bd920fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 5 Jun 2016 16:45:27 +0200 Subject: [PATCH 16/23] TODO.md --- TODO.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/TODO.md b/TODO.md index e2b00f45d..49aa56935 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,3 @@ -- [X] 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. -- [X] Document FetchedRecordsController.trackChanges(fetchAlongside: { db in ... }, ...) -- [X] Document when it is safe to use unowned references in a FetchedRecordsController's callbacks (answer: when the reference is deallocated from the controller's queue - usually the main queue) - [ ] 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 From 4558321ef7ccd5524ce16ca350602356f25bd158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 5 Jun 2016 16:45:34 +0200 Subject: [PATCH 17/23] v0.71.0 --- CHANGELOG.md | 4 +++- GRDB.swift.podspec | 2 +- README.md | 14 +++++++------- Support/Info.plist | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ba2bb7b2..032d67986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ Release Notes ============= -## Next Release +## 0.71.0 + +Released June 5, 2016 **Fixed** 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/README.md b/README.md index ad9c8a3d4..6adf72130 100644 --- a/README.md +++ b/README.md @@ -25,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+ @@ -143,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** @@ -189,7 +189,7 @@ 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. @@ -202,7 +202,7 @@ 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. @@ -311,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 @@ -391,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. @@ -3281,7 +3281,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: 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 From cb2dda84215c1bd4bb0f186af6db88ae06f77390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 6 Jun 2016 07:47:07 +0200 Subject: [PATCH 18/23] README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 6adf72130..f539321e3 100644 --- a/README.md +++ b/README.md @@ -2796,9 +2796,7 @@ 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. -**Changes notified in callbacks may not reflect the current database state.** This is because after a transaction has committed, and before the fetched records controller had the opportunity to notify changes in the main thread, other database transactions can modify the database. - -*This means that values fetched from inside the controller's callbacks may be inconsistent with the controller's records.* +**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: From c229439decd00aa3aad2ef807e80bf215450f27e Mon Sep 17 00:00:00 2001 From: Steven Schveighoffer Date: Mon, 6 Jun 2016 15:13:42 -0400 Subject: [PATCH 19/23] Add description of rollback without throwing error --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f539321e3..1290da824 100644 --- a/README.md +++ b/README.md @@ -1060,7 +1060,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. +The transaction is rollbacked if an error is thrown within the transaction body, and that error is rethrown by the inTransaction method. If you return `TransactionCompletion.Rollback` from your closure, the transaction is also rolled back, but no error is thrown. If you want to insert a transaction between other database statements, you can use the Database.inTransaction() function: From d4c7e00a19e155251ffc8043729e28160be462a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 7 Jun 2016 07:58:55 +0200 Subject: [PATCH 20/23] README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1290da824..4f6340e1e 100644 --- a/README.md +++ b/README.md @@ -1060,7 +1060,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 you return `TransactionCompletion.Rollback` from your closure, the transaction is also rolled back, but no error is thrown. +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: @@ -1113,7 +1113,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: @@ -3387,6 +3387,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. From 93755a62aaf98e473ec5cf95a2ecbc4e5d6e640c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 7 Jun 2016 09:01:27 +0200 Subject: [PATCH 21/23] Typo --- DemoApps/GRDBDemoiOS/GRDBDemoiOS/Database.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Database.swift b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Database.swift index f0e4bcb81..66bc07861 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 (" + From 8058a79ed05afcfe974fb3776d831512dda54c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 7 Jun 2016 09:07:42 +0200 Subject: [PATCH 22/23] README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f6340e1e..4cfda15c4 100644 --- a/README.md +++ b/README.md @@ -1701,7 +1701,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 { From 2833da3b2d62c4e02429adfa650beb03545705db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 7 Jun 2016 09:09:42 +0200 Subject: [PATCH 23/23] README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cfda15c4..eb752b7fd 100644 --- a/README.md +++ b/README.md @@ -2646,7 +2646,7 @@ public protocol TransactionObserverType : class { /// columns). /// /// The event is only valid for the duration of this method call. If you - /// need to keep it longer, store a copy of its properties. + /// need to keep it longer, store a copy: event.copy(). func databaseWillChangeWithEvent(event: DatabasePreUpdateEvent) #endif }