B4J Question [SOLVED] B4XTable SetData with ExecutList as source. Is it possible?

jroriz

Active Member
Licensed User
Longtime User
I am using a resultset to load a B4XTable as suggested in the post "[B4X] B4XTable - Load data from SQL database".
OK, everything is working fine.

But my first attempt was:

B4X:
    B4XTable1.AddColumn("Jogador", B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.SetData( DBUtils.ExecuteList(Main.Banco, "SELECT jogador FROM resultados", Null, 0) )

which made sense to me, since SetData expects a list and ExecutList returns a list. However, this produces the error below.

Am I doing something wrong or does SetData not allow ExecutList as source?

Waiting for debugger to connect...
Program started.
ExecuteMemoryTable: SELECT jogador FROM resultados
Error occurred on line: 677 (B4XTable)
java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object;
at b4j.example.b4xtable$ResumableSub_SetData.resume(b4xtable.java:463)
at b4j.example.b4xtable._setdata(b4xtable.java:225)
at b4j.example.teste._show(teste.java:51)
at b4j.example.main$ResumableSub_AppStart.resume(main.java:143)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
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:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
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:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:85)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:487)
at anywheresoftware.b4a.keywords.Common.access$0(Common.java:467)
at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:541)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
at java.lang.Thread.run(Thread.java:748)
 

jroriz

Active Member
Licensed User
Longtime User
No. ExecuteList returns a list where each item in the list is a string (single column).
You need to put the items in an array:
B4X:
Dim data As List
data.Initialize
For Each row As String In DBUtils.ExecuteList(Main.Banco, "SELECT jogador FROM resultados", Null, 0)
data.Adda(Array(row))
Next
Would this be possible for multiple columns? (SELECT dtin, jogador, valor FROM resultados)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
yes. make sure to create a array of the correct size (and all Rows having the same columncount (array of same size)).
 
Upvote 0

jroriz

Active Member
Licensed User
Longtime User
yes. make sure to create a array of the correct size (and all Rows having the same columncount (array of same size)).
It seems that I will end up stuck with the code very similar to the link of the post # 1 ...
 
Upvote 0

jroriz

Active Member
Licensed User
Longtime User
You should use DBUtils.ExecuteMemoryTable. You might need to go over the list and modify the arrays. Try it and post the results.
B4X:
    B4XTable1.AddColumn("Dtde", B4XTable1.COLUMN_TYPE_DATE)
    B4XTable1.AddColumn("Jogador", B4XTable1.COLUMN_TYPE_TEXT)

    Dim data As List
    data.Initialize
    For Each row() As String In DBUtils.ExecuteMemoryTable(Main.Banco, "SELECT Dtde, Jogador FROM resultados", Null, 0)
        data.Add(row)
    Next
    
    B4XTable1.SetData(data)

That simple!
 
Upvote 0
Top