0

I am using SQLite for Phonegap. And I want to insert some data in my table and I want to avoid the duplication of data.

Like I have data from server.

ID      Name
1       ABC
2       DEF
3       GHI
4       JKL
5       MNO

And next time I am getting same values and I want to insert in DB.

ID      Name
1       ABC
2       DEF
3       GHI
4       JKL
5       MNO
6       PQR
7       STU

So there are some few new values and some old like ID 1,2,3,4,5 and some new 6,7,8 So I want to insert just new values 6,7,8 How I can avoid these duplicates.

Arslan Pervaiz
  • 1,575
  • 4
  • 29
  • 62
  • The normal approach would be to pick the column that is the key and which should be unique and then make that an index so that when inserting into the table if there already is a row with that index value, the insert will fail. The approach would really depend on the kind of data involved and whether the database and its tables are stand alone or if you are trying to keep them synchronized with some other database so you need to worry about communication. So where is the data coming from and what is it you are trying to accomplish? Why the need to avoid duplicates? – Richard Chambers Jun 12 '13 at 22:59
  • @RichardChambers: As I described in my question, Im using with phonegap and in select I get callbacks of success and error. Lets say if there is no record there will be no callback of success. and my condition get failed and record will not be inserted – Arslan Pervaiz Jun 13 '13 at 05:16
  • Take a look at this stack overflow on sqlite with phonegap http://stackoverflow.com/questions/5139302/sqlite-database-on-phonegap and good luck. – Richard Chambers Jun 13 '13 at 14:11

0 Answers0