I'm trying to update the database in my application. Trying to simulate a possible production error intentionally I give DROP
to a table, and then I make a SELECT
in the same table and it works. When changing Activity the same procedure is performed, but this time the error happens.
The following steps are performed:
Load LoadScreenActivity
Performs the onUpgrade()
, if necessary, which copies the new asset base.
If onUpgrade()
is called it runs procedimento()
to check if the database is corrupted, as I did not find a way to corrupt the database so I can use PRAGMA integrity_check
, so I delete the table messages only to simulate the error.
I call testar()
to check the integrity of the database.
public boolean procedimento() {
(...)
database.execSQL("DROP TABLE mensagens");
return testar();
}
public boolean testar() {
try {
database.rawQuery("SELECT COUNT(*) FROM mensagens ORDER BY RANDOM()", new String[]{});
return true;
catch(Exception e){
return false;
}
}
When I start the next Activity (in this case the MainActivity
) and do the same SELECT
...
Caused by: android.database.sqlite.SQLiteException: no such table: messages:, while compiling: SELECT COUNT (*) FROM messages ORDER BY RANDOM ()
Why does not the error immediately happen in the Activity ?