Skip to content

Commit 4354ba4

Browse files
authored
Merge pull request beetbox#5214 from beetbox/handle-null-path
Handle NULL values in the path column
2 parents 92fb830 + 065f091 commit 4354ba4

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

beets/dbcore/db.py

+15
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from types import TracebackType
3030
from typing import (
3131
Any,
32+
AnyStr,
3233
Callable,
3334
DefaultDict,
3435
Dict,
@@ -1088,8 +1089,22 @@ def regexp(value, pattern):
10881089
value = value.decode()
10891090
return re.search(pattern, str(value)) is not None
10901091

1092+
def bytelower(bytestring: Optional[AnyStr]) -> Optional[AnyStr]:
1093+
"""A custom ``bytelower`` sqlite function so we can compare
1094+
bytestrings in a semi case insensitive fashion.
1095+
1096+
This is to work around sqlite builds are that compiled with
1097+
``-DSQLITE_LIKE_DOESNT_MATCH_BLOBS``. See
1098+
``https://github.com/beetbox/beets/issues/2172`` for details.
1099+
"""
1100+
if bytestring is not None:
1101+
return bytestring.lower()
1102+
1103+
return bytestring
1104+
10911105
conn.create_function("regexp", 2, regexp)
10921106
conn.create_function("unidecode", 1, unidecode)
1107+
conn.create_function("bytelower", 1, bytelower)
10931108

10941109
def _close(self):
10951110
"""Close the all connections to the underlying SQLite database

beets/library.py

-16
Original file line numberDiff line numberDiff line change
@@ -1550,17 +1550,6 @@ def parse_query_string(s, model_cls):
15501550
return parse_query_parts(parts, model_cls)
15511551

15521552

1553-
def _sqlite_bytelower(bytestring):
1554-
"""A custom ``bytelower`` sqlite function so we can compare
1555-
bytestrings in a semi case insensitive fashion.
1556-
1557-
This is to work around sqlite builds are that compiled with
1558-
``-DSQLITE_LIKE_DOESNT_MATCH_BLOBS``. See
1559-
``https://github.com/beetbox/beets/issues/2172`` for details.
1560-
"""
1561-
return bytestring.lower()
1562-
1563-
15641553
# The Library: interface to the database.
15651554

15661555

@@ -1585,11 +1574,6 @@ def __init__(
15851574

15861575
self._memotable = {} # Used for template substitution performance.
15871576

1588-
def _create_connection(self):
1589-
conn = super()._create_connection()
1590-
conn.create_function("bytelower", 1, _sqlite_bytelower)
1591-
return conn
1592-
15931577
# Adding objects to the database.
15941578

15951579
def add(self, obj):

0 commit comments

Comments
 (0)