Primary Key (cdbRecordId) - Printable Version +- LiveCloud Forums (https://forums.livecloud.io) +-- Forum: General (https://forums.livecloud.io/forumdisplay.php?fid=1) +--- Forum: General (https://forums.livecloud.io/forumdisplay.php?fid=3) +--- Thread: Primary Key (cdbRecordId) (/showthread.php?tid=462) |
Primary Key (cdbRecordId) - stamatis - 08-23-2020 A quick question about primary keys (cdbRecordId): Is it possible to supply a primary key (in uuid format) rather than have LiveCloud create it? I ask because i have a number of related tables in SQL i'd like to try importing. If not i'd have to create a fairly complex script that would create a cdbRecordId for the primary table and then have to search/replace this key in all child tables. Would be easier if i could just supply a UUID directly! RE: Primary Key (cdbRecordId) - mark_talluto - 08-23-2020 Yes. The record ID must conform to the UUID form as supported by LiveCode. RE: Primary Key (cdbRecordId) - efrain.c - 08-24-2020 Hi stamatis, Here's an example of how to provide your own cdbRecordID: local tDataA, tTable, tTarget # Table name: clients # Keys: firstName, lastName, age, income put myUUID into tDataA["cdb"]["cdbRecordID"] //replace myUUID with the uuid you want to use for the cdbRecordID put "John" into tDataA["firstName"] put "Smith" into tDataA["lastName"] put "47" into tDataA["age"] put "100000" into tDataA["income"] put "clients" into tTable put "cloud" into tTarget put cdb_create(tDataA,tTable,tTarget) into tRecordID RE: Primary Key (cdbRecordId) - stamatis - 10-19-2020 Hi again Efrain, Thank you for the example - that certainly works. I don't seem to be able to modify the cdbRecordID however? I recently used the import -> csv function in LCM to bulk import some tables from an SQL project where primary/foreign keys were already defined in UUID format. As you know, i wasn't able to import the existing primary keys into the cdbRecordID key as that isn't supported during csv import, so I uploaded them to a new key called primaryKey I was hoping to modify the cdb[cdbRecordID] key to match the primaryKey, but it just seems to fail silently. I'm not sure if it's my code or if this isn't permitted by LiveCloud... Here's the code: Code: on mouseUp pButtonNumber Am i doing something majorly wrong or is this operation not permitted? (i also tried this with batchMerge but got the message 'illegal key' -- but this doesn't seem to happen with update) Many thanks! RE: Primary Key (cdbRecordId) - efrain.c - 10-19-2020 Hi Stam, This operation is not permitted. Once a record has been created, its cdbRecordID cannot be modified. RE: Primary Key (cdbRecordId) - stamatis - 10-20-2020 Hi Efrain - I suspected this was the case but wanted to clarify. Also please note that using cdb_update does not thrown an exception as do other methods (such as cdb_batchMerge) Thanks once again, Stam |