diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index b2d2df360..2927186b4 100644 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -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); diff --git a/beets/dbcore/types.py b/beets/dbcore/types.py index 9d6020fa4..82346e704 100644 --- a/beets/dbcore/types.py +++ b/beets/dbcore/types.py @@ -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 diff --git a/beets/library.py b/beets/library.py index 2e3f04034..f5fb30b54 100644 --- a/beets/library.py +++ b/beets/library.py @@ -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)