Fix crash when database is closed with asserts disabled

This commit is contained in:
Simon Binder 2019-11-28 17:59:50 +01:00
parent cf607f0108
commit 41b32b1684
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 5 additions and 2 deletions

View File

@ -61,7 +61,7 @@ abstract class GeneratedDatabase extends DatabaseConnectionUser
final count = ++_openedDbCount[runtimeType];
if (count > 1) {
print(
'WARNING (moor): It looks like you\'ve created the database '
'WARNING (moor): It looks like you\'ve created the database class'
'$runtimeType multiple times. When these two databases use the same '
'QueryExecutor, race conditions will ocur and might corrupt the '
'database. \n'
@ -124,6 +124,9 @@ abstract class GeneratedDatabase extends DatabaseConnectionUser
/// Closes this database and releases associated resources.
Future<void> close() async {
await executor.close();
_openedDbCount[runtimeType]--;
if (_openedDbCount[runtimeType] != null) {
_openedDbCount[runtimeType]--;
}
}
}