12-05-2019, 07:30 PM
(This post was last modified: 12-05-2019, 07:33 PM by JereMiami.)
I am not understanding cdb_sync. This is really the only function that I do not understand and I believe it is probably the most useful of them all. So any help would be greatly appreciated!
In the documentation for the command, it says:
--
Summary
This function will sync all records in a specified table between local and cloud.
--
My question is: What is a local table? Is this a field or datagrid on a card? Do I export this table from the cloud to my local Livecode project? Or, do I create this local table from scratch and, if so, do all rows and columns have to match? I guess what I am asking is what constitutes a local table?
Many thanks in advance!
Hi JereMiami,
A table is just an internal container for a collection of records. Tables exist both on the device, "local", and on the cloud, "cloud". Records can be in a "local" table, a "cloud" table, or both. A table can be created through LCM or with cdb_createTable.
A lot of the APIs have a pTarget parameter that can either be "local" or "cloud", this specifies whether the API should be performed on a "local" table or a table on the "cloud". Let's use cdb_create(pDataA, pTable, pTarget, pInternalA) and cdb_update pDataA, pTable, pRecordID, pTarget, pInternalA as an example.
If we pass "local" to cdb_create, the record will be stored on the device itself. If we pass "cloud", the record will be sent to our servers where it'll be stored. If we create a record on the cloud, there is no "local" record. This means that if we want to update the record, we need to pass "cloud" to cdb_update as well so the record on the cloud can be updated.
cdb_sync can copy the record from the "cloud" table to the "local" table. This allows us to modify the record on the device, without the need to wait for a network transaction. This means we can modify the "local" record all we want, faster than modifying the "cloud" record since there is no wait, then copy it back to the cloud using cdb_sync again when we choose to.
Sorry for the long response. Hopefully I answered your questions. Let me know if you need further clarification.
Excellent response. Thank you!
Yes, it's only possible to create databases in the cloud but records can be created locally or in the cloud. cdb_sync and cdb_batchSync are used to sync records between local and cloud. If you use cdb_create and pass "local" to it, the record will be created on the device. You can then use cdb_sync to upload this record to the cloud.
The location needs to be writable to create local records.
Can you elaborate more on what you mean by "maintaining" a local database?