Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if SQL query has succeed on Android SQLite

I'm dealing with the execSQL function from Android SQLite API. Since I pass query as a parameter, I execute it straight through this function, so I'm not processing it (and I'd prefer not to do it) to know if we are CREATING, INSERTING, DELETING, ...

The point is: is there any generic way to know if the SQL execution has succeed?

Thank you in advance !

like image 698
USB Avatar asked Feb 23 '23 03:02

USB


2 Answers

execSQL throws SQLException if the SQL string is invalid. You can also wrap your statement into transaction using the model:

   db.beginTransaction();
   try {
     ...
     db.setTransactionSuccessful();
   } finally {
     db.endTransaction();
   }
like image 104
hovanessyan Avatar answered Feb 24 '23 15:02

hovanessyan


I usually wrap my try{...}finally{...} blocks with a listener ( beginTransactionWithListener(SQLiteTransactionListener transactionListener)), and use the transactionListner to check whether everything went well within the transaction, in addition to everything within the try/finally.

like image 23
Chris Cashwell Avatar answered Feb 24 '23 16:02

Chris Cashwell