LiveCloud Forums
Function: AddKeys (clarification) - Printable Version

+- LiveCloud Forums (https://forums.livecloud.io)
+-- Forum: General (https://forums.livecloud.io/forumdisplay.php?fid=1)
+--- Forum: Getting Started (https://forums.livecloud.io/forumdisplay.php?fid=4)
+--- Thread: Function: AddKeys (clarification) (/showthread.php?tid=8)



Function: AddKeys (clarification) - Paul - 04-26-2019

This is the example from documentation: https://docs.livecloud.io/AddKeys/ 

Quote:local tTable, tKeys

# Table name: clients
# Keys: firstName, lastName, age, income

put "clients" into tTable
put "occupation,address" into tKeys

cdb_addKeys tTable,tKeys 

It looks like the table, Clients, already has fields, occupation and address, and this command is initializing them as keys. Is this correct?
I'm a little confused by the comment, # Keys: firstName, lastName, age, income. Does that imply these were previously set as keys?

When defining keys in this way, field values are sorted as text. Correct? Are numeric keys currently supported?


RE: Function: AddKeys (clarification) - efrain.c - 04-26-2019

(04-26-2019, 05:52 PM)Paul Wrote: This is the example from documentation: https://docs.livecloud.io/AddKeys/ 

Quote:local tTable, tKeys

# Table name: clients
# Keys: firstName, lastName, age, income

put "clients" into tTable
put "occupation,address" into tKeys

cdb_addKeys tTable,tKeys 

It looks like the table, Clients, already has fields, occupation and address, and this command is initializing them as keys. Is this correct?
I'm a little confused by the comment, # Keys: firstName, lastName, age, income. Does that imply these were previously set as keys?

Hi Paul,

Let's start with the example you quoted. The comments imply that we are starting with a table named "clients" that contains the keys "firstName", "lastName", "age", and "income". The "clients" table does not contain the "occupation" and "address" keys yet.

The cdb_addKeys command adds keys "occupation" and "address" to the "clients" table. After calling cdb_addKeys, as shown in the example, the "clients" table will contains the keys "firstName", "lastName", "age", "income", "occupation", and "address".


[attachment=2]


Quote:When defining keys in this way, field values are sorted as text. Correct?

Can you elaborate? I'm not sure if I'm understanding your question correctly. The image above is a screenshot of a table in LiveCloud Manager (LCM). The first row displays the keys of the table. Subsequent rows are records. Both keys of a table and values of a record are stored as text. Records viewed in LCM can be sorted by any key of the table. Records will be sorted by the text in the value of the chosen key. Hope this helps. Please let me know if I didn't answer your question. 



Quote:Are numeric keys currently supported?

Yes, numeric table keys are supported. Table keys can be alphanumeric. The same goes for key values. Additionally, key values can also be LiveCode arrays.