Here is my table schema:
downloadstbl
_id int not null auto
url text not null
filename text not null
date text not null)
I would like to insert a row only if there isnt a row in the table already with the same url.
E.g, if the following row exists:
_id=1
url="http://google.com/img.jp"
filename="img.jp"
date="11/03/2012"
then if I try to insert another row that has url=”http://google.com/img.jp” the sql statement will not insert to avoid duplicate rows for the same remote file.
I know I could probably do this by first doing a SELECT and checking for whether a row already exists, however I would like to check if this is possible at the point of insertion to make things more robust/clean.
First of all, I would add the
UNIQUEkeyword to theurlcolumn.Then, when inserting, use this
INSERT OR IGNOREinstead ofINSERT.