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.
精彩评论