dimanche 22 février 2015

How to increment quantity column if record exists, else insert record?

I've got the below sqlite database:



CREATE TABLE `test` (
`idx` INTEGER PRIMARY KEY AUTOINCREMENT,
`qty` INTEGER,
`brand` TEXT,
`type` TEXT
);

insert into test (qty, brand, type) values (1, "Merc", "petrol");
insert into test (qty, brand, type) values (1, "Toyota", "diesel");


I want to insert another record but if it exists then I want to increase the qty field, so:



insert into test (qty, brand, type) values (1, "Merc", "diesel");


so would just increase the qty field by one, and



insert into test (qty, brand, type) values (1, "Merc", "petrol");


would insert a new record.


Aucun commentaire:

Enregistrer un commentaire