setVersion failed but transaction not rollback?


when i update the db version , the update db sql execute successfully , but the setVersion is failed . so the next time the update db sql will execute again , and app crashed (duplicate column name) .

 private void openOrUpgrade(int newVersion) {

        database = SQLiteDatabase.openOrCreateDatabase(getAbsDBPath("dbName"), password, null);

        int oldVersion = database.getVersion();
        if (oldVersion != newVersion) {
            try {
                if (oldVersion == 0) {
                    // exec create db sql
                } else {
                    if (oldVersion < newVersion) {
                        // exec update db sql
                       // mostly like "ALTER TABLE  tableName ADD newFiled TEXT"
                //update version

            } catch (Exception e) {
                Log.e("TAG", "create or upgrade database error=" + e.getMessage(), e);
            } finally {


Hi @RubinChen

What is the exact value you are attempting to store as the version? Are you able to recreate the behavior within the SQLCipher for Android test suite?


The exact value is int , eg: 5 (the really value in my code) .
I can’t recreate this case during development , but not try with the SQLCipher for Android test suite .
That has happened five times in the past year .(from user feedback).


Hello @RubinChen

I just added a new test to the suite here which exercises the PRAGMA user_version feature. You may need to investigate your application logic further. We would need more information to provide any further feedback.


Thanks , I will tell you if have more information 。