Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
Posts: 14
Registered: ‎05-19-2012
My Device: bb playbook
My Carrier: none
Accepted Solution

sqlite webdatabase (again)

am developing an app on playbook OS 2.1.0.840 and using web database. am creating the database using window.opendatabase but am having issues updating the database structure when I have to add some new tables. deleting the app does not remove the database. changing the name produces a "no such table" error when am trying to select data from my tables.

 

so the code is like this:

 

var db;

function createDatabase() {
	try {
		var dbSize = 2 * 1024 * 1024;	//Assign 2MB of space for the database
		db = window.openDatabase("DBName", "1.0", "My DB Name", dbSize, createTables);
		if(db!==null)
		{
			//start app main page	
		}
	}
	catch(e) {
		//error handling message
	}
}

the callback function "createTables" contains the logic to create the database tables. so I just don't know why sometimes works, then when I change the name of the database the "no such table" error occurs. looks like not all the time the createTable is executed.

 

what is going on? any help is appreciated and will help me sleep again...

Contributor
Posts: 14
Registered: ‎05-19-2012
My Device: bb playbook
My Carrier: none

Re: sqlite webdatabase (again)

i've sort out my problem. just in case someone will experience the same "issues"... the key is understanding the windows.openDatabase returns the callback asynchronous so the lines where I got "start app main page" could execute before the callback createTables is finished. that means am starting querying tables that are not yet created. Hence the “no such table” error. so the "start app main page" code had to be moved to be executed when the callback createTables is completed.  then next thing is to cater for the fact that once the database is created the callback of windows.openDatabase is not executed anymore when you restart the app, so you need another way to access the code for "start app main page". hope will help someone.