Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android P - 'SQLite: No Such Table Error' after copying database from assets

I have a database saved in my apps assets folder and I copy the database using the below code when the app first opens.

inputStream = mContext.getAssets().open(Utils.getDatabaseName());          if(inputStream != null) {              int mFileLength = inputStream.available();              String filePath = mContext.getDatabasePath(Utils.getDatabaseName()).getAbsolutePath();              // Save the downloaded file             output = new FileOutputStream(filePath);              byte data[] = new byte[1024];             long total = 0;             int count;             while ((count = inputStream.read(data)) != -1) {                 total += count;                 if(mFileLength != -1) {                     // Publish the progress                     publishProgress((int) (total * 100 / mFileLength));                 }                 output.write(data, 0, count);             }             return true;         } 

The above code runs without problem but when you try to query the database you get an SQLite: No such table exception.

This issue only occurs in Android P, all earlier versions of Android work correctly.

Is this a known issue with Android P or has something changed?

like image 204
Michael J Avatar asked May 22 '18 21:05

Michael J


Video Answer


1 Answers

Was having a similar issue, and solved this adding this to my SQLiteOpenHelper

    @Override     public void onOpen(SQLiteDatabase db) {         super.onOpen(db);         db.disableWriteAheadLogging();     } 

Apparently Android P sets the PRAGMA Log thing different. Still no idea if will have side effects, but seems to be working!

like image 116
Ramon Canales Avatar answered Oct 07 '22 18:10

Ramon Canales