Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local Database Storage default data

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.

like image 850
user287635 Avatar asked Mar 06 '10 07:03

user287635


People also ask

What is a default in database?

What Does Default Values - Database Mean? Default values, in the context of databases, are preset values defined for a column type. Default values are used when many records hold similar data.

Where are SQL databases stored by default?

The data and transaction log files are stored in the root of the database directory. The database directory is the folder location specified when the database is created.

What is local data base?

Local database would be SQLite in android. It can be accessed locally only. A server database is hosted in a remote server. Basically It can be accessed by any client in the web. An example of local use would be for example storing credentials or information that you don't want/need to share with another user.


1 Answers

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.

like image 72
N 1.1 Avatar answered Sep 29 '22 04:09

N 1.1