4
I am trying to update the database in my application. Trying to simulate a possible error in production intentionally I give a DROP
in a table, and soon after I do a SELECT
in the same table and works. When changing Activity the same procedure is performed, but this time the error happens.
The following steps are carried out:
Carries the
LoadScreenActivity
Effectuates the
onUpgrade()
, if necessary, which copies the new Assets base.Case
onUpgrade()
be called if theprocedimento()
to check if the database is corrupted, as I did not find a way to corrupt the database to use thePRAGMA integrity_check
, then I delete the table messages just to simulate the error.I call the
testar()
to verify 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 case the MainActivity
) and I do the same SELECT
...
Caused by: android.database.sqlite.Sqliteexception: no such table: messages: while compiling: SELECT COUNT(*) FROM messages ORDER BY RANDOM()
Why the error does not happen immediately in the same Activity?
sorry, but the example is not complete! the business is that NEVER error, never falls in Exception.
– Luiz Carvalho
This code is executed within
onUpgrade()
? Seems to be a problem with transactions.– rodrigorgs
During, but not inside. It’s Running right after you do onUpgrade()
– Luiz Carvalho
Sorry, but for me it became vague whether it is running within onUpgrade or not. Please clarify, preferably including the relevant section of
onUpgrade()
and the passage that callsprocedimento()
.– Piovezan
I edited the text @Piovezan see if it was clearer. Thanks!
– Luiz Carvalho
I know it must be the same, but show the code of the second select... you call
testar()
again?– Piovezan