SQL INSERT or UPDATE
I am trying to accomplish what is normally a fairly simple SQL query, and having troubles getting it to work. My INSERT query works fine:
db.execute('INSERT INTO ' + tableName + ' (ID, DISPLAY ) VALUES(?,?)', displayOptionName, displayOptionValue);
But when I try the INSERT UPDATE version it doesn't work:
db.execute('INSERT INTO ' + tableName + ' (ID, DISPLAY ) VALUES(?,?) ON DUPLICATE KEY UPDATE DISPLAY = ?', displayOptionName, displayOptionValue, displayOptionValue);
I dare say I have just typed something wrong, but it is a little frustrating, the Kitchen Sink 3 examples dont seem to show this query in all it's glory. Is there a better way to get around the problem?
1 Answer
-
Ok, for others, a good link to use is: http://www.sqlite.org/lang_insert.html
Just make sure you set up your database fields rrectly in the first place (PRIMARY KEY)