I am a bit confused concerning how to handle the problem in which you update a row in sqlite whether it is available, or place it whether it does not. I appear to determine another solution on every answer there's for this problem. What is the best or simplest way? EDIT: I meant sqlite, sorry
CREATE TABLE foo (bar INTEGER UNIQUE, baz INTEGER) INSERT INTO foo (bar,baz) VALUES (1, 2)
This will cause an IntegrityError: column bar isn't unique:
INSERT INTO foo (bar,baz) VALUES (1,3)
INSERT OR REPLACE INTO foo (bar,baz) VALUES (1,3)
Rather than placing a brand new row, since a row with bar equaling 1 already is available, the need for baz is up-to-date to three.
Produce a UNIQUE index up for grabs. Then use
INSERT INTO table (...) values (...) ON DUPLICATE KEY UPDATE field = ...
CREATE UNIQUE INDEX mytable_index ON mytable (field1,field2) INSERT INTO mytable (field1,field2,field3) values (val1,val2,val3) ON DUPLICATE KEY UPDATE field3 = val3
This involves that (field1,field2) pairs in mytable be unique.
When you place, either you're going to get a brand new row, or, if (val1,val2) already appear in
mytable, the need for field3 is going to be up-to-date.
IF Is available might be useful here, getting you update when the condition yields true or place if false.