Skip to content

Expose reading errors #148

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

Merged
merged 80 commits into from
Nov 30, 2016
Merged

Expose reading errors #148

merged 80 commits into from
Nov 30, 2016

Conversation

groue
Copy link
Owner

@groue groue commented Nov 28, 2016

This pull request addresses #147 and changes GRDB so that it exposes reading errors.

Until now, GRDB would assume that both SQLite and the database file(s) were fundamentally trustable. Well, the file system is not trustable. Applications have to be able to deal with I/O errors.

The fetching methods have thus been updated:

-Type.fetch(...) -> DatabaseSequence<Type>
-Type.fetchAll(...) -> [Type]
-Type.fetchOne(...) -> Type?
+Type.fetchCursor(...) throws -> DatabaseCursor<Type>
+Type.fetchAll(...) throws -> [Type]
+Type.fetchOne(...) throws -> Type?

Usage:

// Fetch cursors
let rows = try Row.fetchCursor(db, ...) // DatabaseCursor<Row>
while let row = try rows.next() { ... } // Row

// Fetch arrays
let rows = try Row.fetchAll(db, ...)    // [Row]

// Fetch individual values:
let row = try Row.fetchOne(db, ...)     // Row?

groue added 30 commits November 25, 2016 18:34
let cursor = try Row.fetchCursor(db, "SELECT * FROM persons)
while let row = try cursor.step() { ... }
…nce DatabaseCursor.step() has returned nil, all subsequent calls return nil. (addresses #147)
…DatabaseCursor.enumerated since it can't be implemented yet
@groue
Copy link
Owner Author

groue commented Nov 29, 2016

@kdubb, @swiftlyfalling This PR looks ready.

Errors from FetchedRecordsController and DatabaseStorage are not handled yet, but this is not a regression: we can deal with those errors in future PRs. I encourage you to check out the DatabaseCursor branch and evaluate this new version (DatabaseCursor has been merged into master).

See:

@groue groue merged commit 8118f78 into master Nov 30, 2016
@groue
Copy link
Owner Author

groue commented Nov 30, 2016

All right, folks! GRDB v0.91.0 has shipped :-) Thanks again @kdubb for the kick!

@groue groue deleted the DatabaseCursor branch November 30, 2016 19:51
@groue
Copy link
Owner Author

groue commented Dec 21, 2016

@kdubb @swiftlyfalling I'm currently writing an app that needs to properly handle database errors on a locked device. I can not tell you how much GRDB owes to you ❤️

@swiftlyfalling
Copy link
Collaborator

@groue: Yes, that's (unfortunately) an all-too-frequent issue if one wants to support background execution & Data Protection on an iOS device.

These changes are fantastic and make it all possible. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants