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

Add support for SQLite Pre-Update Hooks (+ tests) #63

Merged
merged 1 commit into from
Jun 2, 2016
Merged

Add support for SQLite Pre-Update Hooks (+ tests) #63

merged 1 commit into from
Jun 2, 2016

Conversation

swiftlyfalling
Copy link
Collaborator

@swiftlyfalling swiftlyfalling commented Jun 2, 2016

If SQLITE_ENABLE_PREUPDATE_HOOK is defined, and GRDB is built with a custom SQLite library with the functionality (see: GRDBCustomSQLite), enable support for SQLite Pre-Update Hooks and the new willChangeWithEvent callback on TransactionObservers.

willChangeWithEvent provides a DatabasePreUpdateEvent, which contains the same information as DatabaseUpdateEvent, plus:

  • Pre-change/Post-change rowID (instead of just the final rowID in DatabaseEvent)
  • The triggering depth of the row update
  • Pre-change/Post-change DatabaseValues for the columns in the row

As mentioned in the comments, the requirements are:
SQLite 3.13.0+, built with SQLITE_ENABLE_PREUPDATE_HOOK (which can be accomplished using GRDBCustomSQLite).

If SQLITE_ENABLE_PREUPDATE_HOOK is defined, and GRDB is built with a
custom SQLite library with the functionality (see: GRDBCustomSQLite),
enable support for SQLite Pre-Update Hooks and the new
`willChangeWithEvent` callback on TransactionObservers.
@groue
Copy link
Owner

groue commented Jun 2, 2016

This is a blessed day 💝, that's awesome!

Tests ran smoothly after following SQLiteCustom/README.md instructions. You're a xcconfig wizard!

Git ignores the -USER files, and this is an opportunity for regressions because a simple git clone stops testing for pre-update hooks. A thing to remember.

Still, thanks a lot, you're a boon! Now let's write some documentation and we'll have a gorgeous release!!

@groue groue merged commit bf0f9e1 into groue:master Jun 2, 2016
@@ -1381,7 +1381,21 @@ extension Database {
savepointStack.clear()
for observer in transactionObservers.flatMap({ $0.observer }) {
for event in eventsBuffer {
observer.databaseDidChangeWithEvent(event)
if let event = event as? DatabaseEvent {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll refactor those runtime checks.

groue added a commit that referenced this pull request Jun 3, 2016
…ransactionObserver method so that we avoid runtime checks on events type
@groue
Copy link
Owner

groue commented Jun 3, 2016

Refactoring done

@groue
Copy link
Owner

groue commented Jun 5, 2016

This PR has shipped in v0.71.0

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