jquery - Insert row if not exists otherwise update sqlite - JavaScript -


i know there have been lot of questions on in past, seem unable utilise answers. have tried, don't seem work.

i have table stores 2 user inputted values: name , email. when enter name , e-mail, gets stored single row of table.

i want able update same row different name , email if user types other values, or insert these values if there weren't previous values.

my code here:

db.transaction(function(transaction) {  transaction.executesql('insert details(name,email)\  values(?,?)',[$('#entername').val(), $('#enteremail').val()],  nullhandler,errorhandler);   }); 

and table creation here if needed:

db.transaction(function(tx){    tx.executesql( 'create table if not exists details(id integer not\                    null primary key,name,email)',                    [],nullhandler,errorhandler);                            },errorhandler,successcallback); 

i have tried using insert or replace, creates new row new details , leaves previous row there old details. there efficient options relevant case? thanks

finally got work. had this:

db.transaction(function(transaction) {  transaction.executesql('insert or replace details(id,name,email)\  values(1,?,?)',[$('#entername').val(), $('#enteremail').val()],  nullhandler,errorhandler);   }); 

where id row id. replaces first row whatever else type name , email if doesn't exist


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -