Android Question SQLite: preventing multiple calls to BeginTransaction

Didier9

Well-Known Member
Licensed User
Longtime User
I have a button which updates an SQLite database using BeginTransaction and EndTransaction.
This phone is slow and it is easy to click on the button again before the previous transaction is complete.

When doing so, the app crashes:
B4X:
java.lang.IllegalStateException: Cannot perform this operation because the transaction has already been marked successful.  The only thing you can do now is call endTransaction().

I could implement locks or use Try/Catch but I wanted to know if there was a more direct way to check if a transaction is in progress?
 

Geezer

Active Member
Licensed User
Longtime User
My first thought was to set a tag on the button when clicked and unset it when the transaction is completed. Check the tag when clicked before performing again.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
I did something like that using a global flag. I was hoping for a readback from SQLite but apparently there isn't one...
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
When doing so, the app crashes:

What about: sql.AddNonQueryToBatch(. FIrst result in this search:
It has a built in begin/end transaction. After you first click the Button, immediately have: btn.enable =false, then when the transaction is successful and complete. enable the button: btn.enable=true
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
What about: sql.AddNonQueryToBatch(. FIrst result in this search:
It has a built in begin/end transaction. After you first click the Button, immediately have: btn.enable =false, then when the transaction is successful and complete. enable the button: btn.enable=true
also use ProgressDialogShow2

ProgressDialogShow2 (Text As CharSequence, Cancelable As Boolean)
Shows a dialog with a circular spinning bar and the specified text.
Unlike Msgbox and InputList methods, the code will not block.
You should call ProgressDialogHide to remove the dialog.
Cancelable - Whether the user can dismiss the dialog by pressing on the Back key.

B4X:
ProgressDialogShow2("Determining GPS Location",False)

'getting GPS info

ProgressDialogHide
 
Upvote 0
Top