B
B
Bku2019-11-01 14:26:39
MySQL
Bku, 2019-11-01 14:26:39

How to securely sync records between mobile app and MySql database?

The task is simple, but I can not figure out how to make reliable synchronization.
There is a mobile application for android (SQLite). For example, it has a table Table (_id, field, id_base), where id_base - id from the server
base. There is a base (MySql). Table Table (id, field).
Algorithm:
1) In the application, I save the record: _id=1, field="blabla", id_base=0
2) I send it to mySql (via php), it records: id (autoinc) (aka id_base in the application) = 1, field ="blabla"
3) I return id_base to the application in order to write it into a record there and further understand that these records are related.
Everything works well in principle, but except for the case if the save request was sent to the server, the record was saved there, but for some reason the id_base did not reach the application. Therefore, there is no connection between records and next time a new second record in mysql will be created again.
How to organize the work of synchronization to ensure that the records are synchronized?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zhaar, 2019-11-01
@zhaar

Send data by id=1 from the client until the id_base status changes from 0.
On the server, handle such a situation so as not to duplicate already received data (i.e., check for the existence of a record with this id and a non-zero id_base value). If there is such a line, then the server does not touch it, but gives it to the client so that he puts down the id_base for this record.
If the primary record can change during this time, then update it on the server, but do not create a new row, i.e. work with an existing one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question