@@ -6,6 +6,7 @@ import 'dart:async';
66
77import 'package:drift/drift.dart' ;
88import 'package:drift_sqlite_async/drift_sqlite_async.dart' ;
9+ import 'package:sqlite3/common.dart' ;
910import 'package:sqlite_async/sqlite_async.dart' ;
1011import 'package:test/test.dart' ;
1112
@@ -219,5 +220,29 @@ void main() {
219220 .data,
220221 equals ({'count' : 1 }));
221222 });
223+
224+ test ('cannot update database with read' , () async {
225+ await expectLater (() => dbu.customSelect ('''
226+ -- trick to circumvent regex detecting writes
227+ INSERT INTO test_data(description) VALUES('test data');
228+ ''' ).get (), throwsA (isA <SqliteException >()));
229+ });
230+
231+ test ('allows spaces after returning' , () async {
232+ // This tests that the statement is forwarded to the write connection
233+ // despite using customSelect(). If it wasn't, we'd get an error about
234+ // the database being read-only.
235+ final row = await dbu.customSelect (
236+ 'INSERT INTO test_data(description) VALUES(?) RETURNING * ' ,
237+ variables: [Variable ('Test Data' )]).getSingle ();
238+ expect (row.data['description' ], equals ('Test Data' ));
239+ });
240+
241+ test ('allows spaces before insert' , () async {
242+ final row = await dbu.customSelect (
243+ ' INSERT INTO test_data(description) VALUES(?) ' ,
244+ variables: [Variable ('Test Data' )]).get ();
245+ expect (row, isEmpty);
246+ });
222247 });
223248}
0 commit comments