Reputation: 69
I followed a phonegap tutorial on how to set up and create an SQLite DB on my android tablet. The DB is written in javascript, and the application is written in HTML5.
The DB became really big in the end (1200 lines only with populating/adding data) One of my concerns is that it populates everytime I go to my index.html (frontpage) or a page I called catalog.html. Is this a problem for memory or time etc? the application do not add any content to the DB while running. do anyone know of a way to NOT let it populate every time? Here is some of the code:
document.addEventListener("deviceready", onDeviceReady, false);
var db = window.openDatabase("DBfile", "1.0", "Afghanistan", 200000);
function onDeviceReady() {
db.transaction(populateDB, errorCB, successCB);
}
function populateDB(tx) {
(...
...
...)
}
function errorCB(tx, err) {
alert("Error processing SQL: "+err.code);
}
function successCB() {
alert("DB and tables generated with success!");
}
Will it help to only "link" to the db-file in index.html instead of all the other pages? the strange thing is that there is also one other page that get data from the DB file, but I do not get an "DB and tables generated with success!" alert when I enter that page.
Upvotes: 0
Views: 1762
Reputation: 23273
The way you have your code structured the populateDB method will be called every time you start your app. You will want to guard this call by setting a value in localStorage. Something like:
function onDeviceReady() {
if (localStorage.getItem("firstRun") == null) {
db.transaction(populateDB, errorCB, successCB);
localStorage.setItem("firstRun", false);
}
}
Upvotes: 3
Reputation: 1337
I use Phonegap as well with quite a large database. I suggest you look at a framework for the html5 application such as jQtouch, it mimics the interactions on a "native" iphone app. To my point, with jQtouch, you only load your index.html once, then load the other pages with javascript. You can load the contents with ajax and only have the structure of your page all in index.html.
I haven't had any problems with loading times or memory leaks. Have a look at jQtouch here.
Good luck!
Upvotes: 0