I have a JavaScript object with multiple rows of data and I want to insert it into web sql database.
Here is how my code looks like.
for(i in rows)
{
(function(row){
db.transaction(function(tx) {
tx.executeSql("INSERT INTO my_table (id, name, parent_id) VALUES (?, ?, ?)",
[ row.id, row.name, row.parent_id ], onSuccess, onError
);
});
})(rows[i]);
}
My questions about this are:
- This can be done by moving outer loop inside
db.transaction. Will it be better and why? - Is it possible to add multiple rows in single query like multiple values in single MySQL
INSERT? Or I should not worry about this.
This can be done by moving outer loop inside db.transaction. Will it be better and why?
Is it possible to add multiple rows in single query like multiple values in single MySQL INSERT? Or I should not worry about this.
Again do not loop executeSql, it is async.