Skip to content

Commit 3345223

Browse files
committed
Revert "Merge branch 'dispose-database-tracker' into develop"
This reverts commit a441069, reversing changes made to fcb7d78.
1 parent a441069 commit 3345223

File tree

4 files changed

+12
-121
lines changed

4 files changed

+12
-121
lines changed

drift/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
JSON.
88
- Add `runWithInterceptor` method to databases to only apply interceptors in
99
a restricted block.
10-
- Add `dispose()` method to `DatabaseTracker` to explicitly release in-memory SQLite resources.
1110

1211
## 2.23.1
1312

drift/lib/native.dart

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,10 @@ class _NativeDelegate extends Sqlite3Delegate<Database> {
356356
}
357357

358358
db = sqlite3.open(file.path);
359-
if (!tracker.isDisposed) {
360-
try {
361-
tracker.markOpened(file.path, db);
362-
} on SqliteException {
363-
// ignore
364-
}
359+
try {
360+
tracker.markOpened(file.path, db);
361+
} on SqliteException {
362+
// ignore
365363
}
366364
} else {
367365
db = sqlite3.openInMemory();
@@ -401,12 +399,10 @@ class _NativeDelegate extends Sqlite3Delegate<Database> {
401399
await super.close();
402400

403401
if (closeUnderlyingWhenClosed) {
404-
if (!tracker.isDisposed) {
405-
try {
406-
tracker.markClosed(database);
407-
} on SqliteException {
408-
// ignore
409-
}
402+
try {
403+
tracker.markClosed(database);
404+
} on SqliteException {
405+
// ignore
410406
}
411407

412408
database.dispose();

drift/lib/src/sqlite3/database_tracker.dart

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ final DatabaseTracker tracker = DatabaseTracker();
2323
/// this is necessary.
2424
class DatabaseTracker {
2525
final Database _db;
26-
bool _isDisposed = false;
27-
28-
/// Whether this [DatabaseTracker] has been disposed.
29-
bool get isDisposed => _isDisposed;
3026

3127
/// Creates a new tracker with necessary tables.
3228
DatabaseTracker()
@@ -42,35 +38,24 @@ CREATE TABLE IF NOT EXISTS open_connections(
4238
''');
4339
}
4440

45-
/// Tracks the [openedDb]. The [path] argument can be used to track
46-
/// the path of that database, if it's bound to a file.
47-
///
48-
/// Throws a [StateError] if this tracker has already been disposed.
41+
/// Tracks the [openedDb]. The [path] argument can be used to track the path
42+
/// of that database, if it's bound to a file.
4943
void markOpened(String path, Database openedDb) {
50-
_checkIfDisposed();
51-
5244
final stmt = _db.prepare('INSERT INTO open_connections VALUES (?, ?)');
5345
stmt.execute([openedDb.handle.address, path]);
5446
stmt.dispose();
5547
}
5648

5749
/// Marks the database [db] as closed.
58-
///
59-
/// Throws a [StateError] if this tracker has already been disposed.
6050
void markClosed(Database db) {
61-
_checkIfDisposed();
62-
6351
final ptr = db.handle.address;
6452
_db.execute('DELETE FROM open_connections WHERE database_pointer = $ptr');
6553
}
6654

67-
/// Closes all tracked database connections that are still open.
68-
///
69-
/// Throws a [StateError] if this tracker has already been disposed.
55+
/// Closes tracked database connections.
7056
void closeExisting() {
71-
_checkIfDisposed();
72-
7357
_db.execute('BEGIN;');
58+
7459
try {
7560
final results =
7661
_db.select('SELECT database_pointer FROM open_connections');
@@ -85,30 +70,4 @@ CREATE TABLE IF NOT EXISTS open_connections(
8570
_db.execute('COMMIT;');
8671
}
8772
}
88-
89-
/// Releases all open database handles managed by this tracker and
90-
/// closes the internal in-memory database.
91-
///
92-
/// After calling this method, this instance should no longer be used.
93-
/// Any further calls to public methods will throw a [StateError].
94-
void dispose() {
95-
if (_isDisposed) {
96-
return;
97-
}
98-
99-
// Safely close any tracked connections
100-
closeExisting();
101-
102-
_db.dispose();
103-
_isDisposed = true;
104-
}
105-
106-
/// Checks if this tracker has been disposed and throws a [StateError] if so.
107-
void _checkIfDisposed() {
108-
if (_isDisposed) {
109-
throw StateError(
110-
'DatabaseTracker has already been disposed and can no longer be used.',
111-
);
112-
}
113-
}
11473
}

drift/test/database/database_tracker_test.dart

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)