I'm trying to run a transaction in B4J. When it failes (and is supposed to do a rollback), I receive the following error. I thought SQL.BeginTransaction was supposed to set the autocommit to false? And I don't seem to be able to find a property to regulate this. In the code I've 'created' an error by inserting a record in a non existing table called 'tIdentification2'in the second Query.
DBM.SQLInsertTrans()
Error log:
B4X:
SQL.BeginTransaction
Try
ret = DBM.SQLInsertTrans(SQL, "INSERT INTO tExecutor(OTID, exCode, exDescription, exExTypID, exStatus, exOTCreationTag, exOTLastModifiedLoginID) VALUES(?, ?, ?, ?, ?, ?, ?)", Variables) 'GENTODOC
Variables.Clear
Variables.add(authCurrentMasterID)
Variables.Add(ret)
' generate barcode
Variables.Add(ABMShared.GenerateBarCode(SQL, authCurrentMasterID, "Executor0001BCPrefix"))
Variables.Add(ABMShared.STATUS_OK)
Variables.Add("INSERT_EXECUTORS1_1") 'GENTODOC
Variables.Add(page.ws.Session.GetAttribute("authLoginID2020"))
ret = DBM.SQLInsertTrans(SQL, "INSERT INTO tIdentification2(OTID, idenExID, idenCode ,idenStatus, idenOTCreationTag, idenOTLastModifiedLoginID) VALUES(?, ?, ?, ?, ?, ?)", Variables) ' <--- non-existing table tIdentification.
SQL.TransactionSuccessful
Catch
SQL.Rollback ' <----------- Error
DBM.CloseSQL(SQL)
myToastId = myToastId + 1
page.ShowToast("toast" & myToastId, "toastred", page.XTR("1034","There was an error inserting the record"), 5000)
Return
End Try
DBM.SQLInsertTrans()
B4X:
Sub SQLInsertTrans(SQL As SQL, Query As String, Args As List) As Int 'ignore
Dim res As Int
Select Case DatabaseType
Case 0 ' SQlite
SQL.ExecNonQuery2(Query, Args)
res = SQLSelectSingleResult(SQL, "SELECT last_insert_rowid()", Null)
Case 1 ' MySQL <-------- THIS ONE IS USED
SQL.ExecNonQuery2(Query, Args)
res = SQLSelectSingleResult(SQL, "SELECT LAST_INSERT_ID()", Null)
Case 2 ' MSSQL
Dim ABSQL As ABSQLExt
res = ABSQL.ExecNonQuery3(SQL, Query, Args)
End Select
Return res
End Sub
Error log:
B4X:
Error occurred on line: 611 (ExecutorsPage1)
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Can't call rollback when autocommit=true
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.Util.getInstance(Util.java:387)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:862)
at com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:4617)
at com.mchange.v2.c3p0.impl.NewProxyConnection.rollback(NewProxyConnection.java:860)
at anywheresoftware.b4j.objects.SQL.Rollback(SQL.java:423)
at com.onetwo.prog2100.executorspage1._executors1save_clicked(executorspage1.java:1056)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:462)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:417)
at com.onetwo.prog2100.executorspage1._page_parseevent(executorspage1.java:1303)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$1.run(WebSocketModule.java:126)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:111)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:131)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:301)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at com.onetwo.prog2100.main.main(main.java:29)