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

**URL:** <https://discuss.zetetic.net/t/update-to-4-5-0-issue-net-sqlcipher-database-sqliteexception-sql-logic-error-while-compiling-select-count-from-sqlite-master/5217>\
**Category:** Issues\
**Created:** [December 15, 2021, 7:55am UTC](https://discuss.zetetic.net/t/update-to-4-5-0-issue-net-sqlcipher-database-sqliteexception-sql-logic-error-while-compiling-select-count-from-sqlite-master/5217 "2021-12-15T07:55:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tuan](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/tuan/32/1951_2.png) [@Tuan](https://discuss.zetetic.net/u/Tuan)\
**Post date:** [December 15, 2021, 7:55am UTC](https://discuss.zetetic.net/t/update-to-4-5-0-issue-net-sqlcipher-database-sqliteexception-sql-logic-error-while-compiling-select-count-from-sqlite-master/5217/1 "2021-12-15T07:55:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [December 15, 2021, 2:08pm UTC](https://discuss.zetetic.net/t/update-to-4-5-0-issue-net-sqlcipher-database-sqliteexception-sql-logic-error-while-compiling-select-count-from-sqlite-master/5217/2 "2021-12-15T14:08:34Z")

</div>

Hi @Tuan

Are you able to create a reproducible test case within the SQLCipher for Android [test suite](https://github.com/sqlcipher/sqlcipher-android-tests)? If so, we’d be happy to look into it.

---

<div class="post-metadata">

**Author:** ![Tuan](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/tuan/32/1951_2.png) [@Tuan](https://discuss.zetetic.net/u/Tuan)\
**Post date:** [December 16, 2021, 12:19am UTC](https://discuss.zetetic.net/t/update-to-4-5-0-issue-net-sqlcipher-database-sqliteexception-sql-logic-error-while-compiling-select-count-from-sqlite-master/5217/3 "2021-12-16T00:19:02Z")

</div>

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().

```auto
                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.

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [December 16, 2021, 2:54pm UTC](https://discuss.zetetic.net/t/update-to-4-5-0-issue-net-sqlcipher-database-sqliteexception-sql-logic-error-while-compiling-select-count-from-sqlite-master/5217/4 "2021-12-16T14:54:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Tuan](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/tuan/32/1951_2.png) [@Tuan](https://discuss.zetetic.net/u/Tuan)\
**Post date:** [December 16, 2021, 8:00pm UTC](https://discuss.zetetic.net/t/update-to-4-5-0-issue-net-sqlcipher-database-sqliteexception-sql-logic-error-while-compiling-select-count-from-sqlite-master/5217/5 "2021-12-16T20:00:43Z")

</div>

Hi @developernotes  
Yes, here it is  
Before:

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

```

After:

```auto
            @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,
