You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SQLite has a rather weak type system, and does not enforce type affinity.
sqflite seems to ignore the type affinity of the column. It returns a Map<String, dynamic>, where the type of the values are Strings, Ints, doubles...
If you have an embedded db in your application, where a column has a mixed type (sometimes numeric, sometimes text), the application likely wants to treat this column as TextColumn.
This currently does not work with Moor, as the implementation of StringType tries to cast the dynamic value to String: String mapFromDatabaseResponse(response) => response as String;.
This fails of course if response is an int. Using IntColumn would fail for records that don't have a numeric value.
With raw sqflite, I could work around this issue by calling toString() on the value of the result.
The performance impact should be negligible in case response is a String, as toString() just returns itself, but it would make TextColumn usable on columns with mixed types.
Alternatively, a method like .forceConvertToText() could be added to TextColumnBuilder, which would change the behaviour to calling .toString() instead of casting.
I am currently trying to migrate to moor from raw sqflite and this issue is blocking me from doing so.
The text was updated successfully, but these errors were encountered:
SQLite has a rather weak type system, and does not enforce type affinity.
sqflite seems to ignore the type affinity of the column. It returns a Map<String, dynamic>, where the type of the values are Strings, Ints, doubles...
If you have an embedded db in your application, where a column has a mixed type (sometimes numeric, sometimes text), the application likely wants to treat this column as TextColumn.
This currently does not work with Moor, as the implementation of
StringType
tries to cast the dynamic value to String:String mapFromDatabaseResponse(response) => response as String;
.This fails of course if response is an int. Using IntColumn would fail for records that don't have a numeric value.
With raw sqflite, I could work around this issue by calling
toString()
on the value of the result.I suggest changing the implementation to
String mapFromDatabaseResponse(response) => response.toString();
The performance impact should be negligible in case
response
is a String, astoString()
just returns itself, but it would make TextColumn usable on columns with mixed types.Alternatively, a method like
.forceConvertToText()
could be added to TextColumnBuilder, which would change the behaviour to calling .toString() instead of casting.I am currently trying to migrate to moor from raw sqflite and this issue is blocking me from doing so.
The text was updated successfully, but these errors were encountered: