Report more errors when database is opened

This commit is contained in:
Simon Binder 2019-09-04 21:20:09 +02:00
parent 3c56e0ad6e
commit a17ad13542
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 17 additions and 5 deletions

View File

@ -240,14 +240,26 @@ class DelegatedDatabase extends QueryExecutor with _ExecutorWithQueryDelegate {
logStatements ??= false; logStatements ??= false;
} }
var _ensureOpenCalledCounter = 0; // todo remove
@override @override
Future<bool> ensureOpen() { Future<bool> ensureOpen() {
return _openingLock.synchronized(() async { final call = ++_ensureOpenCalledCounter;
final alreadyOpen = await delegate.isOpen; print('ensure_open_$call: called');
if (alreadyOpen) return true;
return _openingLock.synchronized(() async {
print('ensure_open_$call: lock aquired');
final alreadyOpen = await delegate.isOpen;
if (alreadyOpen) {
print('ensure_open_$call: was already open');
return true;
}
print('ensure_open_$call: opening database');
await delegate.open(databaseInfo); await delegate.open(databaseInfo);
print('ensure_open_$call: running migrations');
await _runMigrations(); await _runMigrations();
print('ensure_open_$call: done with opening');
return true; return true;
}); });
} }

View File

@ -53,11 +53,11 @@ class _SqfliteDelegate extends DatabaseDelegate with _SqfliteExecutor {
@override @override
Future<void> open([GeneratedDatabase db]) async { Future<void> open([GeneratedDatabase db]) async {
print('uses fix for the opening problem.');
assert( assert(
!_debugIsOpening && !isOpen, !_debugIsOpening && !isOpen,
'Database opened multiple times, this should never happen. ' 'Database opened multiple times, this should never happen. '
'Please report this at https://github.com/simolus3/moor/issues/135 to help fix this!'); 'Please report this at https://github.com/simolus3/moor/issues/135 to help fix this!'
'Db already opened: $isOpen. Other operation in progress: $_debugIsOpening');
_debugIsOpening = true; _debugIsOpening = true;
try { try {