Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard failure when trying to perform fetchCount or ValueObservation.trackCount on joined query #495

Closed
Marus opened this issue Mar 6, 2019 · 4 comments
Labels

Comments

@Marus
Copy link
Collaborator

Marus commented Mar 6, 2019

What did you do?

Was trying to perform a count observation using a QueryInterfaceRequest that involved a join.

What did you expect to happen?

To get a count that matched the query expressed.

What happened instead?

Crash within the GRDB library at https://github.com/groue/GRDB.swift/blob/v3.6.2/GRDB/QueryInterface/QueryInterfaceQuery.swift#L247

Environment

GRDB flavor(s): (GRDB, GRDBCipher, GRDBCustom?) GRDBCipher
GRDB version: 3.6.2
Installation method: (CocoaPods, SPM, manual?) Manual
Xcode version: 10.1
Swift version: 4.2
Platform(s) running GRDB: iOS
macOS version running Xcode: Mojave 10.14.3

Demo Project

Example from a playground I had setup can be seen at https://pastebin.com/arCtuYm2 - the last query in that playground (line 95) would cause the crash. Variants with explicit aliases for both tables (must explicitly alias both) work correctly (even if it may not be the most standard SQL generated for the count query SELECT COUNT(*) FROM (SELECT * FROM ....) - but the variant without explicit table aliases crashes. Since it looks to be crashing on alias! I expect that behind the scenes you generate implicit TableAlias objects if not explicitly done so and for some reason that doesn't happen (correctly) in count variants.

@groue
Copy link
Owner

groue commented Mar 6, 2019

Hello @Marus,

Bingo, you have found a bug!

I think I have just fixed it in #490, where some tests for fetchCount on joined queries would crash as well. Those are the 5d9fa76 and 7ff2198 commits, on the way to GRDB 4.

This area of the code has changed quite a bit since GRDB 3.6.2. Inner guts of associations will settle eventually, but this is not quite finished yet. So those commits may not be trivial to backport on the master branch.

Yet I expect those commit to be easily backported to the development branch. Do you fancy have a look? If not, please wait a little bit.

@groue groue added the bug label Mar 6, 2019
@Marus
Copy link
Collaborator Author

Marus commented Mar 6, 2019

Will try to have a look on the 4.0 branch soon - was planning to try and take a look at that anyway - in particular at the PR for the SQLCipher upgrade.

@groue
Copy link
Owner

groue commented Mar 6, 2019

The SQLCipher upgrade (#481) is not ready yet. I'm happy @darrenclark is looking at it because I do not always feel comfortable setting up Xcode targets and build phases, and I know he has deployment constraints that will drive him to a robust solution. I'm sure he will ask for support if he needs some.

Beware SQLCipher 4 is not directly compatible with SQLCipher 3. When it is merged in GRDB 4, you may have to migrate your existing databases: https://discuss.zetetic.net/t/upgrading-to-sqlcipher-4/3283

You can switch to the GRDB-4.0 branch today. I didn't release any beta yet, but it is quite stable. All tests pass unless Travis has a hiccup. Breaking changes are not many, and fixits that help the migration are already there. I don't foresee any other important breaking change until GRDB 4 ships.

Meanwhile, you have found an important bug :-)

@groue
Copy link
Owner

groue commented Mar 6, 2019

Superseded by #496

@groue groue closed this as completed Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants