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 specifying PRAGMA values as JDBC url query parameters #14

Merged
merged 4 commits into from
Nov 20, 2014
Merged

Add support for specifying PRAGMA values as JDBC url query parameters #14

merged 4 commits into from
Nov 20, 2014

Conversation

gitblit
Copy link
Collaborator

@gitblit gitblit commented Nov 17, 2014

This adds support for specifying PRAGMA values as JDBC url query parameters which is quite useful for runtime-based settings within an application.

The idea is to extract recognized PRAGMA values from the filename and inject them into the properties object which is used to build SQLiteConfig. The filename is sanitized during extraction so that the underlying DB engine receives just the filename with optional, standard URI parameters.

jdbc:sqlite:file:mytest.db?journal_mode=wal&synchronous=off

@@ -38,10 +41,15 @@
protected final static Map<TransactionMode, String> beginCommandMap =
new HashMap<SQLiteConfig.TransactionMode, String>();

private final static Set<String> pragmaSet = new TreeSet<String>();
Copy link
Owner

Choose a reason for hiding this comment

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

If there is a possibility to allow duplicate parameters in URL, this should be ArrayList. What do you think?

@xerial
Copy link
Owner

xerial commented Nov 19, 2014

Good idea. I added comments for minor improvements.

@gitblit
Copy link
Collaborator Author

gitblit commented Nov 19, 2014

The pragmaSet is there to quickly confirm that an url parameter is a PRAGMA. It doesn't have anything to do with allowing/disallowing pragma duplication.

Url pragmas that are already in the the Properties object are now ignored. For example, getConnection(String, Properties) can override a url-specified pragma by manually settting it into the Properties object. I think this is what other developers would expect. This same mechanism is used to ignore duplicate pragma values in the url. The url parameters are now processed in reverse order to ensure that the last-specified value is used.

All other review points have been addressed.

@xerial
Copy link
Owner

xerial commented Nov 20, 2014

Looks good!

xerial added a commit that referenced this pull request Nov 20, 2014
Add support for specifying PRAGMA values as JDBC url query parameters
@xerial xerial merged commit 6ac2a1c into xerial:master Nov 20, 2014
@gitblit gitblit deleted the pragma_parameters branch November 20, 2014 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants