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
kingsha
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer

OS6 sqlite db not working?

Hi there. I am trying to build an app that will work in both OS6 and OS5. I decided to use the HTML5 sqlite database framework and it works flawlessly in OS5 (with the google gears) add-on. However, it does not work properly in OS6.

 

My application creates the db on the main screen. However, when I navigate to another page in the app and try to input stuff into the created db, it fails. This is because such tables do not exist at that point. It seems like it wipes out the db from memory as soon as I switch pages. 

 

Has anyone encountered this problem? I have encountered this with various OS6 simulators I have tried.

Please use plain text.
Contributor
kingsha
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer

Re: OS6 sqlite db not working?

Anybody encounter this error yet? I am hopelesssly lost. Any input is appreciated!

Please use plain text.
Developer
billfoust
Posts: 382
Registered: ‎05-19-2008
My Device: BlackBerry Torch

Re: OS6 sqlite db not working?

Are you using the HTML5toGears script? Are you using the latest webwroks packager. I had a problem with SQLite, and making sure that I DID use thje latest packager and did NOT use the HTML5toGears script helped.. (the latest packager does the HTML5toGears thing for you).

Bill
-------------------------------------------
Check out my book on BlackBerry Development for Java.
And my other really really old book
My Apps: FlashKids
Please use plain text.
Contributor
kingsha
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer

Re: OS6 sqlite db not working?

Hi again. I downloaded the new SDK as you suggested. And unfortunately, it did not work again. The same problem persists. Any other suggestions?

Please use plain text.
New Contributor
harpreetgill
Posts: 7
Registered: ‎05-19-2011
My Device: 9900,Playbook

Re: OS6 sqlite db not working?

Can you please post the code you are using?

Please use plain text.
Contributor
kingsha
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer

Re: OS6 sqlite db not working?

[ Edited ]

Hi again everyone. I am using the following code:

 

My first page is called "index.html" in which it simply creates and/or intializes a db. I have also run a test which checks to see if the db is working by simply inserting and retrieving one line. This code works and I do get that result alert.

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

db.transaction(function (tx) {
    tx.executeSql('CREATE TABLE IF NOT EXISTS maagData (id text unique, name text, groupName text, intValue text, unit text, change text, mySettings text, userSettings text)',
    [],
    function (tx,results) {
	tx.executeSql('INSERT INTO maagData (id, name, groupName, intValue, unit, change, mySettings, userSettings) VALUES (?,?,?,?,?,?,?,?)',
	['123','kingsha','Student','132456','KW','up','true','true'],
	function (tx, results) {
         	tx.executeSql('SELECT * FROM maagData',
		[],
		function (tx, results) {
	        	alert(results.rows.length + "...." + results.rows.item(0).name);
		},
		onError);
	},
	onError);
    },
    onError);
});

 

Now on my following page called "maag.html", I have code in the javascript backend which simply trys to insert into the database by parsing data from an xml file.

function storeMaagData()
{
 //these are placeholder variables
 var category;
 var dataValue;
 var mysett;
 var userSett;
	
 //open db and execute function if successful, otherwise display and error alert
 var db = window.openDatabase('mydb', '1.0', 'db for MAAG bb app', 5 * 1024 * 1024);
 if (db)
 {	
   alert('found db');
   db.transaction(function (tx) {	
   $.ajax({
	url: "http://*********/maag.xml",
	success: function(data){
            alert('am in the get data function');
	    //will now parse and input into local db
	    xmlSet = data.getElementsByTagName('subset');
			
	    for(i=0; i<xmlSet.length; i++) 
{ //set the category category = xmlSet[i].getElementsByTagName("subtitle")[0].childNodes[0].nodeValue; alert(xmlSet.length + '...' + category); //get info subset xmlSubSet = xmlSet[i].getElementsByTagName('information'); for(k=0; k<xmlSubSet.length; k++) { dataValue = xmlSubSet[k].getElementsByTagName("new_val")[0].childNodes[0].nodeValue;; userSett = 'true'; mysett = 'true'; alert("almost hit the transaction"); tx.executeSql('SELECT * FROM maagData', [], function (tx, results) { alert(results.rows.length + "...." + results.rows.item(0).name); //now that all the data is ready, insert it into the db table tx.executeSql('INSERT OR REPLACE INTO maagData (id, name, groupName, intValue, unit, change, mySettings, userSettings) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', [ xmlSubSet[k].getAttribute('id'), xmlSubSet[k].getElementsByTagName("info_title")[0].childNodes[0].nodeValue, category, dataValue, xmlSubSet[k].getElementsByTagName("unit")[0].childNodes[0].nodeValue, xmlSubSet[k].getElementsByTagName("change")[0].getAttribute('type'), mysett, userSett ], function(tx,results) {alert('successful insert:' + xmlSubSet[k].getAttribute('id'));}, onStoreError); }, onUserSettingsError); } } }, error: function(){ //could not connect to the maag xml website. Will show a graceful fail message and load any existing data alert('A valid internet connection could not be found.\nWill attempt to load last stored data.'); }, complete: function(){ //function to load data loadMaagData(); }
}); }); } else alert('db could not be opened'); }

 

 This function above fails on the intial get statement I have. It gives me all the alerts I asked it to until the "almost hit the transaction". After that it tries to withdraw the same data I tried to withdraw earlier. But the program simply fails. No error message is even shown. I believe that is becuase there is no recall of any database being made.

 

Can someone check to see if this is a BB simulator bug? I have tried this in the latest sdk sim (9930) to no avail. I am inserting a 'sd' card btw.

 

 

Please use plain text.
Developer
billfoust
Posts: 382
Registered: ‎05-19-2008
My Device: BlackBerry Torch

Re: OS6 sqlite db not working?

You've got an ajax call in the middle of the db.transaction method. When you do the .ajax(), you have a seperate success function where you try to use tx, but at this point, you are in an asynchronous callback, so your db transaction is gone.

 

move your db.transaction() call into the success: function of your .ajax call. you don't need the db transaction until then anyway.

 

 if (db)
 {	
   alert('found db');
// NOT HERE
//   db.transaction(function (tx) {	
   $.ajax({
	url: "http://*********/maag.xml",
	success: function(data){
            alert('am in the get data function');
	    //will now parse and input into local db
	    xmlSet = data.getElementsByTagName('subset');
//HERE
            db.transaction(function (tx) {	
            ....
            });

 

Bill
-------------------------------------------
Check out my book on BlackBerry Development for Java.
And my other really really old book
My Apps: FlashKids
Please use plain text.
Contributor
kingsha
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer

Re: OS6 sqlite db not working?

Thanks for your suggestion bill. I have tried it and recall trying it once earlier too.

 

The function now actually runs through all the loops and doesnt get stuck. The problem is that the db.transactions do not load. It practically skips them (maybe becuase the loops end too fast?). 

Please use plain text.
BlackBerry Development Advisor (Retired)
jeffheifetz
Posts: 518
Registered: ‎07-18-2011
My Device: Bold

Re: OS6 sqlite db not working?

Try implementing the error callback on your insert transaction and see if you're getting some errors from the db



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)
Please use plain text.