Last active
August 29, 2015 14:07
-
-
Save manjeshpv/cd2866e67ce1cbbbc7d1 to your computer and use it in GitHub Desktop.
WebSQL Multiple Insertion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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