Alternative way of addressing elements of a structure?

Just starting out? Need help? Post your questions and find answers here.
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Alternative way of addressing elements of a structure?

Post 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....
PB 5.73 on Windows 10 & OS X High Sierra
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3943
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Alternative way of addressing elements of a structure?

Post 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)
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: Alternative way of addressing elements of a structure?

Post 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.... :(
PB 5.73 on Windows 10 & OS X High Sierra
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3943
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Alternative way of addressing elements of a structure?

Post 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 ?
Windows (x64)
Raspberry Pi OS (Arm64)
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Alternative way of addressing elements of a structure?

Post by citystate »

would using an array of pointers work for you?
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
fabulouspaul
User
User
Posts: 34
Joined: Sun Nov 23, 2014 1:18 pm

Re: Alternative way of addressing elements of a structure?

Post by fabulouspaul »

How about using a SQLite-database in memory and accessing the data with SQL-commands? [OpenDatabase(#db_handle, ":memory:",..)]
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: Alternative way of addressing elements of a structure?

Post 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).
PB 5.73 on Windows 10 & OS X High Sierra
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: Alternative way of addressing elements of a structure?

Post 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...
PB 5.73 on Windows 10 & OS X High Sierra
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: Alternative way of addressing elements of a structure?

Post 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...
PB 5.73 on Windows 10 & OS X High Sierra
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: Alternative way of addressing elements of a structure?

Post 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...
PB 5.73 on Windows 10 & OS X High Sierra
Post Reply