1

I want to sync data between android SQLite database and MySQL database offline/online from multiple users???

I have two tables

  1. For User details
  2. For their queries

I tried by saving data to SQLite first and then send it to the server but there is data confliction. how can I manage unique id to that particular table matched with the SQLite database? Suppose,

  1. I have inserted a query from User A. it is saved in SQLite DB and sent to the server after being online. so primary key id is 1 and is the same for MySQL & SQLite.
  2. Now User B also submits his query. it is also saved in SQLite DB and sent to the server. so here is also primary key id is 1. Now it will give error as it is going against the primary key as it is the same id as already stored in the server.

So, now how can I avoid data confliction. Remember I am creating an app for offline and online both. when the internet is not available, it will be saved to SQLite and after being online it will be saved to MySQL server.

Any suggestion or any way would be appreciable.

2 Answers 2

2

In Mysql Table Create one more Column with Auto increment and make it a primary key.

Sign up to request clarification or add additional context in comments.

Comments

0

Use a timestamp including milliseconds and the users login ID as the key this way it is always unique even if the users both post at the same exact time. EG primary ID of 201910190859123451 when the time and date is 2019-10-19 08:59:12:345 and the users ID is 1 however you will need to make your primary ID into a big int.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.