1

We have an android app that uses SQLite for some form of persistent storage. The sqlite code works on all devices except Oneplus devices. ( I am testing on Oneplus 2 A2003)

Following is the error that I am seeing in logcat.

android.database.sqlite.SQLiteException: no such table: testtable (code 1): , while compiling: INSERT INTO testtable(ID,CompletedOn,CreatedOn,Type,Pending,Priority,Attributes) VALUES (?,?,?,?,?,?,?)

Following is the piece of database that is used for open database

   SQLiteDatabase db = SQLiteDatabase.openDatabase(this.getHelperContext().getDatabasePath(DATABASE_NAME).getAbsolutePath(), null,
                    SQLiteDatabase.NO_LOCALIZED_COLLATORS);

Have tried even specifying the access rights while opening, but no difference. e.g. SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READWRITE

Any help would be appreciated.

user_v
  • 9,628
  • 4
  • 40
  • 32
  • Are you creating the database correctly? Post your onCreate and onUpdate. – 323go Jan 04 '16 at 13:05
  • Uninstall and reinstall the app, to make sure that you are working with the right database schema, and you're not breaking due to inconsistencies between your schema version number and your `onUpgrade()` implementation. Or, examine the schema of your existing database to see what is different between it and your desired schema. – CommonsWare Jan 04 '16 at 13:06
  • The database schema (with tables & sample data) is part of the app, the code only tries to read/update/insert. And its only an issue with Oneplus 2 device, works fine with rest (app older than 2 years) – user_v Jan 04 '16 at 13:10
  • Did you find any solution to your issue? – chossen-addict Feb 04 '16 at 20:32
  • No, we did not find any solution, finally had to drop it due to the ROI – user_v Feb 29 '16 at 09:13

1 Answers1

0

Check this answer https://stackoverflow.com/a/33032467/4504324 it solved the issue for me.

Just close the db before copying the sqlite stream into internal database.

private void copyDataBase() throws IOException {

    try {
        //Open your local db as the input stream
        InputStream myInput = mContext.getAssets().open("databases/" + DB_NAME+".sqlite");
        // Path to the just created empty db
        String outFileName = mContext.getDatabasePath(DB_NAME).getAbsolutePath();

        //Open the empty db as the output stream
        OutputStream myOutput = new FileOutputStream(outFileName);

        //close the database so that stream can be copied
        this.getReadableDatabase().close();

        //transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, length);
        }
        //Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Community
  • 1
  • 1
Uday Naidu
  • 532
  • 1
  • 6
  • 16