@@ -14,11 +14,13 @@ const defaultSqlitePath = 'libsqlite3.so.0';
14
14
15
15
class TestSqliteOpenFactory extends DefaultSqliteOpenFactory {
16
16
String sqlitePath;
17
+ List <String > initStatements;
17
18
18
19
TestSqliteOpenFactory (
19
20
{required super .path,
20
21
super .sqliteOptions,
21
- this .sqlitePath = defaultSqlitePath});
22
+ this .sqlitePath = defaultSqlitePath,
23
+ this .initStatements = const []});
22
24
23
25
@override
24
26
sqlite.Database open (SqliteOpenOptions options) {
@@ -45,12 +47,29 @@ class TestSqliteOpenFactory extends DefaultSqliteOpenFactory {
45
47
},
46
48
);
47
49
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
+
48
65
return db;
49
66
}
50
67
}
51
68
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);
54
73
}
55
74
56
75
Future <SqliteDatabase > setupDatabase ({String ? path}) async {
0 commit comments