diff --git a/packages_flutter/sqflite_example_android_wal/test/update_count_issue_wal_test_main.dart b/packages_flutter/sqflite_example_android_wal/test/update_count_issue_wal_test_main.dart index f9e03f8b..ac2b0757 100644 --- a/packages_flutter/sqflite_example_android_wal/test/update_count_issue_wal_test_main.dart +++ b/packages_flutter/sqflite_example_android_wal/test/update_count_issue_wal_test_main.dart @@ -26,6 +26,32 @@ void main() async { final count = await bookRepository.deleteBook(book!['id']); expect(count, 1, reason: 'Deleting existing row should return 1'); }); + + test('Inserting a new record with int PK should return the PK as row id in ' + 'WAL mode', () async { + final int id = 5; + final book = {'id': id, 'description': 'Test insert $id'}; + final result = await bookRepository.insertBook(book); + expect( + result, + id, + reason: + 'Inserting a new record with int PK should return the PK as row id', + ); + }); + + test('Inserting a new record with non-int PK should return internal non-zero ' + 'row id in WAL mode', () async { + final data = {'id': 'EUR', 'description': 'Test insert EUR'}; + final result = await bookRepository.insertCurrency(data); + expect( + result, + greaterThan(0), + reason: + 'Inserting a new record with non-int PK should return internal ' + 'non-zero row id', + ); + }); } class LocalDatabaseService { @@ -61,6 +87,7 @@ class LocalDatabaseService { } const booksTableName = 'books'; +const _currenciesTableName = 'currency'; void _createTables(Batch batch) { batch.execute('DROP TABLE IF EXISTS $booksTableName'); @@ -69,6 +96,12 @@ void _createTables(Batch batch) { "description" TEXT )'''); + batch.execute('DROP TABLE IF EXISTS $_currenciesTableName'); + batch.execute('''CREATE TABLE $_currenciesTableName ( + "id" TEXT PRIMARY KEY, + "description" TEXT +)'''); + _insertDummyData(batch); } @@ -166,4 +199,18 @@ class BookRepository { print('Rows deleted: $count. But record is actually deleted: $savedData'); return count; } + + Future insertBook(Map book) async { + final db = (await LocalDatabaseService.instance()).database!; + final result = await db.insert(booksTableName, book); + print('Row inserted, row id: $result'); + return result; + } + + Future insertCurrency(Map data) async { + final db = (await LocalDatabaseService.instance()).database!; + final result = await db.insert(_currenciesTableName, data); + print('Row inserted, row id: $result'); + return result; + } }