Android Question Map & Array, which one is easier to process?

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

I need to store sql table structure. Using a map, with this declaration
B4X:
Sub Globals
    Private Fields() As Map
    Private Tables() As Map
End Sub

Fields = Array As Map (InitFields("ID",3),InitFields("DT",1),InitFields("FRM_N",1))
Tables = Array As Map(InitTables("MEM_FRM",Fields))

Or using Custom Type and array
B4X:
Sub Globals
    Type Field(Nm As String,Typ As Byte)
    Type Table(Nm As String,Field() As Field)
    Private Fields() As Field
    Private Tables() As Table
End Sub

Fields = Array As Field(InitFields("ID",3),InitFields("DT",1),InitFields("FRM_N",1))
Tables = Array As Table(InitTables("MEM_FRM",Fields))

Which one is easier to process, such as retrieve its value, delete, update, etc.
 

sorex

Expert
Licensed User
Longtime User
as @Erel already mentioned it all depends on what you want to do with it.

if you just want to list data you could store your data in a list or array.

if you want to keep track of IDs or use them for easy access you could use maps and use the ID as the key and the custom type as data.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Hi,

Thanks for your replied.

I want to use it to create Sub that will able to store/sent data from/to RDC into/from sqlite table.

For each data retrieve from RDC, I need to write a different Sub since this data will store in different sqlite table.

Using this structure, I will only need to create 1 Sub (with this structure as parameter) that will able to store data to any of sqlite table I want.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I have tested, for me, it was easier using Array.

Declaration is more user friendly. Look at these codes
B4X:
'Using array
Private Nm = Tables(0).Nm as String
Private Fields() as Field
Fields= Tables(0).Fields

'Using Map
Private Nm = Tables(0).GetKeyAt(0) as String
Private Fields() As Map
Fields= Tables(0).GetValueAt(0)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
it depends how you structure things

if you just fill a map with the right info you could do it like this

B4X:
Type user (name as string,age as int)
dim u as user
u=mUsers.get(userid) 'get specific user info based on its ID from a usermap
log(u.name &" "& u.age)
 
Last edited:
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Key is dynamic, I don't know its value, I have to use GeyKeyAt to get the key name.

The idea is, send table structure & its value to a Sub & Sub returns SQL scripts.
 
Upvote 0
Top