fix(db): fix support for sqlite3 connector#2009
Merged
jethrokuan merged 1 commit intomasterfrom Dec 21, 2021
Merged
Conversation
Moving the PRAGMA foreign_keys invocation out of the transaction seems to work now.
Member
Author
|
cc @nobiot if you want to confirm :) |
Contributor
|
@jethrokuan |
Contributor
|
See detail of my tests in #1927. |
Contributor
|
@jethrokuan Ubuntu's Sqlite3 package gives me an older version (and has the same issue with the newest) so I compiled from source. |
Contributor
|
Maybe the Widows binary does something special? |
nobiot
added a commit
to nobiot/org-roam
that referenced
this pull request
Dec 27, 2021
This commit is follow-up for PR org-roam#2009 should fix issues org-roam#1927 & org-roam#1910. Currently, `[:pragma (= foreign_keys ON)]` is present only in function `org-roam-db--init`. This means the `foreign_keys` is turned on only when the db file is created for the first time. Subsequent Emacs sessions won't turn it on as the db file is already present and does not evaluate `org-roam-db--init`. This PRAGMA needs to be turned on each database connection at runtime according to sqlite's documentation (https://sqlite.org/foreignkeys.html#fk_enable) ``` Foreign key constraints are disabled by default (for backwards compatibility), so must be enabled separately for each database connection ``` I have observed that on Windows only the Emacs session that initially creates the Org-roam db file works correctly with the `sqlite3` option. Subsequent Emacs sessions have the same "Unique constraint failed" error messages. I have tested this patch on Windows and Ubuntu; both seem to work in the first and subsequent Emacs sessions. I am not 100% sure if the location of the PRAGMA is the best; use it as a proof-of-cocenpt for the fix. Thank you.
jethrokuan
pushed a commit
that referenced
this pull request
Jan 2, 2022
* (fix):db: pragma foreign keys to work with sqlite3 This commit is follow-up for PR #2009 should fix issues #1927 & #1910. Currently, `[:pragma (= foreign_keys ON)]` is present only in function `org-roam-db--init`. This means the `foreign_keys` is turned on only when the db file is created for the first time. Subsequent Emacs sessions won't turn it on as the db file is already present and does not evaluate `org-roam-db--init`. This PRAGMA needs to be turned on each database connection at runtime according to sqlite's documentation (https://sqlite.org/foreignkeys.html#fk_enable) ``` Foreign key constraints are disabled by default (for backwards compatibility), so must be enabled separately for each database connection ``` I have observed that on Windows only the Emacs session that initially creates the Org-roam db file works correctly with the `sqlite3` option. Subsequent Emacs sessions have the same "Unique constraint failed" error messages. I have tested this patch on Windows and Ubuntu; both seem to work in the first and subsequent Emacs sessions. I am not 100% sure if the location of the PRAGMA is the best; use it as a proof-of-cocenpt for the fix. Thank you. * remove: [:pragma (= foreign_keys ON)] from org-roam-db--init * fix: defconst org-roam--sqlite-available-p outputs error When `org-roam-database-connector` is not `sqlite`, it outputs an unnecessary error when Org-roam starts up as `defconst` evaluates `(emacsql-sqlite-ensure-binary)`. ``` Org-roam initialization: (error "No EmacSQL SQLite binary available, aborting") ``` For other database connectors, this is not relevant. * chore: rm org-roam--sqlite-available-p As per our conversation, org-roam--sqlite-available-p not needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Moving the PRAGMA foreign_keys invocation out of the transaction seems
to work now.