File tree Expand file tree Collapse file tree 5 files changed +28
-7
lines changed Expand file tree Collapse file tree 5 files changed +28
-7
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## 2.4.1+2
4
+
5
+ - Fix error when sending json data with ` execute() ` [ #11 ] ( https://github.com/isoos/postgresql-dart/pull/11 )
6
+
3
7
## 2.4.1+1
4
8
5
9
- Fix error when passing ` allowReuse: null ` into ` query() ` [ #8 ] ( https://github.com/isoos/postgresql-dart/pull/8 )
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ class PostgresTextEncoder {
29
29
}
30
30
31
31
if (value is Map ) {
32
- return _encodeJSON (value);
32
+ return _encodeJSON (value, escapeStrings );
33
33
}
34
34
35
35
if (value is PgPoint ) {
@@ -152,7 +152,7 @@ class PostgresTextEncoder {
152
152
return "'$string '" ;
153
153
}
154
154
155
- String _encodeJSON (dynamic value) {
155
+ String _encodeJSON (dynamic value, bool escapeStrings ) {
156
156
if (value == null ) {
157
157
return 'null' ;
158
158
}
@@ -161,7 +161,7 @@ class PostgresTextEncoder {
161
161
return "'${json .encode (value )}'" ;
162
162
}
163
163
164
- return json.encode (value);
164
+ return _encodeString ( json.encode (value), escapeStrings );
165
165
}
166
166
167
167
String _encodePoint (PgPoint value) {
Original file line number Diff line number Diff line change 1
1
name : postgres
2
2
description : PostgreSQL database driver. Supports statement reuse and binary protocol.
3
- version : 2.4.1+1
3
+ version : 2.4.1+2
4
4
homepage : https://github.com/isoos/postgresql-dart
5
5
6
6
environment :
Original file line number Diff line number Diff line change @@ -546,9 +546,12 @@ void main() {
546
546
});
547
547
548
548
test ('Encode JSONB' , () {
549
- expect (encoder.convert ({'a' : 'b' }), '{"a":"b"}' );
550
- expect (encoder.convert ({'a' : true }), '{"a":true}' );
551
- expect (encoder.convert ({'b' : false }), '{"b":false}' );
549
+ expect (encoder.convert ({'a' : 'b' }, escapeStrings: false ), '{"a":"b"}' );
550
+ expect (encoder.convert ({'a' : true }, escapeStrings: false ), '{"a":true}' );
551
+ expect (
552
+ encoder.convert ({'b' : false }, escapeStrings: false ), '{"b":false}' );
553
+ expect (encoder.convert ({'a' : true }), '\' {"a":true}\' ' );
554
+ expect (encoder.convert ({'b' : false }), '\' {"b":false}\' ' );
552
555
});
553
556
554
557
test ('Attempt to infer unknown type throws exception' , () {
Original file line number Diff line number Diff line change @@ -103,6 +103,20 @@ void main() {
103
103
]
104
104
]);
105
105
});
106
+ test ('Can store JSON map with execute' , () async {
107
+ final result = await connection.execute (
108
+ 'INSERT INTO t (j) VALUES (@a:jsonb) RETURNING j' ,
109
+ substitutionValues: {
110
+ 'a' : {'a' : 4 }
111
+ });
112
+ expect (result, 1 );
113
+ final resultQuery = await connection.query ('SELECT j FROM t' );
114
+ expect (resultQuery, [
115
+ [
116
+ {'a' : 4 }
117
+ ]
118
+ ]);
119
+ });
106
120
107
121
test ('Can store JSON list' , () async {
108
122
var result = await connection
You can’t perform that action at this time.
0 commit comments