dart_postgresql
dart_postgresql copied to clipboard
Encoding numbers as json is buggy.
Typeconverter.dart Line: 163
Change to:
if (value is num) {
...
var n = value.toString();
return "'$n'";
}
Also note doc comment is wrong.
//FIXME can probably simplify this, as in postgresql json type must take // map or array at top level, not string or number. (I think???) String encodeValueToJson(value, {getConnectionName()}) { if (value == null) return "'null'";
if (value is Map || value is List)
return encodeString(JSON.encode(value));
if (value is String)
return encodeString('"$value"');
if (value is num) {
// These are not valid JSON numbers, so encode them as strings.
// TODO consider throwing an error instead.
if (value.isNaN) return '"nan"';
if (value == double.INFINITY) return '"infinity"';
if (value == double.NEGATIVE_INFINITY) return '"-infinity"';
return value.toString();
}
try {
var map = value.toJson();
return encodeString(JSON.encode(value));
} catch (e) {
throw _error('Could not convert object to JSON. '
'No toJson() method was implemented on the object.', getConnectionName);
}
}