mirror of
https://github.com/beetbox/beets.git
synced 2025-12-26 18:43:38 +01:00
Flexible SQL columns have TEXT affinity
Reverts 2314f0f9ff
Also implements handling of text values for the base `Type` and
overwrites in the blob-based `PathType`
This commit is contained in:
parent
a92493cf12
commit
a17e8b54be
3 changed files with 13 additions and 6 deletions
|
|
@ -724,7 +724,7 @@ class Database(object):
|
|||
id INTEGER PRIMARY KEY,
|
||||
entity_id INTEGER,
|
||||
key TEXT,
|
||||
value NONE,
|
||||
value TEXT,
|
||||
UNIQUE(entity_id, key) ON CONFLICT REPLACE);
|
||||
CREATE INDEX IF NOT EXISTS {0}_by_entity
|
||||
ON {0} (entity_id);
|
||||
|
|
|
|||
|
|
@ -93,12 +93,16 @@ class Type(object):
|
|||
http://www.sqlite.org/datatype3.html
|
||||
https://docs.python.org/2/library/sqlite3.html#sqlite-and-python-types
|
||||
|
||||
Flexible fields have the type afinity `NULL`. This means the
|
||||
`sql_value` may be of any type returned by the database adapter.
|
||||
Since the schema might change it is advisable that this method
|
||||
handles all of them.
|
||||
Flexible fields have the type afinity `TEXT`. This means the
|
||||
`sql_value` is either a `buffer` or a `unicode` object` and the
|
||||
method must handle these in addition.
|
||||
"""
|
||||
return self.normalize(sql_value)
|
||||
if isinstance(sql_value, buffer):
|
||||
sql_value = bytes(sql_value).decode('utf8', 'ignore')
|
||||
if isinstance(sql_value, unicode):
|
||||
return self.parse(sql_value)
|
||||
else:
|
||||
return self.normalize(sql_value)
|
||||
|
||||
def to_sql(self, model_value):
|
||||
"""Convert a value as stored in the model object to a value used
|
||||
|
|
|
|||
|
|
@ -108,6 +108,9 @@ class PathType(types.Type):
|
|||
else:
|
||||
return value
|
||||
|
||||
def from_sql(self, sql_value):
|
||||
return self.normalize(sql_value)
|
||||
|
||||
def to_sql(self, value):
|
||||
if isinstance(value, str):
|
||||
value = buffer(value)
|
||||
|
|
|
|||
Loading…
Reference in a new issue