SQLite - Checking for a duplicate entry before adding it
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
SQLite - Checking for a duplicate entry before adding it
I have a function that will add a new entry to a table in my SQLite database. I would like to add to the function some kind of SQL query that I use to check to see if I am adding a duplicate entry before doing so. Is there a query I can perform to search the table based on a few columns to return the number of matches?
Re: SQLite - Checking for a duplicate entry before adding it
Are you saying that you are able to do an INSERT in SQL... but you don't know how to do a... SELECT ? !
Anyway. Make a simple SELECT on your column, before to do the INSERT, to check.
Some people would advise you to put your insert function in a TRY CATCH structure.
http://forums.runrev.com/phpBB2/viewtop ... f=7&t=9418
You can even add some "fuzyness" (because a "duplicate" for human, is not a always a "duplicate" for computer... spelling mistakes, typos etc.) with "LIKE" (and wildcard %), in order to make a warning for the user before the insert.

Anyway. Make a simple SELECT on your column, before to do the INSERT, to check.
Code: Select all
put "SELECT * from mytable where name='"&newEntry&"'"
http://forums.runrev.com/phpBB2/viewtop ... f=7&t=9418
You can even add some "fuzyness" (because a "duplicate" for human, is not a always a "duplicate" for computer... spelling mistakes, typos etc.) with "LIKE" (and wildcard %), in order to make a warning for the user before the insert.
Code: Select all
put "SELECT * from mytable where name like '%"&newentry&"%'" into tSQL
Re: SQLite - Checking for a duplicate entry before adding it
Not exactlybangkok wrote:Are you saying that you are able to do an INSERT in SQL... but you don't know how to do a... SELECT ? !
![]()

I found this function to be useful, where tSQL is the SELECT argument:
Code: Select all
put revQueryDatabase(tDatabaseID, tSQL) into theCursor
put revNumberOfRecords(theCursor) into numRecords