Hi all,
I have modified a DBUTILS routine to return a list :-
A log shows :-
Waiting for debugger to connect...
Program started.
ExecuteListOfMaps: SELECT * FROM Clients
(MyMap) {ID=1, Name=Eunony farming, Phone=null}
(MyMap) {ID=2, Name=Bill Shultz, Phone=null}
(MyMap) {ID=3, Name=G & C Obst, Phone=null}
(ArrayList) [{ID=1, Name=Eunony farming, Phone=null}, {ID=2, Name=Bill Shultz, Phone=null}, {ID=3, Name=G & C Obst, Phone=null}]
Client list =
(ArrayList) [{ID=1, Name=Eunony farming, Phone=null}, {ID=2, Name=Bill Shultz, Phone=null}, {ID=3, Name=G & C Obst, Phone=null}]
I was expecting a list.
The calling code also sees the Arraylist, as shown by the last two lines of the log, here's the code
What have I done wrong? I would prefer to use list, if not how do I access the data from an arraylist (having problems finding this info)?
I have modified a DBUTILS routine to return a list :-
B4X:
' Code based on DBUTILS routines
Public Sub ExecuteListOfMaps(SQL As SQL, Query As String) As List
Dim rs As ResultSet
rs = SQL.ExecQuery(Query)
Log("ExecuteListOfMaps: " & Query)
Dim lst As List
lst.Initialize
Do While rs.NextRow
Dim mp As Map
mp.Initialize
For col = 0 To rs.ColumnCount - 1
mp.Put(rs.GetColumnName(col) ,rs.GetString2(col))
Next
Log(mp)
lst.Add(mp)
Loop
rs.Close
Log(lst)
Return lst
End Sub
A log shows :-
Waiting for debugger to connect...
Program started.
ExecuteListOfMaps: SELECT * FROM Clients
(MyMap) {ID=1, Name=Eunony farming, Phone=null}
(MyMap) {ID=2, Name=Bill Shultz, Phone=null}
(MyMap) {ID=3, Name=G & C Obst, Phone=null}
(ArrayList) [{ID=1, Name=Eunony farming, Phone=null}, {ID=2, Name=Bill Shultz, Phone=null}, {ID=3, Name=G & C Obst, Phone=null}]
Client list =
(ArrayList) [{ID=1, Name=Eunony farming, Phone=null}, {ID=2, Name=Bill Shultz, Phone=null}, {ID=3, Name=G & C Obst, Phone=null}]
I was expecting a list.
The calling code also sees the Arraylist, as shown by the last two lines of the log, here's the code
B4X:
public Sub LoadClients(cb As B4XComboBox)
Main.Clients = DBUtils.ExecuteListOfMaps(Main.SQL1,"SELECT * FROM Clients")
Log($"Client list = "$ )
Log(Main.Clients )
If cb.isInitialized Then cb.cmbBox.Items.Clear
Dim I As Int = 0
Dim mp As Map
mp.Initialize
For I = 0 To Main.Clients.size-1
mp = Main.Clients.get(i)
cb.cmbBox.items.Add(mp.Get("name"))
Next
End Sub
What have I done wrong? I would prefer to use list, if not how do I access the data from an arraylist (having problems finding this info)?