Can Execsql Supports Multiple Sql Statements
Can execSQL supports multiple statements or shall i execute separate commands. My use case is in context of transactions. fun update(id: Long, roles: List): Int? {
Solution 1:
Nope.
execSQL()
only executes single statements. Anything after the first ;
is ignored.
okay, is execSQL known to throw errors, just in case if there's an issue so i can execute rollback, shall I include it in a try catch block?
Yes it can throw exceptions. The canonical pattern for transactions is something along the lines of (Java but the idea is the same in Kotlin):
db.beginTransaction();
try {
// db operations that can throw and should be executed atomically
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
The idea is that endTransaction()
is a rollback unless the transaction is set as successful at the end of the try block.
Post a Comment for "Can Execsql Supports Multiple Sql Statements"