views:

308

answers:

1

Hi

I have developed application using HTML 5 Localstorage.

How can I create a TABLE and populate 10000+ rows before initializing my HTML 5 enabled application.

Please suggest a pattern.

+2  A: 
var db = openDatabase('dbname', 'dbversion 1.0', 'description', 64*1024);
db.transaction(function (query){
   query.executeSql('CREATE TABLE IF NOT EXISTS tablename (id unique, value)');
   var rows = 10000, i;
   for(i=0; i < rows; i++){
      query.executeSql('INSERT INTO tablename (id, value) VALUES ('+ i + ', "Stackoverflow")');
   }

   query.executeSql('SELECT * FROM tablename', [], function (query, results) {
      for (i = 0; i < 5; i++) {
         alert(results.rows.item(i).text);
      }
   });
});

//Do magic with your webapp now

The queries accepted are SQLite type. Check the official specification for more.

N 1.1