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: 23
Registered: ‎07-11-2011
My Device: Beginner Developer
My Carrier: Rogers
Accepted Solution

SQLite cannot extract data on BB simulator?

[ Edited ]

Hi everyone. I am creating an HTML5 based database using the webworks platform in the BB simulators. Unforuntaely, my database cannot retrieve data! It can create the database, create tables and even insert data, but it simply refuses to extract the data. No errors are thrown or picked up.

 

Below is a a section of my code. I have been trying to debug it for days without any success. Any help is appreciated!

function setupDB() {
try {
db = openDatabase('IESSSdb', '1.0', 'MG app db', 5 * 1024 * 1024);
		
	if (db) {
		db.transaction(function (tx) {

tx.executeSql('CREATE TABLE IF NOT EXISTS maagData (id int unique, name text, group text, value int, unit text, change text)'); tx.executeSql('CREATE TABLE IF NOT EXISTS settings (id unique, appSettings text, userSettings text)'); tx.executeSql('INSERT INTO maagData (id, name, group, value, unit, change) VALUES (?, ?, ?, ?, ?, ?)', [1, 'kingsha', 'SUPPLY', '999', 'MW', 'up']); alert('I made the tables'); //select stuff tx.executeSql('SELECT name,value FROM maagData WHERE key = 1', [], function (tx, results) {
document.getElementById("taContents").value = results.rows.item(0).name + "=" + results.rows.item(0).value; alert('i found it' + results.rows.item(0).name); });
alert('done selecting'); }, function (tx, error) { // error alert('1.Something went wrong: '+ error.message); }); } else { alert('could not find a db man'); document.getElementById('taContents').value += "\r\nNo DB\r\nopenDatabase:\r\n" + openDatabase; } } catch (err) { alert(err); document.getElementById('taContents').value += err; } }

 

Like i mentioned before, the tables are successfully created. Its just the 'select' transaction does not work. I have no clue y?

Contributor
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer
My Carrier: Rogers

Re: SQLite cannot extract data on BB simulator?

Also, everything executes normally. No alert messages are thrown from the error blocks.
Retired
Posts: 518
Registered: ‎07-18-2011
My Device: Bold
My Carrier: Rogers

Re: SQLite cannot extract data on BB simulator?

Hi kingsha,

 

There were two main problems with your code.

 

The most important problem is that you aren't keeping in mind the nature of JavaScript. Javascript essentially has 1 thread, and all the database methods are asynchronous. This means that when the methods return, its unlikely the code has actually completed but you will still try invoking the next part. This has the potential to cause you serious problems in the future.

 

The second problem was that some of your SQL was wrong. The words group and value cannot be used for column names. And you used the term key and id interchangeably.

 

function onError (tx, err) {
	alert("Error on transaction with message: " + err.message);
}

function onDBCreate(db) {
	db.transaction(function (tx) {
		tx.executeSql('CREATE TABLE IF NOT EXISTS maagData (id int unique, name text, groupName text, intValue int, unit text, change text)',
		    [],
			function (tx, r) {
				tx.executeSql('INSERT INTO maagData (id, name, groupName, intValue, unit, change) VALUES (?, ?, ?, ?, ?, ?)',
					[1, 'kingsha', 'SUPPLY', '999', 'MW', 'up'],
					function (tx, r) {
						tx.executeSql('SELECT name,intValue FROM maagData WHERE id = 1',
							[], 
							function (tx, results) { 
								alert(results.rows.item(0).name + "=" + results.rows.item(0).intValue);
							},
							onError);
					},
					onError);
			},
			onError);
	});
}

function setupDB(){
	try {
		var db = window.openDatabase('sasdfasdffd', '1.0.1', 'adasdfasdfc', 5 * 1024 * 1024, onDBCreate);		
	} catch (err) {
		alert("Caught Error: " + err);
	}
}

 



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Contributor
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer
My Carrier: Rogers

Re: SQLite cannot extract data on BB simulator?

[ Edited ]

Thanks so much for the reply jeffs. I now understand the concept better. I did have to make a slight modification to your code. The callback function once the db is created/opened was not working. I got around it by using this:

function setupDB(){
   try {
	var db = window.openDatabase('thisdb', '1.0.1', 'db for this bb app', 5 * 1024 * 1024, null);
	
        if (db)
		onDBCreate(db);
	else
		alert('did not make db');
	} catch (err) {
		alert("Caught Error: " + err);
	}
}

 

Contributor
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer
My Carrier: Rogers

Re: SQLite cannot extract data on BB simulator?

Now there is another problem. The code above works perfectly in OS5 (thanks to jeff).

 

But, when I try to simulate it in OS6, it fails. It gives me a DOM error when it is creating the DB. The error is:

Error: TYPE_MISMATCH_ERR: DOM Exception 17

 

I have tried googling what that means but can't figure out a solution for it. Any idea how I can make this work in OS6? 

 

Retired
Posts: 518
Registered: ‎07-18-2011
My Device: Bold
My Carrier: Rogers

Re: SQLite cannot extract data on BB simulator?

The reason the original code wasn't being invoked is likely because the database has already been created, and the creation callback is only called the first time. (A great time to do all the table creation and initialization).

 

As per the exception, I wonder if it is something to do with an SQL insert having a type mismatch. Try tracking ti down to the exact error function thats throwing it.  A great way to test all of this is using the awesome Ripple emulator.

 



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Contributor
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer
My Carrier: Rogers

Re: SQLite cannot extract data on BB simulator?

The error is thrown upon database creation. The line: var db = window.openDatabase('thisdb', '1.0.1', 'db for this bb app', 5 * 1024 * 1024, null); causes this error. I will continue googling this error. But thanks for note about initial database creation callback function.
Retired
Posts: 518
Registered: ‎07-18-2011
My Device: Bold
My Carrier: Rogers

Re: SQLite cannot extract data on BB simulator?

According to the HTML5 SQL Database Spec - "If the database version provided is not the empty string, and there is already a database with the given name from the origin origin, but the database has a different version than the version provided, then throw anINVALID_STATE_ERR exception and abort these steps." Is it possible its because I changed your database version?



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Contributor
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer
My Carrier: Rogers

Re: SQLite cannot extract data on BB simulator?

Hmm...i read the spec. But no, I changed the version back to 1.0 without any success. Still get the same error.

Contributor
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer
My Carrier: Rogers

Re: SQLite cannot extract data on BB simulator?

Hi again. I got a resolution to the problem. I had to remove the 'null' argument from the openDatabase function. I guess that was screwing around with everything. Here is the final command which works on both OS5 and OS6.

 

var db = window.openDatabase('thisdb', '1.0', 'db for this bb app', 5 * 1024 * 1024);

 I just wanted to thank you once again jeff. You helped me resolve this mess!