Baseflow / flutter_cache_manager

Generic cache manager for flutter
https://baseflow.com
MIT License
739 stars 426 forks source link

SqfliteDatabaseException attempt to write a readonly database (code 1032 SQLITE_READONLY_DBMOVED[1032])) #359

Open baer999 opened 2 years ago

baer999 commented 2 years ago

🐛 Bug Report

When using the flutter_cache_manager within Dart 2.15 within Flutter 2 I get sometime this Fail with SQLite.

Error: SqfliteDatabaseException DatabaseException(attempt to write a readonly database (code 1032 SQLITE_READONLY_DBMOVED[1032])) sql 'UPDATE cacheObject SET url = ?, key = ?, relativePath = ?, eTag = ?, validTill = ?, touched = ?, length = ?, _id = ? WHERE _id = ?' args [https://asdf.de/img/start_aktion-1_mobil-opti...., https://asdf.de/img/start_aktion-1_mobil-opti...., 57dcb0d0-79e7-11ec-bb36-436c12859413.png, W/"16304a-17dc2bf19ff", 1643284306013, 1642679987235, 1454154, 1, 1]

Expected behavior

I would like to have a non throwing Error behaviour with the Cache Manager.

Reproduction steps

Call within InitState method something like this (async):

mainProvider.retrieveStartPageData(mta).then((value) async {
  if (value != null) {
    if (mainProvider.myHi.length > 0) {
      for (var headerImage in mainProvider.myHi) {
        await DefaultCacheManager().getSingleFile(
            '${Env.value!.imgUrl}${headerImage.imageMobile}');
      }
    }
  }
});

Configuration

Dart: 2.15 Flutter 2.5

Platform:

olegyablokov commented 2 years ago

I have a similar problem, it says:

E/SQLiteLog(27356): (1) fileHasMoved : original inode of /data/user/0/com.company.myapp/files/libCachedImageData.db is (132300)
E/SQLiteLog(27356): (1) Stat of fd(135) : st_mode(100600) st_uid(10398) st_gid(10398) st_ino(132300) st_size(16384)
E/SQLiteLog(27356): (1) File name of fd(135) : /data/data/com.company.myapp/files/libCachedImageData.db (deleted)
E/SQLiteLog(27356): (1) osStat failed "/data/user/0/com.company.myapp/files/libCachedImageData.db" due to error (2)
E/SQLiteLog(27356): (1) Stat of /data/user/0/com.company.myapp/files : st_mode(40700) st_uid(10398) st_gid(10398) st_ino(132186)
E/SQLiteLog(27356): (1) Stat of /data/user/0/com.company.myapp : st_mode(40700) st_uid(10398) st_gid(10398) st_ino(131279)
E/SQLiteLog(27356): (1) Stat of /data/user/0 : st_mode(40771) st_uid(1000) st_gid(1000) st_ino(393217)
E/SQLiteLog(27356): (1) Stat of /data/user : st_mode(40711) st_uid(1000) st_gid(1000) st_ino(196610)
E/SQLiteLog(27356): (1) Stat of /data : st_mode(40771) st_uid(1000) st_gid(1000) st_ino(2)
E/SQLiteLog(27356): (1032) statement aborts at 5: [DELETE FROM cacheObject WHERE _id = ?] attempt to write a readonly database

Dart: 2.16.1 Flutter: 2.10.3 Tried with cached_network_image: 3.0.0, 3.1.0, 3.1.0+1 and 3.2.0, same error everywhere.

baer999 commented 1 year ago

Error still exists, does anyone has an idea how to fix this? Here is more detailled stacktrace:


SqfliteDatabaseException
DatabaseException(Error Domain=FMDatabase Code=1032 "attempt to write a readonly database" UserInfo={NSLocalizedDescription=attempt to write a readonly database}) sql 'UPDATE cacheObject SET url = ?, key = ?, relativePath = ?, eTag = ?, validTill = ?, touched = ?, length = ?, _id = ? WHERE _id = ?' args [https://test.de/img/allgemein_content-opti.png, https://test.de/img/allgemein_content-opti.png, dee7f2a0-6380-11ed-87ad-47c6ad692ff1.png, W/"8bc07-17a3e020c59", 1668968866506, 1668545835289, 572423, 27, 27]
mechanism
runZonedGuarded
handled
true

exception_impl.dart in wrapDatabaseException at line 11 within sqflite
Called from: <asynchronous suspension>
database_mixin.dart in SqfliteDatabaseMixin.txnRawUpdate.<fn> at line 418 within sqflite_common
Called from: <asynchronous suspension>
basic_lock.dart in BasicLock.synchronized at line 33 within synchronized
Called from: <asynchronous suspension>
database_mixin.dart in SqfliteDatabaseMixin.txnSynchronized at line 344 within sqflite_common