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

Don't call sqlite3_config() unless explicitly required to do so #284

Merged
merged 5 commits into from
Dec 13, 2017

Conversation

groue
Copy link
Owner

@groue groue commented Dec 7, 2017

Context

GRDB calls the SQLite sqlite3_config function in order to configure the global error log.

Any call to sqlite3_config must happen before any connection to any database. In other words, changing the SQLite configuration after a connection has been opened is a misuse of SQLite .

Bug

GRDB was calling sqlite3_config() once, before opening its first database connection. But issue #283 has revealed that this GRDB practice could conflict with other pieces of code that also open database connections. When GRDB opens its first connection after another part of the program has already opened a connection, this sqlite3_config() invocation is a misuse.

Fix

This PR fixes this, by only calling sqlite3_config() when the GRDB user configures the error log:

// Invokes sqlite3_config
Database.logError = { (resultCode, message) in
    NSLog("%@", "SQLite error \(resultCode): \(message)")
}

This also mean that the user is now responsible for setting the Database.logError before any other piece of code would open a connection.

@groue
Copy link
Owner Author

groue commented Dec 7, 2017

@gereons, I expect this PR to fix #283. Will you eventually give it a try and confirm that the warning does no longer appear?

@gereons
Copy link

gereons commented Dec 8, 2017

Will do, sure!

@gereons
Copy link

gereons commented Dec 11, 2017

LGTM. Log message is gone, and my app continues to work as intended, I haven't noticed anything unusual.

@groue
Copy link
Owner Author

groue commented Dec 11, 2017

OK @gereons, thanks for your confirmation! I'll see why some test fail on travis, and ship a new version soon after.

@groue groue merged commit 246f368 into master Dec 13, 2017
@groue groue deleted the Issue283 branch December 13, 2017 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants