I scrap data on the web with a Google Chrome extension. I store them in an multidimensional array. I want to save all theses data in a Sqlite database.
I read this page How to speed up the process when inserting 1000's of records into sqlite using HTML5 but the answer given does not seem to work.
When I open a transaction for each INSERT it works
i=0;
while(i<n){
(function(aa){
db.transaction(function (tx) {
tx.executeSql("INSERT INTO Links2 (c1, c2, c3, c4, c5, c6) VALUES ('"+aa[0]+"', "+parseInt(aa[1])+", '"+parseInt(aa[2])+"', '"+aa[3]+"', '"+aa[4]+"', '"+aa[5]+"')");
});
})(myDataArray[i]);
i++;
}
The problem is when I try to opening the transaction before the While
db.transaction(function (tx) {
i=0;
while(i<n){
aa = myDataArray[i];
txquer(tx, i, aa[0], parseInt(aa[1]), parseInt(aa[2]), aa[3], aa[4], aa[5]);
i++;
}
});
function txquer(tx,i,a,b,c,d,e,f){
console.log("INSERT INTO Links2 (c1, c2, c3, c4, c5, c6) VALUES ('"+a+"', "+b+", '"+c+"', '"+d+"', '"+e+"', '"+f+"')");
tx.executeSql("INSERT INTO Links2 (c1, c2, c3, c4, c5, c6) VALUES ('"+a+"', "+b+", '"+c+"', '"+d+"', '"+e+"', '"+f+"')");
}
When I test individually every console.log output I works. But the script does not save the data in the database.