Fix bug with VmDatabase.opened

This commit is contained in:
Simon Binder 2020-12-07 22:03:55 +01:00
parent 42ba773422
commit 1edcc634b1
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 13 additions and 4 deletions

View File

@ -108,6 +108,8 @@ class VmDatabase extends DelegatedDatabase {
class _VmDelegate extends DatabaseDelegate {
late Database _db;
bool _hasCreatedDatabase = false;
bool _isOpen = false;
final File? file;
@ -115,7 +117,9 @@ class _VmDelegate extends DatabaseDelegate {
_VmDelegate(this.file, this.setup);
_VmDelegate._opened(this._db, this.setup) : file = null {
_VmDelegate._opened(this._db, this.setup)
: file = null,
_hasCreatedDatabase = true {
_initializeDatabase();
}
@ -130,16 +134,18 @@ class _VmDelegate extends DatabaseDelegate {
@override
Future<void> open(QueryExecutorUser user) async {
if (!_isOpen) {
if (!_hasCreatedDatabase) {
_createDatabase();
_initializeDatabase();
}
_initializeDatabase();
_isOpen = true;
return Future.value();
}
void _createDatabase() {
assert(!_isOpen);
assert(!_hasCreatedDatabase);
_hasCreatedDatabase = true;
final file = this.file;
if (file != null) {

View File

@ -33,6 +33,9 @@ void main() {
final row = await db.customSelect('SELECT my_function() AS r;').getSingle();
expect(row!.readString('r'), 'hello from Dart');
final nativeRow = existing.select('SELECT my_function() AS r;').single;
expect(nativeRow['r'], 'hello from Dart');
await db.close();
});
}