@@ -14,11 +14,13 @@ const defaultSqlitePath = 'libsqlite3.so.0';
1414
1515class TestSqliteOpenFactory extends DefaultSqliteOpenFactory {
1616 String sqlitePath;
17+ List <String > initStatements;
1718
1819 TestSqliteOpenFactory (
1920 {required super .path,
2021 super .sqliteOptions,
21- this .sqlitePath = defaultSqlitePath});
22+ this .sqlitePath = defaultSqlitePath,
23+ this .initStatements = const []});
2224
2325 @override
2426 sqlite.Database open (SqliteOpenOptions options) {
@@ -45,12 +47,29 @@ class TestSqliteOpenFactory extends DefaultSqliteOpenFactory {
4547 },
4648 );
4749
50+ db.createFunction (
51+ functionName: 'test_connection_number' ,
52+ argumentCount: const sqlite.AllowedArgumentCount (0 ),
53+ function: (args) {
54+ // write: 0, read: 1 - 5
55+ final name = Isolate .current.debugName ?? '-0' ;
56+ var nr = name.split ('-' ).last;
57+ return int .tryParse (nr) ?? 0 ;
58+ },
59+ );
60+
61+ for (var s in initStatements) {
62+ db.execute (s);
63+ }
64+
4865 return db;
4966 }
5067}
5168
52- SqliteOpenFactory testFactory ({String ? path}) {
53- return TestSqliteOpenFactory (path: path ?? dbPath ());
69+ SqliteOpenFactory testFactory (
70+ {String ? path, List <String > initStatements = const []}) {
71+ return TestSqliteOpenFactory (
72+ path: path ?? dbPath (), initStatements: initStatements);
5473}
5574
5675Future <SqliteDatabase > setupDatabase ({String ? path}) async {
0 commit comments