-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[bug] use single-quotes for string literals in sqlite queries #5419
Closed
Conversation
This file contains 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
amonks
force-pushed
the
amonks/fix-single-quotes
branch
from
September 13, 2024 04:44
96016f8
to
c716905
Compare
Historically, sqlite accepts double-quoted string literals, which is in contravention of the sql standard (which says single quotes should be used for string literals, and double quotes for identifiers like column names). The sqlite authors consider this a misfeature, and are making efforts to change it: - Since sqlite 3.27.0 (2019-02-07), using double-quotes for a string literal causes a warning to be printed to the error log. - Since sqlite 3.29.0 (2019-07-10), the sqlite authors recommend compiling sqlite with the -DSQLITE_DQS=0 option, which causes use of double quotes for string literals to be an error. More details here: https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted My sqlite is compiled with this recommended option, so prior to this change, running, eg, `beet ls`, produced this error: Traceback (most recent call last): File "/usr/local/bin/beet", line 33, in <module> sys.exit(load_entry_point('beets==1.6.0', 'console_scripts', 'beet')()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/beets/ui/__init__.py", line 1285, in main _raw_main(args) File "/usr/local/lib/python3.11/site-packages/beets/ui/__init__.py", line 1272, in _raw_main subcommand.func(lib, suboptions, subargs) File "/usr/local/lib/python3.11/site-packages/beets/ui/commands.py", line 1089, in list_func list_items(lib, decargs(args), opts.album) File "/usr/local/lib/python3.11/site-packages/beets/ui/commands.py", line 1084, in list_items for item in lib.items(query): ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/beets/library.py", line 1529, in items return self._fetch(Item, query, sort or self.get_default_item_sort()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/beets/library.py", line 1503, in _fetch return super()._fetch( ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/beets/dbcore/db.py", line 1094, in _fetch rows = tx.query(sql, subvals) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/beets/dbcore/db.py", line 859, in query cursor = self.db._connection().execute(statement, subvals) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sqlite3.OperationalError: no such column: "" - should this be a string literal in single-quotes? Making the appropriate change to library.py allowed `beet ls` to continue to this error: Traceback (most recent call last): File "/usr/local/bin/beet", line 33, in <module> sys.exit(load_entry_point('beets==1.6.0', 'console_scripts', 'beet')()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/beets/ui/__init__.py", line 1285, in main _raw_main(args) File "/usr/local/lib/python3.11/site-packages/beets/ui/__init__.py", line 1272, in _raw_main subcommand.func(lib, suboptions, subargs) File "/usr/local/lib/python3.11/site-packages/beets/ui/commands.py", line 1089, in list_func list_items(lib, decargs(args), opts.album) File "/usr/local/lib/python3.11/site-packages/beets/ui/commands.py", line 1084, in list_items for item in lib.items(query): ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/beets/library.py", line 1529, in items return self._fetch(Item, query, sort or self.get_default_item_sort()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/beets/library.py", line 1503, in _fetch return super()._fetch( ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/beets/dbcore/db.py", line 1093, in _fetch rows = tx.query(sql, subvals) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/beets/dbcore/db.py", line 858, in query cursor = self.db._connection().execute(statement, subvals) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sqlite3.OperationalError: no such column: "text" - should this be a string literal in single-quotes? The change to query.py allowed `beet ls` to succeed. As for testing, I frankly don't think it's worthwhile to build an automated test harness for beets that recompiles sqlite differently. I think it's sufficient in this case to observe that the existing tests pass. I've been running with this patch for 6 months or so, and haven't had any issues.
amonks
force-pushed
the
amonks/fix-single-quotes
branch
from
September 13, 2024 04:49
c716905
to
f821415
Compare
@arogl right you are! I'll close this. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Historically, sqlite accepts double-quoted string literals, which is in contravention of the sql standard (which says single quotes should be used for string literals, and double quotes for identifiers like column names).
The sqlite authors consider this a misfeature, and are making efforts to change it:
More details here: https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted
My sqlite is compiled with this recommended option, so prior to this change, running, eg,
beet ls
, produced this error:Making the appropriate change to library.py allowed
beet ls
to continue to this error:The change to query.py allowed
beet ls
to succeed.As for testing, I frankly don't think it's worthwhile to build an automated test harness for beets that recompiles sqlite differently. I think it's sufficient in this case to observe that the existing tests pass. I've been running with this patch for 6 months or so, and haven't had any issues.
Description
Fixes #X.
(...)
To Do
docs/
to describe it.)docs/changelog.rst
to the bottom of one of the lists near the top of the document.)