Skip to content

Instantly share code, notes, and snippets.

@manjeshpv
Last active August 29, 2015 14:07
Show Gist options
  • Save manjeshpv/cd2866e67ce1cbbbc7d1 to your computer and use it in GitHub Desktop.
Save manjeshpv/cd2866e67ce1cbbbc7d1 to your computer and use it in GitHub Desktop.
WebSQL Multiple Insertion
// Multiples INSERTs : 2500ms
// Using BEGIN and COMMIT : 90ms
// Using SELECT and UNION : 40ms
var newQuery = true, query = '';
for (i=0; i<locations_length; i++) {
if (newQuery) {
query = 'INSERT INTO myTable (id, name, code)';
newQuery = false;
}
else {
query += ' UNION';
}
query += ' SELECT "'+values[i][0]+'", "'+values[i][1]+'", "'+values[i][2]+'"';
if (i!=0 && i%499==0) {
db.execute(query);
newQuery = true;
}
}
//executing remaining lines
if (i%499!=0) {
db.execute(query);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment