[Gambas-user] structure and class
T Lee Davidson
t.lee.davidson at gmail.com
Tue Aug 8 23:28:22 CEST 2023
On 8/8/23 12:53, Marco Ancillotti wrote:
> Now , I've made a class that is like:
>
> Public column1 as integer
> Public column2 as string
> Public column3 as Float
> Public column4 as blablabla
>
> I then made an array of that class and push my query result data to that array.
>
> It work but it need a lot of code so I would like to dynamic declare the class looking columns in results so I can
> made a reusable function with different query.
>
> Thanks
> Marco.
I still don't understand why you are complicating things by trying to use a class. Could something like the following suit your
needs?
[code]
Public Sub main()
Dim hConn As Connection = Connections["Connection1"]
Dim hResult As Result
Dim hResultField As ResultField
Dim cRow As New Collection
Dim acRows As New Collection[]
Dim Column As Variant
hConn.Open
hResult = hConn.Exec("select * from `my_table`")
For Each hResult
For Each hResultField In hResult.Fields
cRow[hResultField.Name] = hResult[hResultField.Name]
Next
acRows.Add(cRow.Copy())
Next
hConn.Close
For Each cRow In acRows
For Each Column In cRow
Print Subst("&1: &2, ", cRow.Key, Column);
Next
Print
Next
End
[/code]
--
Lee
More information about the User
mailing list