Android Question v6.80 and SQL crash?

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Since upgrading to 6.80 I have gotten a few "Don't have database lock! crashes

B4X:
Screen Size: X(320)  Y(533)  Scale:1.5

OSVersion:4.0.4  API:15


java.lang.IllegalStateException: Don't have database lock!
  at android.database.sqlite.SQLiteDatabase.verifyLockOwner(SQLiteDatabase.java:2090)
  at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:690)
  at anywheresoftware.b4a.sql.SQL.EndTransaction(SQL.java:269)
  at com.BOBs.BBS.csystemrecord._addupdate(csystemrecord.java:112)
  at com.BOBs.BBS.csubscriptions._dosubscriptions(csubscriptions.java:673)
  at com.BOBs.BBS.starter._startup_alldone(starter.java:1298)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.hooks.Hooks.java_lang_reflect_Method_VTinvoke(Hooks.java:6451)
  at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
  at anywheresoftware.b4a.keywords.Common$5.run(Common.java:996)
  at android.os.Handler.handleCallback(Handler.java:605)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:199)
  at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:168)
  at anywheresoftware.b4a.keywords.Common.DoEvents(Common.java:388)
  at com.BOBs.BBS.cpleasewait._showpleasewait(cpleasewait.java:475)
  at com.BOBs.BBS.main._createscreen(main.java:745)
  at com.BOBs.BBS.main._activity_resume(main.java:524)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.hooks.Hooks.java_lang_reflect_Method_VTinvoke(Hooks.java:6451)
  at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
  at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
  at com.BOBs.BBS.main.afterFirstLayout(main.java:109)
  at com.BOBs.BBS.main.access$000(main.java:17)
  at com.BOBs.BBS.main$WaitForLayout.run(main.java:80)
  at android.os.Handler.handleCallback(Handler.java:605)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:137)
  at android.app.ActivityThread.main(ActivityThread.java:4424)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  at dalvik.system.NativeStart.main(Native Method)
java.lang.IllegalStateException: Don't have database lock!
  at android.database.sqlite.SQLiteDatabase.verifyLockOwner(SQLiteDatabase.java:2090)
  at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:690)
  at anywheresoftware.b4a.sql.SQL.EndTransaction(SQL.java:269)
  at com.BOBs.BBS.csystemrecord._addupdate(csystemrecord.java:112)
  at com.BOBs.BBS.csubscriptions._dosubscriptions(csubscriptions.java:673)
  at com.BOBs.BBS.starter._startup_alldone(starter.java:1298)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.hooks.Hooks.java_lang_reflect_Method_VTinvoke(Hooks.java:6451)
  at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
  at anywheresoftware.b4a.keywords.Common$5.run(Common.java:996)
  at android.os.Handler.handleCallback(Handler.java:605)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:199)
  at anywheresoftware.b4a.Msgbox.msgbox(Msgbox.java:138)
  at anywheresoftware.b4a.specci48.spdialogs.SPDialogs$Msgbox3.Show(SPDialogs.java:54)
  at com.BOBs.BBS.cgenfuncs._msgboxwithreply(cgenfuncs.java:1274)
  at com.BOBs.BBS.main._error_msgbox(main.java:1133)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.hooks.Hooks.java_lang_reflect_Method_VTinvoke(Hooks.java:6451)
  at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
  at anywheresoftware.b4a.keywords.Common$5.run(Common.java:996)
  at android.os.Handler.handleCallback(Handler.java:605)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:199)
  at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:168)
  at anywheresoftware.b4a.keywords.Common.DoEvents(Common.java:388)
  at com.BOBs.BBS.cpleasewait._showmessage(cpleasewait.java:410)
  at com.BOBs.BBS.main._starterprogress(main.java:1788)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.hooks.Hooks.java_lang_reflect_Method_VTinvoke(Hooks.java:6451)
  at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
  at anywheresoftware.b4a.keywords.Common$5.run(Common.java:996)
  at android.os.Handler.handleCallback(Handler.java:605)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:137)
  at android.app.ActivityThread.main(ActivityThread.java:4424)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  at dalvik.system.NativeStart.main(Native Method)

