Baseflow / Baseflow/flutter_cached_network_image

【Android】DatabaseException no such column: key

Open
#654 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
2.6k
Forks
731
Avg merge
3d 9h
Merged PRs (30d)
1

Description

## 🐛 Bug Report

### Expected behavior
Images display without problems.

### Reproduction steps
I updated plugin version from 1.4.2 to 3.1.2 and released on Google Play Store.
(At the same time, I updated the flutter version from 1.22.6 to 2.2.3.)

And then, there was some reports of the bug that the image doesn't show up, and it stays on the loading screen all the time.
But I can't reproduce the bug on my phone.
I think that bug is caused by the cache database not being updated for some reason when the app is updated.

Here is the error that Firebase Crashlytics catched.
```
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: DatabaseException(no such column: key (code 1 SQLITE_ERROR[1]): , while compiling: SELECT * FROM cacheObject WHERE key = ?) sql 'SELECT * FROM cacheObject WHERE key = ?' args [https://firebasestorage.googleapis.com/v0/bappspot.com/o/channel-images%2FdluP5hY0o3FZmXYt1mjN%2Fsmall2.jpg?alt=media]}. Error thrown Instance of 'ErrorDescription'.
at .wrapDatabaseException(exception_impl.dart:11)
at SqfliteDatabaseMixin.txnRawQuery.(database_mixin.dart:406)
at BasicLock.synchronized(basic_lock.dart:33)
at SqfliteDatabaseMixin.txnSynchronized(database_mixin.dart:346)
at CacheObjectProvider.get(cache_object_provider.dart:110)
at CacheStore._getCacheDataFromDatabase(cache_store.dart:111)
```

Then, as an emergency measure, I deleted the cache DB and the cached images when the app started.

Here is the code.

```dart
Future deleteCache() async {
await _deleteCacheDatabase();
await _deleteImageDirectory();
}

Future _deleteCacheDatabase() async {
try {
final databaseDirectoryPath = await getApplicationSupportDirectory();
final databaseFilePath =
join(databaseDirectoryPath.path, '${DefaultCacheManager.key}.db');
final databaseFile = File(databaseFilePath);
final databaseExists = databaseFile.existsSync();
if (databaseExists) {
await deleteDatabase(databaseFilePath);
}
} on Exception catch (e) {
Crashlytics().recordError(exception: e);
}
}

Future _deleteImageDirectory() async {
try {
final cacheDirectoryPath = await getTemporaryDirectory();
final imageDirectoryPath =
join(cacheDirectoryPath.path, '${DefaultCacheManager.key}');
final imageDirectory = Directory(imageDirectoryPath);
final imageDirectoryExists = imageDirectory.existsSync();
if (imageDirectoryExists) {
imageDirectory.deleteSync(recursive: true);
}
} on Exception catch (e) {
Crashlytics().recordError(exception: e);
}
}
```

It was working fine on my device, but when I released it to Google Play Store, I got the following error and it seems that some devices are not displaying images properly.
```
DatabaseException(no such table: cacheObject (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM cacheObject WHERE key = ?) sql 'SELECT * FROM cacheObject WHERE key = ?' args [https://firebasestorage.googleapis.com/v0/b/...]. Error thrown Instance of 'ErrorDescription'.
```

Please let me know how I can fix the error.

### Configuration
```
Flutter 2.2.3 • channel unknown • unknown source
Framework • revision f4abaa0735 (3 months ago) • 2021-07-01 12:46:11 -0700
Engine • revision 241c87ad80
Tools • Dart 2.13.4
```

**Version:** 3.1.2

**Platform:**
- [ ] :iphone: iOS
- [x] :robot: Android

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.