@@ -158,5 +158,43 @@ void main() {
158158 await db.execute ('PRAGMA wal_checkpoint(TRUNCATE)' );
159159 await db.execute ('VACUUM' );
160160 });
161+
162+ test ('should allow ignoring errors' , () async {
163+ final db = await setupDatabase (path: path);
164+ await createTables (db);
165+
166+ ignore (db.execute (
167+ 'INSERT INTO test_data(description) VALUES(json(?))' , ['test3' ]));
168+ });
169+
170+ test ('should properly report errors in transactions' , () async {
171+ final db = await setupDatabase (path: path);
172+ await createTables (db);
173+
174+ var tp = db.writeTransaction ((tx) async {
175+ tx.execute ('INSERT INTO test_data(description) VALUES(?)' , ['test1' ]);
176+ tx.execute ('INSERT INTO test_data(description) VALUES(?)' , ['test2' ]);
177+ ignore (tx.execute ('INSERT INTO test_data(description) VALUES(json(?))' ,
178+ ['test3' ])); // Errors
179+ // Will not be executed because of the above error
180+ ignore (tx.execute (
181+ 'INSERT INTO test_data(description) VALUES(?) RETURNING *' ,
182+ ['test4' ]));
183+ });
184+
185+ // The error propagates up to the transaction
186+ await expectLater (tp, throwsA ((e) => e is sqlite.SqliteException ));
187+
188+ expect (await db.get ('SELECT count() count FROM test_data' ),
189+ equals ({'count' : 0 }));
190+
191+ // Check that we can open another transaction afterwards
192+ await db.writeTransaction ((tx) async {});
193+ });
161194 });
162195}
196+
197+ // For some reason, future.ignore() doesn't actually ignore errors in these tests.
198+ void ignore (Future future) {
199+ future.then ((_) {}, onError: (_) {});
200+ }
0 commit comments