Merge branch 'beetbox:master' into fix_false_positive_ftintitle

This commit is contained in:
Karl-Ludwig Besser 2024-09-30 10:17:19 -05:00 committed by GitHub
commit ab86b2d1e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 15 additions and 14 deletions

View file

@ -237,7 +237,7 @@ There are a few coding conventions we use in beets:
.. code-block:: python
with g.lib.transaction() as tx:
rows = tx.query('SELECT DISTINCT "{0}" FROM "{1}" ORDER BY "{2}"'
rows = tx.query("SELECT DISTINCT '{0}' FROM '{1}' ORDER BY '{2}'"
.format(field, model._table, sort_field))
To fetch Item objects from the database, use lib.items(…) and supply
@ -248,7 +248,7 @@ There are a few coding conventions we use in beets:
.. code-block:: python
with lib.transaction() as tx:
rows = tx.query('SELECT …')
rows = tx.query("SELECT …")
Transaction objects help control concurrent access to the database
and assist in debugging conflicting accesses.

View file

@ -1040,8 +1040,8 @@ class FixedFieldSort(FieldSort):
if self.case_insensitive:
field = (
"(CASE "
'WHEN TYPEOF({0})="text" THEN LOWER({0}) '
'WHEN TYPEOF({0})="blob" THEN LOWER({0}) '
"WHEN TYPEOF({0})='text' THEN LOWER({0}) "
"WHEN TYPEOF({0})='blob' THEN LOWER({0}) "
"ELSE {0} END)".format(self.field)
)
else:

View file

@ -312,11 +312,8 @@ class SmartArtistSort(dbcore.query.Sort):
order = "ASC" if self.ascending else "DESC"
field = "albumartist" if self.album else "artist"
collate = "COLLATE NOCASE" if self.case_insensitive else ""
return (
"(CASE {0}_sort WHEN NULL THEN {0} "
'WHEN "" THEN {0} '
"ELSE {0}_sort END) {1} {2}"
).format(field, collate, order)
return f"COALESCE(NULLIF({field}_sort, ''), {field}) {collate} {order}"
def sort(self, objs):
if self.album:

View file

@ -231,7 +231,7 @@ def _get_unique_table_field_values(model, field, sort_field):
raise KeyError
with g.lib.transaction() as tx:
rows = tx.query(
'SELECT DISTINCT "{}" FROM "{}" ORDER BY "{}"'.format(
"SELECT DISTINCT '{}' FROM '{}' ORDER BY '{}'".format(
field, model._table, sort_field
)
)

View file

@ -42,6 +42,8 @@ Bug fixes:
issues in the future.
:bug:`5289`
* :doc:`plugins/discogs`: Fix the ``TypeError`` when there is no description.
* Remove single quotes from all SQL queries
:bug:`4709`
For packagers:

View file

@ -59,7 +59,7 @@ class StoreTest(ItemInDBTestCase):
self.i.store()
new_year = (
self.lib._connection()
.execute("select year from items where " 'title="the title"')
.execute("select year from items where title = ?", (self.i.title,))
.fetchone()["year"]
)
assert new_year == 1987
@ -70,7 +70,7 @@ class StoreTest(ItemInDBTestCase):
self.i.store()
new_genre = (
self.lib._connection()
.execute("select genre from items where " 'title="the title"')
.execute("select genre from items where title = ?", (self.i.title,))
.fetchone()["genre"]
)
assert new_genre == original_genre
@ -104,7 +104,8 @@ class AddTest(BeetsTestCase):
new_grouping = (
self.lib._connection()
.execute(
"select grouping from items " 'where composer="the composer"'
"select grouping from items where composer = ?",
(self.i.composer,),
)
.fetchone()["grouping"]
)
@ -118,7 +119,8 @@ class AddTest(BeetsTestCase):
new_grouping = (
self.lib._connection()
.execute(
"select grouping from items " 'where composer="the composer"'
"select grouping from items where composer = ?",
(self.i.composer,),
)
.fetchone()["grouping"]
)