Optimizing Websql Local Database Population
I am trying to optimize the speed that my  Local database populates in a Web app that is being developed.  Currently, it uses PHP to access the Database and then inserts that data
Solution 1:
I would prepare a query with placeholders, then execute it for each row with the right arguments. Something like this (JS part only, using underscore.js for array helpers):
db.transaction(function(tx) {
    var q = 'INSERT INTO Cost_Codes (Cost_Code_No, Name, Unit_Of_Measure) VALUES (?, ?, ?)';
    _(rows).each(function(row) {
        tx.executeSql(q, [row.code, row.name, row.unit]);
    });
});
Edit: a query with placeholders has two main benefits:
- It makes it a lot easier for the DB engine to cache and reuse query plans (because you are running the same query a hundred times instead of a hundred different queries once).
 - It makes escaping data and avoiding SQL injections a lot easier.
 
Post a Comment for "Optimizing Websql Local Database Population"