Skip to content

Commit 8f4d2b3

Browse files
committed
add rollback test
1 parent 17cdae2 commit 8f4d2b3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

packages/sqlite_async/test/basic_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,31 @@ void main() {
349349
await db.close();
350350
});
351351

352+
test('executeMultiple rolls back on failure', () async {
353+
final db = await testUtils.setupDatabase(path: path);
354+
await createTables(db);
355+
356+
// Insert an initial row with id=1
357+
await db.execute(
358+
'INSERT INTO test_data(id, description) VALUES(?, ?)', [1, 'initial']);
359+
360+
// Attempt executeMultiple where second statement fails due to duplicate primary key
361+
await expectLater(
362+
db.executeMultiple('''
363+
INSERT INTO test_data(id, description) VALUES(2, 'should_rollback');
364+
INSERT INTO test_data(id, description) VALUES(1, 'duplicate_key');
365+
'''),
366+
throwsA(isA<SqliteException>()),
367+
);
368+
369+
// Verify only the initial row exists - the first insert in executeMultiple should have been rolled back
370+
final results = await db.getAll('SELECT id, description FROM test_data ORDER BY id');
371+
expect(results.length, equals(1));
372+
expect(results.rows[0], equals([1, 'initial']));
373+
374+
await db.close();
375+
});
376+
352377
test('with all connections', () async {
353378
final maxReaders = _isWeb ? 0 : 3;
354379

0 commit comments

Comments
 (0)