mirror of https://github.com/AMT-Cheif/drift.git
Call doWhenOpened for customStatement (#199)
This commit is contained in:
parent
8a8b811643
commit
1f8dfbe887
|
@ -1,3 +1,7 @@
|
|||
## unreleased
|
||||
|
||||
- Fix crash when `customStatement` is the first operation used on a database ([#199](https://github.com/simolus3/moor/issues/199))
|
||||
|
||||
## 2.0.1
|
||||
|
||||
- Introduced `isBetween` and `isBetweenValues` methods for comparable expressions (int, double, datetime)
|
||||
|
|
|
@ -270,7 +270,11 @@ mixin QueryEngine on DatabaseConnectionUser {
|
|||
@protected
|
||||
@visibleForTesting
|
||||
Future<void> customStatement(String statement, [List<dynamic> args]) {
|
||||
return _resolvedEngine.executor.runCustom(statement, args);
|
||||
final engine = _resolvedEngine;
|
||||
|
||||
return engine.executor.doWhenOpened((executor) {
|
||||
return executor.runCustom(statement, args);
|
||||
});
|
||||
}
|
||||
|
||||
/// Executes [action] in a transaction, which means that all its queries and
|
||||
|
|
|
@ -73,4 +73,10 @@ void main() {
|
|||
// shouldn't call stream queries - we didn't set the updates parameter
|
||||
verifyNever(streamQueries.handleTableUpdates(any));
|
||||
});
|
||||
|
||||
test('custom statement', () async {
|
||||
// regression test for https://github.com/simolus3/moor/issues/199 - the
|
||||
// mock will throw when used before opening
|
||||
expect(db.customStatement('UPDATE tbl SET a = b'), completes);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -29,6 +29,10 @@ class MockExecutor extends Mock implements QueryExecutor {
|
|||
assert(_opened);
|
||||
return Future.value(0);
|
||||
});
|
||||
when(runCustom(any, any)).thenAnswer((_) {
|
||||
assert(_opened);
|
||||
return Future.value(0);
|
||||
});
|
||||
when(beginTransaction()).thenAnswer((_) {
|
||||
assert(_opened);
|
||||
return transactions;
|
||||
|
|
Loading…
Reference in New Issue