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: 31
Registered: ‎01-06-2011
My Device: 9300
My Carrier: MTN Nigeria
Accepted Solution

SQLite DB access in BB 6

Hello,

 

I previously wrote my webworks application using google gears for SQLite DB access. Recently, I decided to use HTML5 instead so my application would run on OS 6. After several painstaking hours of rewriting the application (and having to rethink the flow thanks to HTML5's asynchronous DB access Smiley Mad), I finally make the application to run on OS 5 using the html5_init.js file with no google gears in my javascript file. However, my application has still refused to run normally on OS 6. I have managed to narrow down one of the issues to something like this:

 

 

db.transaction(function(tx){
    tx.executeSql('some_sql', [], function(tx){
        var request2 = new XMLHttpRequest();
	request2.open("GET", 'some_url');
	request2.setRequestHeader("Content-type", "text/html");
	request2.onreadystatechange = function() {
            tx.executeSql('some_sql');
        }
    }
}

 

 

Now here's the problem, on calling the second tx.executeSql(), the tx object is recognized as a valid SQL transaction object but the method call fails with the following exception:

 

INVALID_STATE_ERROR: DOM Exception 11

 

What could I be doing wrong?

Cheers!
Ezeozue Chidube
Seamfix Nigeria Limited (www.seamfix.com)
www.twitter.com/cezeozue
Developer
Posts: 37
Registered: ‎12-24-2010
My Device: Tour
My Carrier: Verizon

Re: SQLite DB access in BB 6

The only time that I saw this error in the 6.0 simulators was when I didn't have a memory card simulated.

Developer
Posts: 189
Registered: ‎08-13-2008
My Device: Not Specified

Re: SQLite DB access in BB 6

Hi

 

I've seen the same thing happening as described by Silaryn above.

If you have an old device that has been upgraded to OS 6.0  then it will require an external memory card for the DB to work correctly.

 

Other times I have seen this error is when the BB is in Mass Storage mode. I.e. after you have connected the BB upto the computer and used it to store some files etc.

The BB requires a reboot sometimes to get out of mass storage mode.

 

There areare a few previous posts on this.

 

Cheers

 

Andrew

Contributor
Posts: 31
Registered: ‎01-06-2011
My Device: 9300
My Carrier: MTN Nigeria

Re: SQLite DB access in BB 6

I didn't think mounting an SD card was the issue since I had already made several successful DB calls. Moreover, the Torch (whose simulator I am using), stores its DB by default on an inbuilt eMMC card (which I don't know how to access both from the simulator and an actual device, but that's a different discussion). For avoidance of doubt though, I mounted an SD Card; still to no avail.

 

Let me clarify what I think may be my issue: I am referring to a transaction object within an asynchronous function and I fear that the transaction object may no longer be valid. I just need to know for sure that this is the case and look for alternative approaches if it is.

Cheers!
Ezeozue Chidube
Seamfix Nigeria Limited (www.seamfix.com)
www.twitter.com/cezeozue
Developer
Posts: 189
Registered: ‎08-13-2008
My Device: Not Specified

Re: SQLite DB access in BB 6

Hi

 

I think you may be correct,

 

 Have you tried using

 

db.transaction(function(tx2){ etc

 

within the callback function instead of just calling the transaction again.

 

 

Cheers

 

Andrew

Contributor
Posts: 31
Registered: ‎01-06-2011
My Device: 9300
My Carrier: MTN Nigeria

Re: SQLite DB access in BB 6

I tried that and experienced the quirkest behaviour I have seen on webworks so far. Let me explain:

 

I had already learnt (the hard way), that enclosing one db.transaction within another does not work (Has it ever worked for you?). And as expected it did not work in this case. However, when I put an alert (Hence, a pause) just before the inner db.transaction, it worked. My rationalization is that the pause provided enough time for the first transaction to complete and return before running the inner one. Any other thoughts about that? In any case, having an alert at that position will not serve my purpose.

 

As an aside, its about time we had a WebWorks book. Any interested parties? I'm good for a few chapters.

Cheers!
Ezeozue Chidube
Seamfix Nigeria Limited (www.seamfix.com)
www.twitter.com/cezeozue
Developer
Posts: 189
Registered: ‎08-13-2008
My Device: Not Specified

Re: SQLite DB access in BB 6

Hi

 

I have been able to nest database transactionw with callback functions and also with the asynschoronous function of an AJAX call. It took a bit of time to get my head around it, but I got there in the end.

 

I tend to use the callback from the actual db.transaction to carry out the next db call. (Not the callbackfunction from the transaction itself...that is confusing!)

 

e.g.

 

db.transaction(function(tx){
        tx.executeSql('some_sql', [],  tx_transaction_ok, tx_error_handler);

    }
    , tx_error_handler
    , function(tx){
        var request2 = new XMLHttpRequest();
        request2.open("GET", 'some_url');
        request2.setRequestHeader("Content-type", "text/html");
        request2.onreadystatechange = function() {
             db.transaction(function(tx){tx.executeSql('some_sql', [],  tx_transaction_ok });

        }
);

 

(I may have missed some parenthesis etc)

 

Have you tried this method? This way the db object is released before using it again.

 

Cheers

 

Andrew

Contributor
Posts: 31
Registered: ‎01-06-2011
My Device: 9300
My Carrier: MTN Nigeria

Re: SQLite DB access in BB 6

No, I have not tried this approach. I did not even know that db.transaction had its own callback; I can already think of a few places in my code where this knowledge would have been useful.

 

I was already about to unhook the inner process from the transaction using setTimeout() but let me give your suggestion a shot. If it works, I'll mark it as the solution.

 

Thanks.

Cheers!
Ezeozue Chidube
Seamfix Nigeria Limited (www.seamfix.com)
www.twitter.com/cezeozue
Developer
Posts: 67
Registered: ‎09-23-2010
My Device: Curve
My Carrier: T-Mobile

Re: SQLite DB access in BB 6

I too have seen the behavior described above where a transaction seems to go on forever, but if I have an alert in there it succeeds. I have even put in time delays up to 15 seconds to try to give the callback time to deliver the data but it just times out.

 

Obviously, I am missing something here. I understand the reason for using asynchronous transactions but is there an option for a synchronous transaction or just a plain execute as in version 5?

 

 

Contributor
Posts: 31
Registered: ‎01-06-2011
My Device: 9300
My Carrier: MTN Nigeria

Re: SQLite DB access in BB 6

I'm not sure if my problem was with the transaction going on forever but its solved. It requires a bit of a paradigm change to shift from synchronous to asynchronous transactions. And there's no option for synchronous transactions in BB 6 as far as I know. 

Cheers!
Ezeozue Chidube
Seamfix Nigeria Limited (www.seamfix.com)
www.twitter.com/cezeozue