本地数据库存储默认数据

时间:2010-03-06 07:44:12

标签: html5 local-storage

我使用HTML 5 Localstorage开发了应用程序。

如何在初始化my之前创建一个TABLE并填充10000多行 支持HTML 5的应用程序。

请建议一种模式。

1 个答案:

答案 0 :(得分:5)

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

接受的查询是SQLite类型。查看official specification了解更多信息。

相关问题