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

Match DatabaseError on ResultCode #754

Merged
merged 4 commits into from
Apr 9, 2020
Merged

Match DatabaseError on ResultCode #754

merged 4 commits into from
Apr 9, 2020

Conversation

groue
Copy link
Owner

@groue groue commented Apr 9, 2020

This pull request makes it possible to match database errors on their result code:

do {
    try Player(...).insert(db)
} catch ResultCode.SQLITE_CONSTRAINT_FOREIGNKEY {
    // foreign key constraint error
} catch ResultCode.SQLITE_CONSTRAINT {
    // any other constraint error
} catch {
    // any other database error
}

Edit: further GRDB 5 commits expose the result codes on DatabaseError itself:

do {
    try Player(...).insert(db)
} catch DatabaseError.SQLITE_CONSTRAINT_FOREIGNKEY {
    // foreign key constraint error
} catch DatabaseError.SQLITE_CONSTRAINT {
    // any other constraint error
} catch {
    // any other database error
}

@groue groue added this to the GRDB 5 milestone Apr 9, 2020
@groue groue mentioned this pull request Apr 9, 2020
42 tasks
@groue groue merged commit 65ac210 into GRDB5 Apr 9, 2020
@groue groue deleted the dev/ResultCode-match branch April 9, 2020 18:42
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.

None yet

1 participant