ionic-team / ionic-storage

Ionic Storage module for Ionic apps
MIT License
434 stars 99 forks source link

After update "@ionic/storage": "2.1.3", to"@ionic/storage": "2.2.0" App not working only when user update the app #241

Open bhandaribhumin opened 3 years ago

bhandaribhumin commented 3 years ago

Reproduce Description :

We already have an application on AppStore/play store with app version 1.0.0 after we update dependency from "@ionic/storage": "2.1.3", to "@ionic/storage": "2.2.0" and push with version 1.1.0 to AppStore/play store application works only when user installs fresh but when they try to update app then the app will be stuck.

We can not tested upgrade scenario before send to production can anyone suggest how can I solve this issue?

"@ionic/storage": "2.1.3" works "@ionic/storage": "2.2.0" not works on upgrade scenario.

Ref : https://github.com/ionic-team/ionic-storage/commit/2e888c52a17b8702324ffc2531369fe6e8bb7bb5

Error LOGs:

"OPEN database: _ionicstorage", source: http://localhost/plugins/cordova-sqlcipher-adapter/www/SQLitePlugin.js (175)
"new transaction is queued, waiting for open operation to finish", source: http://localhost/plugins/cordova-sqlcipher-adapter/www/SQLitePlugin.js (106)
D/SERVER: Handling local request: http://localhost/assets/icon/favicon.ico
E/SQLitePlugin: unexpected error, stopping db thread
    net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;
        at net.sqlcipher.database.SQLiteCompiledSql.native_compile(Native Method)
        at net.sqlcipher.database.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:89)
        at net.sqlcipher.database.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:62)
        at net.sqlcipher.database.SQLiteProgram.<init>(SQLiteProgram.java:91)
        at net.sqlcipher.database.SQLiteQuery.<init>(SQLiteQuery.java:48)
        at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:60)
        at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:2016)
        at net.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1902)
        at net.sqlcipher.database.SQLiteDatabase.keyDatabase(SQLiteDatabase.java:2669)
        at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(SQLiteDatabase.java:2599)
        at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1247)
        at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1214)
        at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1304)
        at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1292)
        at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1284)
        at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1329)
        at io.sqlc.SQLiteAndroidDatabase.open(SQLiteAndroidDatabase.java:86)
        at io.sqlc.SQLitePlugin.openDatabase(SQLitePlugin.java:228)
        at io.sqlc.SQLitePlugin.access$000(SQLitePlugin.java:29)
        at io.sqlc.SQLitePlugin$DBRunner.run(SQLitePlugin.java:351)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
: [INFO:CONSOLE(197)] "OPEN database: _ionicstorage FAILED, aborting any pending transactions", source: http://localhost/plugins/cordova-sqlcipher-adapter/www/SQLitePlugin.js (197)
: [INFO:CONSOLE(83)] "Could not open database", source: http://localhost/plugins/cordova-sqlcipher-adapter/www/SQLitePlugin.js (83)
D/CordovaActivity: Paused the activity.
bhandaribhumin commented 2 years ago

@mhartington could you please help me on this? It is critical and high priority for us because user lost his/her data after update new version of the app. we fix this issue for Android but SQLitePlugin.m -> sqlite3_exec is not working after passing key from app.module.ts

IonicStorageModule.forRoot({
      dbKey:'',
      driverOrder: ['sqlite', 'indexeddb', 'websql']
    })

cipher plugin version details : "cordova-sqlcipher-adapter": "0.1.12-rc2",

bhargavas12 commented 2 years ago

@bhandaribhumin is this issue resolved? even we are facing the same thing after upgrade.

Thanks

bhandaribhumin commented 2 years ago

yes @bhargavas12 resolved, we are doing few changes in SQLitePlugin.m and SQLitePlugin.java file and it works :)

bhandaribhumin commented 2 years ago

Fixes : SQLitePlugin.m

 if(sqlite3_exec(db, (const char*)"SELECT * FROM _ionickv;", my_special_callback, NULL, NULL) == SQLITE_OK){
                        NSLog(@"_ionickv is open");
                }else{
                    NSLog(@"Key Not valid");
                    sqlite3_key(db, "_ionickey", strlen("_ionickey"));
                    sqlite3_exec(db, (const char*)"SELECT * FROM _ionickv;", my_special_callback, NULL, NULL);
                }

SQLitePlugin.java

try {
              mydb.open(dbfile, key);
            } catch (Exception e) {
              Log.e(this.getClass().getSimpleName(), "Failed with previous key : "+key+" With error : "+e.getMessage());
              mydb.open(dbfile, "_ionickey");
            }
bhargavas12 commented 2 years ago

@bhandaribhumin
driverOrder: ['localstorage', 'indexeddb', 'sqlite', 'websql'] this is our drive order and we updated to angular 13 from angular9 and ionic version is 6. as part of this upgrade the storage isn't retaining. tried your hack but no luck.

what i tried:

moved to latest ionic/storage i.e.., 3.0.6 installed ionic/storage-angular - 3.0.6 tried to shuffle drive order but nothing worked.

Please help.

bhandaribhumin commented 2 years ago

@bhargavas12 you may need to add below code while init storage in app.module.ts

 IonicStorageModule.forRoot({
      dbKey:'',
      driverOrder: ['sqlite', 'indexeddb', 'websql']
    }),

We had tested all scenarios and now app works perfectly.

bhargavas12 commented 2 years ago

we had the preferrence as localstorage followed by indexdb and sqllite. in the app before upgrade