Michele Pradella <michele.prade...@selea.com> wrote: > Hi all, I have to INSERT a row in a DB but I have first to check if the > Key I'm inserting already exist. > Now I'm doing a "SELECT count..." first to check if the key exist and > then INSERT or UPDATE records. > Do you know if there's a better or faster way to do that? > Perhaps with an ON CONFLICT <http://www.sqlite.org/lang_conflict.html> > resolution algorithm of INSERT or UPDATE?
See if you can set your table up for INSERT OR REPLACE, as Simon describes. If for some reason you cannot, do an UPDATE first, use sqlite3_changes to see if any rows were actually affected, and if not do INSERT. This saves you a SELECT. -- Igor Tandetnik _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users