I think this is what you're after -
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
var insertValues = {
values1: [1, 'First row'],
values2: [2, 'Second row']
};
doInserts(insertValues);
function doInserts(insertValues) {
db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql(
'INSERT INTO DEMO (id, data) VALUES (?, ?)',
insertValues.values1,
insertSuccess,
insertFail
);
tx.executeSql(
'INSERT INTO DEMO (id, data) VALUES (?, ?)',
insertValues.values2,
insertSuccess,
insertFail
);
});
}
function insertSuccess() {
console.log('insert success');
}
function insertFail(err) {
console.log('insertFail, err.message: ' + err.message);
}
This stuff is asynchronous so if you want to know when all your inserts are finished one trick that works is to -
- Count the number of inserts you are expecting to do and store it in a variable.
- When an insert is successful, decrement 1 on the variable storing the number of inserts expected.
- When the variable holding the number of inserts expected is 0 then you know all your inserts have finished.