Page 1 of 1
Alternative way of addressing elements of a structure?
Posted: Thu Oct 26, 2017 6:35 pm
by kpeters58
Is there an alternative way of addressing elements of a structure, such as indexing into it like with an array?
So rather than doing (pseudo code)
Structure WideDatabaseRecord
Column1.s
;...
Column200.s
EndStructure
NewList VirtualRecords.WideDatabaseRecord()
; select * from WideTable
VirtualRecord\Column1 = GetDatabaseString(1)
; ...
VirtualRecord\Column200 = GetDatabaseString(200)
I could loop though the structure elements assigning column values to them rather than having 200 lines of repetitive code....
Re: Alternative way of addressing elements of a structure?
Posted: Thu Oct 26, 2017 7:18 pm
by wilbert
Array inside structure ?
Code: Select all
Structure WideDatabaseRecord
Array Column.s(200)
EndStructure
a.WideDatabaseRecord
a\Column(1) = "column 1"
a\Column(2) = "column 2"
Debug a\Column(2)
Re: Alternative way of addressing elements of a structure?
Posted: Fri Oct 27, 2017 3:24 am
by kpeters58
wilbert wrote:Array inside structure ?
Code: Select all
Structure WideDatabaseRecord
Array Column.s(200)
EndStructure
a.WideDatabaseRecord
a\Column(1) = "column 1"
a\Column(2) = "column 2"
Debug a\Column(2)
That would only work if all database columns were of the same type....

Re: Alternative way of addressing elements of a structure?
Posted: Fri Oct 27, 2017 5:40 am
by wilbert
kpeters58 wrote:That would only work if all database columns were of the same type....

Can you give a bit more information about how a record looks and what types you need to use for the columns ?
Re: Alternative way of addressing elements of a structure?
Posted: Mon Oct 30, 2017 1:06 am
by citystate
would using an array of pointers work for you?
Re: Alternative way of addressing elements of a structure?
Posted: Mon Oct 30, 2017 11:37 am
by fabulouspaul
How about using a SQLite-database in memory and accessing the data with SQL-commands? [OpenDatabase(#db_handle, ":memory:",..)]
Re: Alternative way of addressing elements of a structure?
Posted: Wed Nov 01, 2017 3:24 am
by kpeters58
wilbert wrote:kpeters58 wrote:That would only work if all database columns were of the same type....

Can you give a bit more information about how a record looks and what types you need to use for the columns ?
I typically use SQLite's INTEGER & TEXT storage classes only (very rarely BLOBs as well).
Re: Alternative way of addressing elements of a structure?
Posted: Wed Nov 01, 2017 3:25 am
by kpeters58
fabulouspaul wrote:How about using a SQLite-database in memory and accessing the data with SQL-commands? [OpenDatabase(#db_handle, ":memory:",..)]
Hmm - interesting suggestion. Hadn't thought about that one yet...
Re: Alternative way of addressing elements of a structure?
Posted: Wed Nov 01, 2017 3:25 am
by kpeters58
fabulouspaul wrote:How about using a SQLite-database in memory and accessing the data with SQL-commands? [OpenDatabase(#db_handle, ":memory:",..)]
Hmm - interesting suggestion. Hadn't thought about that one yet...
Re: Alternative way of addressing elements of a structure?
Posted: Wed Nov 01, 2017 3:25 am
by kpeters58
fabulouspaul wrote:How about using a SQLite-database in memory and accessing the data with SQL-commands? [OpenDatabase(#db_handle, ":memory:",..)]
Hmm - interesting suggestion. Hadn't thought about that one yet...