sqlcipher/sqlcipher-android-tests

[rawExecSQL] How to handle try catch exception when use rawExecSQL ?

chihung93 opened this issue ยท 5 comments

I'm using this code base on your Unit Test ๐Ÿ‘
https://github.com/sqlcipher/sqlcipher-android-tests/blob/86318cc315836edf5a064de0e35dc5de21e149b2/app/src/main/java/net/zetetic/tests/ClosedDatabaseTest.java

But it doesn't work.

try {
                // should throw IllegalStateException:
                database.rawExecSQL("SELECT 1;");

                // should not get here:
                Log.e(ZeteticApplication.TAG, "SQLiteDatabase.rawExecSQL() did NOT throw exception on closed database");
                return false;
            } catch (IllegalStateException e) {
                Log.v(ZeteticApplication.TAG, "SQLiteDatabase.rawExecSQL() did throw exception on closed database OK", e);
            }

Hi @chihung93

Are you using the latest master of the test suite? I ask because you referenced a specific git blob. Does it crash on a specific emulator/device? If so, what is the Android API version and device you are running where you experience the crash? Thanks!

It crashed because the SQL script was wrong, but I wanted to avoid crashing when running any SQL script.
It happens on any device.

My device :
Zenfone - android 6.0
Jacs - android 5.0

SQL cipher - Version: 3.5.8

Hi @chihung93

That specific test is running through various scenarios where it should throw an exception because the database is closed. Can you try updating to 3.5.9 and try running the test suite on your devices and let us know what you are seeing.

So sorry, this is my fault. I forget to close the database using an IllegalStateException, I have to replace it with SQLiteException and it has worked.
Thanks.

Hello @chihung93

We are happy everything is working properly for you now. Take care!