• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Primary Key (cdbRecordId)
#1
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!
  Reply
#2
Yes. The record ID must conform to the UUID form as supported by LiveCode.
  Reply
#3
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
  Reply
#4
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
   local tTableDataA, tDataA, tTarget, tTableName, tID
  
   put "dashboard" into tTableName
   put "cloud" into tTarget
  
   put cdb_read("dashboard", "*", "cloud") into tTableDataA                                  
  
   repeat for each element tElement in tTableDataA
      put tElement["primaryKey"] into tDataA["cdb"]["cdbRecordID"]
      put tElement["cdb"]["cdbRecordID"] into tID
      
      cdb_update tDataA,tTableName,tID, tTarget
   end repeat
  
end mouseUp

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!
  Reply
#5
Hi Stam,

This operation is not permitted. Once a record has been created, its cdbRecordID cannot be modified.
  Reply
#6
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
  Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)