lundi 2 mars 2015

SQLite insert if not exist else increase integer value

I need a way to insert a value if the value doesn't exist and if it does it should increase that value by another variable.


This is what my table looks like:



CREATE TABLE IF NOT EXISTS table(
Id INTEGER PRIMARY KEY,
Date TEXT,
Quantity INTEGER


Whenever i add a date to the database, with a quantity i want it to, add the quantity to the "quantity" in table. So every "Date" would only have 1 "Quantity" assigned.


Just a small example:



INSERT INTO Table (Date, Quantity) VALUES('%s', Quantity+%s)) % ('12/5/2013', 20);


If there already is a record that looks like ('12/5/2013', 5) it would be ('12/5/2013', 25) instead.


I found 1 very similar question, but i don't understand it.. Another Question


Aucun commentaire:

Enregistrer un commentaire