syncdata return value

Discussions about syncing data via Bluetooth, Dropbox, FTP, and using CSWeb
Post Reply
AriSilva
Posts: 605
Joined: July 22nd, 2016, 3:55 pm

syncdata return value

Post by AriSilva »

Hi folks,
I´m using syncdata(get, dict, universe) to transfer cases from the server.
It returns 1 (true) even if the syncdata did not transfer anything.
Is there a way to know the number of cases that were transferred? Maybe it did not transfer anything because I already have the newest cases.
Or, is there a way to know if the universe that I informed in the function has any transferrable cases in the server?
Best
Ari
Best
Ari
Gregory Martin
Posts: 1806
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: syncdata return value

Post by Gregory Martin »

I'm no sync expert, so I try to stay away from sync-related questions, but those who are more knowledgeable about sync are on leave now.

There's no way directly in CSPro logic to get the information that you want, but you can query the SQLite tables (in the CSPro DB file) for details that may give you this information.

I'm going to generalize and assume you're only syncing with one source ... if not, some of these queries will have to account for the "device_id" of the device you're connecting with. I'll also assume you're always syncing both ways ... if not, the queries need to account for the "direction." I'm also going to assume all syncs are done without a universe.

Again, I'm not a sync expert, so I'm not sure that this is 100% accurate, but you can test it and see if it will work for you.

Before your sync, get the last "file_revision" sent to the device:

Code: Select all

SELECT `file_revision` FROM `sync_history` ORDER BY `file_revision` DESC LIMIT 1;
Let's say that this is 17. (If there are no rows, then there have been no syncs.)

Determine how many cases are in your file that have been updated since the last sync:

Code: Select all

SELECT COUNT(*) FROM `cases` WHERE `last_modified_revision` > 17;
If the sync succeeds, this should be the number of cases that are sent to the other device.

Then do your sync. Once complete, rerun that first query:

Code: Select all

SELECT `file_revision` FROM `sync_history` ORDER BY `file_revision` DESC LIMIT 1;
I believe, if you received cases, this would be 18. You can then determine how many cases you received using:

Code: Select all

SELECT COUNT(*) FROM `cases` WHERE `last_modified_revision` = 18;
Again, I'm not 100% sure this is correct, and I haven't tested it. If you try this and it fails, let us know and hopefully someone more knowledgeable than me will be available to respond.
Post Reply