From df32c1c5d5b5e5e000d46dd38dd0a48158c91cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 18 Jul 2016 12:57:38 +0200 Subject: [PATCH 1/3] Allow SelectStatement to perform database changes - Fixes #80 and #82 for good. --- GRDB/Core/Database.swift | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index f712b0d5d..500a83516 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -1100,17 +1100,7 @@ final class StatementCompilationObserver { observer.databaseEventKinds.append(.Delete(tableName: String.fromCString(CString1)!)) case SQLITE_UPDATE: let observer = unsafeBitCast(observerPointer, StatementCompilationObserver.self) - let tableName = String.fromCString(CString1)! - - // Ignore all changes to sqlite_master. - // - // The schema changes are already processed by the SQLITE_DROP_TABLE, SQLITE_CREATE_INDEX, etc. (see above). - // - // Plus SQLite will sometimes announce that SELECT statements - // perform changes to sqlite_master. See DatabasePoolConcurrencyTests.testIssue80() - if tableName != "sqlite_master" { - observer.insertUpdateEventKind(tableName: tableName, columnName: String.fromCString(CString2)!) - } + observer.insertUpdateEventKind(tableName: String.fromCString(CString1)!, columnName: String.fromCString(CString2)!) case SQLITE_SAVEPOINT: let observer = unsafeBitCast(observerPointer, StatementCompilationObserver.self) let name = String.fromCString(CString2)! @@ -1411,7 +1401,28 @@ extension Database { static func preconditionValidSelectStatement(sql sql: String, observer: StatementCompilationObserver) { GRDBPrecondition(observer.invalidatesDatabaseSchemaCache == false, "Invalid statement type for query \(String(reflecting: sql)): use UpdateStatement instead.") GRDBPrecondition(observer.savepointAction == nil, "Invalid statement type for query \(String(reflecting: sql)): use UpdateStatement instead.") - GRDBPrecondition(observer.databaseEventKinds.isEmpty, "Invalid statement type for query \(String(reflecting: sql)): use UpdateStatement instead.") + + // Don't check for observer.databaseEventKinds.isEmpty + // + // When observer.databaseEventKinds.isEmpty is NOT empty, this means + // that the database is changed by the statement. + // + // It thus looks like the statement should be performed by an + // UpdateStatement, not a SelectStatement: transaction observers are not + // notified of database changes when they are executed by + // a SelectStatement. + // + // However https://github.com/groue/GRDB.swift/issues/80 and + // https://github.com/groue/GRDB.swift/issues/82 have shown that SELECT + // statements on virtual tables can generate database changes. + // + // :-( + // + // OK, this is getting very difficult to protect the user against + // himself: just give up, and allow SelectStatement to execute database + // changes. We'll cope with eventual troubles later, when they occur. + // + // GRDBPrecondition(observer.databaseEventKinds.isEmpty, "Invalid statement type for query \(String(reflecting: sql)): use UpdateStatement instead.") } func updateStatementWillExecute(statement: UpdateStatement) { From 78327f648d5a550aeb155bb815e0096c744654fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 18 Jul 2016 13:16:36 +0200 Subject: [PATCH 2/3] v0.75.2 --- CHANGELOG.md | 9 +++++++++ GRDB.swift.podspec | 2 +- README.md | 22 +++++++++++----------- Support/Info.plist | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf2dd8ada..50339128e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ Release Notes ============= +## 0.75.2 + +Released July 18, 2016 + +**Fixed** + +- Fixed crashes that could happen when using virtual tables (fixes [#82](https://github.com/groue/GRDB.swift/issues/82)) + + ## 0.75.1 Released July 8, 2016 diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index 81ecef495..35c1acafa 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.75.1' + s.version = '0.75.2' 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 588670bf2..e92eecc82 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ You should give it a try. --- -**July 8, 2016: GRDB.swift 0.75.1 is out** ([changelog](CHANGELOG.md)). Follow [@groue](http://twitter.com/groue) on Twitter for release announcements and usage tips. +**July 18, 2016: GRDB.swift 0.75.2 is out** ([changelog](CHANGELOG.md)). Follow [@groue](http://twitter.com/groue) on Twitter for release announcements and usage tips. **Requirements**: iOS 8.0+ / OSX 10.9+, Xcode 7.3+ @@ -143,7 +143,7 @@ Documentation **Reference** -- [GRDB Reference](http://cocoadocs.org/docsets/GRDB.swift/0.75.1/index.html) (on cocoadocs.org) +- [GRDB Reference](http://cocoadocs.org/docsets/GRDB.swift/0.75.2/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.75.1' +pod 'GRDB.swift', '~> 0.75.2' ``` > :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.75.1' To use GRDB with Carthage, specify in your Cartfile: ``` -github "groue/GRDB.swift" ~> 0.75.1 +github "groue/GRDB.swift" ~> 0.75.2 ``` > :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.75.1/Structs/Configuration.html) for more details. +See [Configuration](http://cocoadocs.org/docsets/GRDB.swift/0.75.2/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.75.1/Structs/Configuration.html) for more details. +See [Configuration](http://cocoadocs.org/docsets/GRDB.swift/0.75.2/Structs/Configuration.html) for more details. Database pools are more memory-hungry than database queues. See [Memory Management](#memory-management) for more information. @@ -1477,10 +1477,10 @@ for person in Person.fetch(db, sql, adapter: adapter) { For more information about row adapters, see the documentation of: -- [RowAdapter](http://cocoadocs.org/docsets/GRDB.swift/0.75.1/Protocols/RowAdapter.html): the protocol that lets you define your custom row adapters -- [ColumnMapping](http://cocoadocs.org/docsets/GRDB.swift/0.75.1/Structs/ColumnMapping.html): a row adapter that renames row columns -- [SuffixRowAdapter](http://cocoadocs.org/docsets/GRDB.swift/0.75.1/Structs/SuffixRowAdapter.html): a row adapter that hides the first columns of a row -- [ScopeAdapter](http://cocoadocs.org/docsets/GRDB.swift/0.75.1/Structs/ScopeAdapter.html): the row adapter that groups several adapters together to define scopes +- [RowAdapter](http://cocoadocs.org/docsets/GRDB.swift/0.75.2/Protocols/RowAdapter.html): the protocol that lets you define your custom row adapters +- [ColumnMapping](http://cocoadocs.org/docsets/GRDB.swift/0.75.2/Structs/ColumnMapping.html): a row adapter that renames row columns +- [SuffixRowAdapter](http://cocoadocs.org/docsets/GRDB.swift/0.75.2/Structs/SuffixRowAdapter.html): a row adapter that hides the first columns of a row +- [ScopeAdapter](http://cocoadocs.org/docsets/GRDB.swift/0.75.2/Structs/ScopeAdapter.html): the row adapter that groups several adapters together to define scopes ## Raw SQLite Pointers @@ -3375,7 +3375,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.75.1/Classes/DatabaseQueue.html) and [DatabasePool](http://cocoadocs.org/docsets/GRDB.swift/0.75.1/Classes/DatabasePool.html). Both adopt the [DatabaseReader](http://cocoadocs.org/docsets/GRDB.swift/0.75.1/Protocols/DatabaseReader.html) and [DatabaseWriter](http://cocoadocs.org/docsets/GRDB.swift/0.75.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.75.2/Classes/DatabaseQueue.html) and [DatabasePool](http://cocoadocs.org/docsets/GRDB.swift/0.75.2/Classes/DatabasePool.html). Both adopt the [DatabaseReader](http://cocoadocs.org/docsets/GRDB.swift/0.75.2/Protocols/DatabaseReader.html) and [DatabaseWriter](http://cocoadocs.org/docsets/GRDB.swift/0.75.2/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 eb90c95cc..dedd45df7 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.75.1 + 0.75.2 CFBundleSignature ???? CFBundleVersion From 09f57d3bb6630443a5d56e1280cee7fcc579c066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 18 Jul 2016 20:58:30 +0200 Subject: [PATCH 3/3] TODO.md --- TODO.md | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO.md b/TODO.md index 309c290d0..235f8a2a3 100644 --- a/TODO.md +++ b/TODO.md @@ -18,6 +18,7 @@ Not sure +- [ ] Issue 85: Consider Django ordering: "Each order_by() call will clear any previous ordering": https://docs.djangoproject.com/en/1.9/ref/models/querysets/#order-by - [ ] Support for NSColor/UIColor. Beware UIColor components can go beyond [0, 1.0] in iOS10.