@@ -6,6 +6,7 @@ import 'package:test/test.dart';
6
6
import 'utils/test_utils_impl.dart' ;
7
7
8
8
final testUtils = TestUtils ();
9
+ const _isDart2Wasm = bool .fromEnvironment ('dart.tool.dart2wasm' );
9
10
10
11
void main () {
11
12
group ('Shared Basic Tests' , () {
@@ -125,48 +126,67 @@ void main() {
125
126
expect (savedTx! .closed, equals (true ));
126
127
});
127
128
128
- test ('should properly report errors in transactions' , () async {
129
- final db = await testUtils.setupDatabase (path: path);
130
- await createTables (db);
129
+ test (
130
+ 'should properly report errors in transactions' ,
131
+ () async {
132
+ final db = await testUtils.setupDatabase (path: path);
133
+ await createTables (db);
131
134
132
- var tp = db.writeTransaction ((tx) async {
133
- await tx.execute (
134
- 'INSERT OR ROLLBACK INTO test_data(id, description) VALUES(?, ?)' ,
135
- [1 , 'test1' ]);
136
- await tx.execute (
137
- 'INSERT OR ROLLBACK INTO test_data(id, description) VALUES(?, ?)' ,
138
- [2 , 'test2' ]);
139
- expect (await tx.getAutoCommit (), equals (false ));
140
- try {
135
+ var tp = db.writeTransaction ((tx) async {
141
136
await tx.execute (
142
137
'INSERT OR ROLLBACK INTO test_data(id, description) VALUES(?, ?)' ,
143
- [2 , 'test3' ]);
144
- } catch (e) {
145
- // Ignore
146
- }
147
-
148
- expect (await tx.getAutoCommit (), equals (true ));
149
- expect (tx.closed, equals (false ));
150
-
151
- // Will not be executed because of the above rollback
152
- await tx.execute (
153
- 'INSERT OR ROLLBACK INTO test_data(id, description) VALUES(?, ?)' ,
154
- [4 , 'test4' ]);
155
- });
156
-
157
- // The error propagates up to the transaction
138
+ [1 , 'test1' ]);
139
+ await tx.execute (
140
+ 'INSERT OR ROLLBACK INTO test_data(id, description) VALUES(?, ?)' ,
141
+ [2 , 'test2' ]);
142
+ expect (await tx.getAutoCommit (), equals (false ));
143
+ try {
144
+ await tx.execute (
145
+ 'INSERT OR ROLLBACK INTO test_data(id, description) VALUES(?, ?)' ,
146
+ [2 , 'test3' ]);
147
+ } catch (e) {
148
+ // Ignore
149
+ }
150
+
151
+ expect (await tx.getAutoCommit (), equals (true ));
152
+ expect (tx.closed, equals (false ));
153
+
154
+ // Will not be executed because of the above rollback
155
+ await tx.execute (
156
+ 'INSERT OR ROLLBACK INTO test_data(id, description) VALUES(?, ?)' ,
157
+ [4 , 'test4' ]);
158
+ });
159
+
160
+ // The error propagates up to the transaction
161
+ await expectLater (
162
+ tp,
163
+ throwsA ((e) =>
164
+ e is SqliteException &&
165
+ e.message
166
+ .contains ('Transaction rolled back by earlier statement' )));
167
+
168
+ expect (await db.get ('SELECT count() count FROM test_data' ),
169
+ equals ({'count' : 0 }));
170
+
171
+ // Check that we can open another transaction afterwards
172
+ await db.writeTransaction ((tx) async {});
173
+ },
174
+ skip: _isDart2Wasm
175
+ ? 'Fails due to compiler bug, https://dartbug.com/59981'
176
+ : null ,
177
+ );
178
+
179
+ test ('reports exceptions as SqliteExceptions' , () async {
180
+ final db = await testUtils.setupDatabase (path: path);
158
181
await expectLater (
159
- tp,
160
- throwsA ((e) =>
161
- e is SqliteException &&
162
- e.message
163
- .contains ('Transaction rolled back by earlier statement' )));
164
-
165
- expect (await db.get ('SELECT count() count FROM test_data' ),
166
- equals ({'count' : 0 }));
167
-
168
- // Check that we can open another transaction afterwards
169
- await db.writeTransaction ((tx) async {});
182
+ db.get ('SELECT invalid_statement;' ),
183
+ throwsA (
184
+ isA <SqliteException >()
185
+ .having ((e) => e.causingStatement, 'causingStatement' ,
186
+ 'SELECT invalid_statement;' )
187
+ .having ((e) => e.extendedResultCode, 'extendedResultCode' , 1 ),
188
+ ),
189
+ );
170
190
});
171
191
});
172
192
}
0 commit comments