orbitaloop/WebSqlSync

All rows from server on first sync are sent to server again in second sync

Closed this issue · 3 comments

Hello,

perhaps the issue title is a little bit confusing, but let me explain: My HTML5 Web app is empty at the beginning. Then I call the initSync(), and afterwards a syncNow(). The syncNow() sends no rows to server and the server sends back all current rows from the servers db. Your client code takes all these rows and does an INSERT of all rows into the local websql db. But these INSERTs also triggers your created TRIGGERs and writes all these rows into the table "new_elem".
Here is the problem (or the not so nice thing ;-) ) On the next/second syncNow() call all these rows will be sent again back to the server, but this is actually not necessary, or?!
The same happens for UPDATEs coming from server. The TRIGGERs will be triggered. But they shouldn't when we do INSERTs/UPDATEs from inside your websqlsync code.

IMHO, the TRIGGERs should be disabled during doing the INSERTs/UPDATEs on the data coming from the server, and afterwards they should be enabled again.

But this is not possible in WebSQL. I only found this workaround:
http://sqlite.1065341.n5.nabble.com/how-to-disable-a-trigger-td17010.html

Another solution would be to remove these rows from table "new_elem" after the INSERT/UPDATE was executed.

What do you think? Or is the current behaviour intended?

Best Regards,
Mario

Hi Mario,

Thanks a lot for your message. Sorry about that, this is a bug I introduced in my last Friday's commit :
Before, I was deleting all the new_elem after a sync. But after my latest commit, I only delete the "new_elem" sent to the server, to avoid to loose new or modified elements added in new_elem during the sync (if the user is working on the data, while the sync execute on the background. But it was a bad idea, because of the problem you raised. Desactivating the trigger will do the same as before, and we won't be able to sync in the background, while the user is working on the data...

You can revert the latest commit meanwhile I find a workaround (thanks by the way ;-)

Best regards,
Sam

Ok, I have found a solution, I only delete the new_elem sent to the server or received by the server. I think it's the only way to have the syncronization working on the background.
I just commited the changes.
Please, tell me if you find any problem.
Thanks Mario,

Sam

Thanks.
Your last fix seems to work fine! I think you can close this issue.

Mario