I am looking at my csystemrecord.addupdate code (that hasn't changed in years)

Just wondering if anything changed in 6.80 with SQL


The routine that is being executed is below
.

B4X:
public  Sub AddUpdate As Boolean

  If mRecordID = 0 Then
  cDatabase.SQLDatabase.BeginTransaction

  mSQLStatement = "INSERT into " &DEFINE_DB_SystemTableName &" DEFAULT VALUES "

  '------------------------------------------------------------------------------------------------------
  '  Insert the New record
  '------------------------------------------------------------------------------------------------------
  Try
  cDatabase.SQLDatabase.ExecNonQuery(mSQLStatement)
  cDatabase.SQLDatabase.TransactionSuccessful
  cDatabase.SQLDatabase.EndTransaction

  '---------------------------------------------------------------------------------------------------
  '  Retrieve the RecordID for the last record just Added
  '---------------------------------------------------------------------------------------------------
  mRecordID = cDatabase.SQLDatabase.ExecQuerySingleResult("SELECT max(RecordID) FROM " &DEFINE_DB_SystemTableName)

'  If mPrinterMacAddress.Length = 0 Then
'  mPrinterMacAddress  = "2C:27:D7:A2:8B:50"
'  End If
  Catch
            #If Debug
  Log(LastException.Message)
          #End If
           
            CallSubDelayed3("Main", "Error_MsgBox", LastException.Message, "Database Error SystemRecord-001")         

  cDatabase.SQLDatabase.EndTransaction
  Return False
  End Try
  End If


  mSQLStatement = "UPDATE " &DEFINE_DB_SystemTableName &" SET " &DEFINE_DB_TagSystemFlags1  &"="  &mFlags1  &", "  _
  &DEFINE_DB_TagSystemFlags2  &"=""" &mFlags2  &""", "  _
  &DEFINE_DB_TagSystemNextDBCount  &"="  &mNextDBCount  &", "  _
  &DEFINE_DB_TagSystemPrinterMacAddress &"=""" &mPrinterMacAddress  &""", "  _
                                      &DEFINE_DB_TagSystemPrinterName      &"=""" &mPrinterName      &""", "  _
  &DEFINE_DB_TagSystemLastImportedPath  &"=""" &mLastImportedPath  &""", "  _                                       
  &DEFINE_DB_TagSystemPrinterIPAddress  &"=""" &mPrinterIPAddress  &""", "  _                                       
  &DEFINE_DB_TagSystemPrinterIPUserID  &"=""" &mPrinterIPUserID  &""", "  _                                       
  &DEFINE_DB_TagSystemPrinterIPPwd  &"=""" &mPrinterIPPwd  &""", "  _                                       
  &DEFINE_DB_TagSystemPrinterIPPort  &"=""" &mPrinterIPPort  &""", "  _                                       
  &DEFINE_DB_TagSystemMacAddress    &"=""" &mMacAddress      &""", "  _                                                                             
                                      &DEFINE_DB_TagSystemReusePerformed  &"="  &mReusePerformed  &"  "  _
  &" where " &DEFINE_DB_TagSystemRecordID &"=" &mRecordID


  cDatabase.SQLDatabase.BeginTransaction

  Try
  cDatabase.SQLDatabase.ExecNonQuery(mSQLStatement)
  cDatabase.SQLDatabase.TransactionSuccessful
  cDatabase.SQLDatabase.EndTransaction

  Return True
  Catch
         #If Debug
  Log(LastException.Message)
         #End If
         
         CallSubDelayed3("Main", "Error_MsgBox", LastException.Message, "Database Error SystemRecord-002")
         
  cDatabase.SQLDatabase.EndTransaction
  Return False
  End Try
End Sub
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
The reason for the DoEvents is that I have a window showing "Please Wait" where I update labels showing what is going on.

If I do not do the DoEvents changing the text in the labels does not always show up

I only call DoEvents when I want something to appear on the screen while I am still in the routine

If there is a better way to get the labels to update while still in the routine I am interested.
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Slow? Relative term.

It's not necessary slow, but I am doing a lot of different things like:
1) Loading players
2) Pairing Players
3) Seating Players
4) Generating matchups

When Loading and Pairing my Please Wait is up and it says something like
Please Wait
Loading Players
<Player Name>

Similar for the Pairing / Seating

I know my users and they Like seeing the Name changes as processing occurs and if I don't call DoEvents sometimes you only see one name or two name changes of 50 or 100 names and it's done (or at least that's how it was on previous versions). Now I understand that calling DoEvents is slowing things down but my users like the feedback.

I am just calling it do update the UI as processing records / data

Is there an easier way to update the UI while looping records? I just want the display to change.

BobVal
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Other than the ones in T8TextSize that is the only one I have but it is in my PleaseWait routine - will try and restructure the code
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…