Hello!
I have a complex problem. I process JSON data in the background in a service and insert it into two SQLite tables. It works perfectly.
I would like to do the same task, but instead of putting the data to be modified in its final place, I create two temp tables, put the data in them, and then delete the contents of the original tables, insert the new data, and delete the temp tables. It seems to work.
While json processing I am in the main app. When I open another activity (named menu), a very strange error occurs, one I've never seen before.
But there are more complex error log also:
However, when I close my app completely and start again, everything is fine.
It appears to be an SQL-related error, but I'm not sure.
My original code. The error happen when updatetype = "replace":
What would be the problem?
thanks in advance
Steven
I have a complex problem. I process JSON data in the background in a service and insert it into two SQLite tables. It works perfectly.
I would like to do the same task, but instead of putting the data to be modified in its final place, I create two temp tables, put the data in them, and then delete the contents of the original tables, insert the new data, and delete the temp tables. It seems to work.
While json processing I am in the main app. When I open another activity (named menu), a very strange error occurs, one I've never seen before.
B4X:
** Activity (main) Pause, UserClosed = false **
Activity onResume set 03/29 isbaping packagename: com.iqom.enyugta.glass
smart_link is not supported!!!
register: id=1a800000501
** Activity (menu) Create (first time) **
JOGOSULTSÁG: REPOHAR false
** Activity (menu) Resume **
[B]Thread[6,tid=8544,WaitingInMainSignalCatcherLoop,Thread*=0xf0acb400,peer=0x13440000,"Signal Catcher"]: reacting to signal 3
Wrote stack traces to tombstoned[/B]
B4X:
Activity onResume set 03/29 isbaping packagename: com.iqom.enyugta.glass
smart_link is not supported!!!
... lot of repeated lines seen above ...
[B]Activity onResume set 03/29 isbaping packagename: com.iqom.enyugta.glass
smart_link is not supported!!![/B]
--------- beginning of crash
FATAL EXCEPTION: main
Process: com.iqom.enyugta.glass, PID: 7730
java.lang.RuntimeException: Unable to stop service com.iqom.enyugta.glass.svchatter@a28a4c4: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at android.app.ActivityThread.handleStopService(ActivityThread.java:4473)
at android.app.ActivityThread.access$1900(ActivityThread.java:260)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1998)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7945)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:603)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:258)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at com.iqom.enyugta.glass.svchatter.onDestroy(svchatter.java:119)
at android.app.ActivityThread.handleStopService(ActivityThread.java:4449)
... 8 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at com.iqom.enyugta.glass.websocketserverwrapper._stopserver(websocketserverwrapper.java:203)
at com.iqom.enyugta.glass.svchatter._service_destroy(svchatter.java:1825)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
... 11 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/iqom/enyugta/glass/websocketserverwrapper$WebSocketServerWrapper$$ExternalSyntheticLambda0;
at com.iqom.enyugta.glass.websocketserverwrapper$WebSocketServerWrapper.stop(websocketserverwrapper.java:357)
... 17 more
Caused by: java.lang.ClassNotFoundException: com.iqom.enyugta.glass.websocketserverwrapper$WebSocketServerWrapper$$ExternalSyntheticLambda0
... 18 more
It appears to be an SQL-related error, but I'm not sure.
My original code. The error happen when updatetype = "replace":
B4X:
public Sub FeldolgozTermekJSON(jsonText As String) As String
Private res As String = ""
Private cikkcsop As String = "cikkcsop_temp"
Private cikkt As String = "cikkt_temp"
Try
' 1. Parse JSON
Dim parser As JSONParser
parser.Initialize(jsonText)
Dim root As Map = parser.NextObject
Dim updatetype As String = root.GetDefault("updatetype", "replace") ' alapértelmezés: nem fűz
Dim data As List = root.Get("data")
If updatetype = "replace" Then
' 2. Létrehoz ideiglenes táblákat
CreateTempTables
Else
'update esetén az eredeti táblákban dolgozom
cikkcsop = "cikkcsop"
cikkt = "cikkt"
End If
' 3. Végigmegy az itemgroupokon
Private csopazon As Int = 1
Private cikkid As Int = 1
For Each entry As Map In data
Dim itemgroups As List = entry.Get("itemgroup")
For Each group As Map In itemgroups
Dim groupname As String = group.Get("name")
If updatetype = "update" Then
'meg kell keresnem a groupname-t a cikkcsopban
Private csazon As Object = SQL1.ExecQuerySingleResult2($"
SELECT azon
FROM cikkcsop
WHERE lower(megnevezes) = ?"$,Array As String(groupname.ToLowerCase))
If IsNumber(csazon) Then
csopazon = csazon
Log($"Létező cikkcsoport: ${groupname}, azon:${csopazon}"$)
Else
'nincs ilyen cikkcsoport
csopazon = SQL1.ExecQuerySingleResult($"
select max(coalesce(cast(azon as integer),0))+1
from cikkcsop
"$)
Log($"Új cikkcsoport: ${groupname}, azon:${csopazon}"$)
' Beszúrás a cikkcsop-ba
SQL1.ExecNonQuery2($"INSERT INTO ${cikkcsop} (azon, megnevezes) VALUES (?, ?)"$, Array As String(csopazon, groupname))
End If
Else
' Beszúrás a cikkcsop_temp-be
SQL1.ExecNonQuery2($"INSERT INTO ${cikkcsop} (azon, megnevezes) VALUES (?, ?)"$, Array As String(csopazon, groupname))
End If
' Items
Dim items As List = group.Get("items")
For Each item As Map In items
Private ujme As String = mertekegysegvalt(item.GetDefault("unit","OWN"),False)
Private ujmentak As String = mertekegysegvalt(item.GetDefault("NTAKunit","DARAB"),True)
If Codebase.afakodok.GetDefault(item.Get("VAT"),"0") = "0" Then
DobKivetelt("Unknown VAT code:" & item.GetDefault("VAT","???"))
End If
Private insMap As Map
insMap.Initialize
Private whereMap As Map
whereMap.Initialize
If updatetype = "update" Then
'meg kell keresnem a cikkszámot a cikktben
Private cazon As Object = SQL1.ExecQuerySingleResult2($"
SELECT azon
FROM cikkt
WHERE cikkszam = ?"$,Array As String(item.Get("id")))
If IsNumber(cazon) Then
'van már ilyen cikkszám, update lesz
whereMap.Put("cikkszam",item.Get("id"))
Else
'nincs ilyen cikksszám, insert lesz
cikkid = SQL1.ExecQuerySingleResult($"
select max(coalesce(cast(azon as integer),0))+1
from cikkt
"$)
End If
Else
'teljes terméktörzscsere, insert lesz
End If
insMap.Put("csopazon",csopazon)
insMap.Put("cikkszam",item.Get("id"))
insMap.Put("megnevezes",item.Get("name"))
insMap.Put("vtszkodtip",item.Get("navcode").As(Map).Get("type"))
insMap.Put("vtsz",item.Get("navcode").As(Map).Get("code"))
insMap.Put("me",ujme)
insMap.Put("bruttoar",item.Get("pricebrutto"))
insMap.Put("afakod",item.Get("VAT"))
insMap.Put("vonalkod",item.Get("barcode"))
insMap.Put("azon",cikkid)
insMap.Put("fokatjson",item.Get("NTAKmaingroup"))
insMap.Put("alkatjson",item.Get("NTAKsubgroup"))
insMap.Put("ntakme",ujmentak)
insMap.Put("ntakszorzo",item.Get("NTAKmultiplier"))
If whereMap.Size = 0 Then
Private l As List
l.Initialize
l.Add(insMap)
DBUtils.InsertMaps(SQL1,cikkt,L)
Else
DBUtils.UpdateRecord2(SQL1,cikkt,insMap,whereMap)
End If
cikkid = cikkid + 1
Next
csopazon = csopazon + 1
Next
Next
If updatetype = "replace" Then
' 4. Ha ideiglenes táblák feltöltése sikeres, véglegesítés
ReplaceOriginalTables
End If
Log("Sikeres terméktörzs betöltés és csere!")
Catch
If feldhiba.Length > 0 Then
Else
feldhiba = LastException.Message
End If
Log("Hiba a terméktörzs JSON feldolgozás során: " & feldhiba)
res = "Error in processing items JSON: " & feldhiba
End Try
Return res
End Sub
Sub CreateTempTables
'SQL1.BeginTransaction
SQL1.ExecNonQuery("DROP TABLE IF EXISTS cikkcsop_temp")
SQL1.ExecNonQuery("DROP TABLE IF EXISTS cikkt_temp")
MasolatTablaLetrehozasa("cikkcsop")
MasolatTablaLetrehozasa("cikkt")
End Sub
Sub ReplaceOriginalTables
'SQL1.BeginTransaction
Try
SQL1.ExecNonQuery("DELETE FROM cikkcsop")
SQL1.ExecNonQuery("DELETE FROM cikkt")
Log($"Insert előtt:"$ )
Log($"Cikkcsop rekordszám: ${SQL1.ExecQuerySingleResult("SELECT count(*) FROM cikkcsop")}"$ )
Log($"Cikkt rekordszám: ${SQL1.ExecQuerySingleResult("SELECT count(*) FROM cikkt")}"$ )
SQL1.ExecNonQuery("INSERT INTO cikkcsop SELECT * FROM cikkcsop_temp")
SQL1.ExecNonQuery("INSERT INTO cikkt SELECT * FROM cikkt_temp")
SQL1.ExecNonQuery("DROP TABLE cikkcsop_temp")
SQL1.ExecNonQuery("DROP TABLE cikkt_temp")
Log($"Insert után:"$ )
Log($"Cikkcsop rekordszám: ${SQL1.ExecQuerySingleResult("SELECT count(*) FROM cikkcsop")}"$ )
Log($"Cikkt rekordszám: ${SQL1.ExecQuerySingleResult("SELECT count(*) FROM cikkt")}"$ )
'SQL1.TransactionSuccessful
Catch
Log("Hiba véglegesítés közben: " & LastException)
End Try
'SQL1.EndTransaction
End Sub
thanks in advance
Steven
Last edited: