Android Question List add multiple columns

padvou

Active Member
Licensed User
Longtime User
Hello,
I have an sql query that returns 4 columns.
How can i add the data to a list so that each row in the list is a record from the result of the query but the list will also reflect the 4 columns?
 

LucaMs

Expert
Licensed User
Longtime User
1604072162314.png


Registered since 2012 and still not able to use the site's search function?

These are topics discussed 1,000 times!

Sorry but, personally, I refuse to answer in a case like this.
(and maybe today I'm a little too nervous)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Define a Type, create an instance for each row add it to the list. You can then easily sort the data on any column using the List SortType Methods.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
How can i add the data to a list so that each row in the list is a record from the result
You create a Type, like this ...
B4X:
Type sectionRec (id As Int, title As String, row As Int)
B4X:
Then you transfer the data from each SQL record to a new object like this ...
B4X:
Public Sub getSections(pageId As Int) As List
    Dim cur As ResultSet
    Dim result As List
    result.Initialize
    cur = dB.ExecQuery(SQL_SELECT_SECTIONS & pageId & " ORDER BY Row")
    Do While cur.NextRow
        Dim s As sectionRec
        s.Initialize
        s.Id = cur.GetInt2(0)
        s.title = cur.GetString2(1)
        s.row = cur.GetInt2(2)
        result.Add(s)
    Loop
    Return result
End Sub
I hope that helps.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
DBUtils2.ExecuteMemoryTable (SQL As SQL, Query As String, StringArgs As String, Limit As Int)
Executes the query and returns the result as a list of arrays.
Each item in the list is a strings array.
StringArgs - Values to replace question marks in the query. Pass Null if not needed.
Limit - Limits the results. Pass 0 for all results.
Returns : List
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Another option could be a LOM (list of maps). Each record is returned in a map (key = field; value = data) and each map is added to a list.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Another option could be a LOM (list of maps). Each record is returned in a map (key = field; value = data) and each map is added to a list.

See:
DBUtils2.ExecuteMap(SQL As SQL, Query As String, StringArgs As String)
'Executes the query and returns a Map with the column names as the keys
'and the first record values As the entries values.
'The keys are lower cased.
'Returns an uninitialized map if there are no results.
 
Upvote 0
Top