cordova - How to check whether data exists and insert by one query in websql? -
can have 1 full query check whether data has been in database , insert if not?
i believe can done in normal sql using transaction
.
the consideration not manual select
query insert
have more 1 table done.
since websql implementation of sqlite, use insert or ignore
manage conflict resolution in single transaction.
for example, if had following table:
create table data (id integer primary key, event_id integer, track_id integer, value integer); create unique index data_idx on data(event_id, track_id);
which contained data:
1|1|2|3 2|2|3|4
you issue following sequential statements:
insert or ignore data values (null, 1, 2, 3); insert or ignore data values (null, 2, 3, 5); insert or ignore data values (null, 3, 4, 5);
and result of select * data
be:
1|1|2|3 2|2|3|4 3|3|4|5
the existing rows not updated because of constraint violation, first 2 statements ignore instead of fail, third execute , third row inserted.
Comments
Post a Comment