Instead of doing an each loop on a JSON file containing a list of SQL statments and passing them one at a time, is it possible with Safari client side storage to simply wrap the data in "BEGIN TRANSACTION" / "COMMIT TRANSACTION" and pass that to the database system in a single call? Looping 1,000+ statements takes too much time.
Currently iterating one transaction at a time:
$j.getJSON("update1.json", function(data){ $j.each(data, function(i,item){ testDB.transaction( function (transaction) { transaction.executeSql(data[i], [], nullDataHandler, errorHandler); } ); }); });
Trying to figure out how to make just one call:
$j.getJSON("update1.json", function(data){ testDB.transaction( function (transaction) { transaction.executeSql(data, [], nullDataHandler, errorHandler); } ); });
Has anybody tried this yet and succeeded?
Every example I could find in the documentation seems to show only one
SQL
statement perexecuteSql
command. I would just suggest showing an "ajax spinner" loading graphic and execute your SQL in a loop. You can keep it all within the transaction, but the loop would still need to be there:Moving the loop inside the transaction and using the
for i =
should help get a little more speed out of your loop.$.each
is good for less than a 1000 iterations, after that the nativefor(var = i...
will probably be faster.Note Using my code, if any of your SQL statements throw errors, the entire transaction will fail. If that is not your intention, you will need to keep the loop outside the transaction.