Update to 4.5.0 issue: net.sqlcipher.database.SQLiteException: SQL logic error: , while compiling: select count(*) from sqlite_master;

Hi all,
Thanks so much for looking at my post.

We updated the library from 4.4.3 to 4.5.0 in our Android app and now some of our tests fail with the following error:

net.sqlcipher.database.SQLiteException: SQL logic error: , 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.(SQLiteCompiledSql.java:62)
at net.sqlcipher.database.SQLiteProgram.(SQLiteProgram.java:91)
at net.sqlcipher.database.SQLiteQuery.(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.openOrCreateDatabase(SQLiteDatabase.java:1322)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:166)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:135)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:131)



It’s the result of calling: dbHelper.getWritableDatabase(………);
after calling dbHelper.close():

Has anyone encountered this issue before? Any help is appreciated.
Thanks.

Hi @Tuan

Are you able to create a reproducible test case within the SQLCipher for Android test suite? If so, we’d be happy to look into it.

Hi @developernotes,

Thanks for replying. I was going through the test suite, but couldn’t find a similar test case.
One of our team members found that we are still calling the command “PRAGMA …” on preKey().

                database.rawExecSQL("PRAGMA key=........);
                database.rawExecSQL("PRAGMA cipher_migrate");

Removing both commands and the failed tests are now passing.
We are upgrading from 4.4.3 to 4.5.0. We have a set of tests that open/close/open the DB. They have all been passing. But with the upgrade to 4.5.0, some of them fail to open the DB, after being closed with the error above.

Do you have any idea why removing the “PRAGMA” command fixes the failure to open the DB?

Thanks so much.

Hi @Tuan

That’s great to hear you were able to resolve the issue. Can you share the entire contents of your previous preKey method?

Hi @developernotes
Yes, here it is
Before:

            @Override
            public void preKey(SQLiteDatabase database) {
                database.rawExecSQL("PRAGMA key=......");
                database.rawExecSQL("PRAGMA cipher_migrate");
            }

After:

            @Override
            public void preKey(SQLiteDatabase database) {
                database.rawExecSQL("PRAGMA key=.......");
            }

Actually removing both lines, not all of the failed tests passed. We are removing only “database.rawExecSQL(“PRAGMA cipher_migrate”);”

Thanks,