开发者

Local Database Storage default data

开发者 https://www.devze.com 2022-12-22 06:22 出处:网络
I have developed application using HTML 5 Localstorage. How can I create a TABLE and populate 10000+ rows before initi开发者_开发知识库alizing my

I have developed application using HTML 5 Localstorage.

How can I create a TABLE and populate 10000+ rows before initi开发者_开发知识库alizing my HTML 5 enabled application.

Please suggest a pattern.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消