Database transactions not working in android

I use the following code, but am experiencing some problems:

mDb.beginTransaction(); String updateQuery ="Query entered here"; String[] valVars = { Variables initialized here }; Cursor c = mDb.rawQuery(updateQuery, valVars); if (c != null) { mDb.setTransactionSuccessful(); mDb.endTransaction(); return true; } else { mDb.endTransaction(); return false; } 

When I use debug instead of running return true , it directly returns return false, even if it is in the else statement. Please tell me what the problem is and how to do it.

+4
source share
1 answer

Use this construct as described in the documentation :

 db.beginTransaction(); try { ... db.setTransactionSuccessful(); } finally { db.endTransaction(); } 
+1
source

Source: https://habr.com/ru/post/1394973/


All Articles