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
New Contributor
Posts: 7
Registered: ‎01-18-2011
My Device: simulator 6

Html5 Sqlite problem ?

 

Hello Everybody,

 

I am new to Blackberry widget.

 

http://supportforums.blackberry.com/t5/Web-Development/Supporting-Gears-using-HTML5-in-BlackBerry-We....

 

I have downloaded one example from above link , which is used to datastorage in blackberry by using html5(which is working with  os6) is working fine . When i am trying to do some small application , while retireving the data before inserting or retriving all records it  is executing next method and first time it is showing  only few records once again i will refresh or come back and go it will show all records.

The Following is the code i am using for retrieving the data. 

db.transaction( function(tx) {
			tx.executeSql('select Task_Desc,Obj_Desc,Status,Action_Code,serverErrorMessage from HEADR ;',[],
					function(tx, results) {
				for(var i = 0; i < results.rows.length; i++) {
					imgName = results.rows.item(i).Task_Desc;
					tempName = results.rows.item(i).Obj_Desc;
					tempStatus = results.rows.item(i).Status;
					actCode=results.rows.item(i).Action_Code;
					errMsg=results.rows.item(i).serverErrorMessage;
					}
                                }, sqlFail);
		}, txFail);

 Following are the few functions in javascript which is followed by the above code.

getDetails();

showDetails();

before executing above code it is executing getDetails() function and showDetails().

and it is displaying only few records. once i refresh or go back and come it will display all records.

Please help me to solve this  problem .

 

Thanks and Regards

S.Sivamurthy.

 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Html5 Sqlite problem ?

One thing that can trip up a lot of developers is the fact that HTML5 database access is asynchronous and not synchronous..

 

So if you do a getData() and then a showData() right after it, it will be a race condition to see if the database can retrieve the contents in time for your show query.

 

I'm not sure if this is what is causing the issue for you or not.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 7
Registered: ‎01-18-2011
My Device: simulator 6

Re: Html5 Sqlite problem ?

Thanks tneil

    

             My problem is before retrieving records it isgoing to ShouDetails() and it is displaying only UI details(static text)  without database details (dynamic data). please help me how to solve this problem. Is there any other methods for datastore which should work in Blackberry  OS5 and OS6.

 

 

Thanks and regards

Siva 

Developer
Posts: 37
Registered: ‎01-18-2011
My Device: Huron 8800

Re: Html5 Sqlite problem ?

Here is your code piece with my comment

 

db.transaction(function(tx) {
    tx.executeSql(
        'select Task_Desc,Obj_Desc,Status,Action_Code,serverErrorMessage from HEADR ;', 
        [],
        function(tx, results) {
            for(var i = 0; i < results.rows.length; i++) {
                imgName = results.rows.item(i).Task_Desc;
                tempName = results.rows.item(i).Obj_Desc;
                tempStatus = results.rows.item(i).Status;
                actCode=results.rows.item(i).Action_Code;
                errMsg=results.rows.item(i).serverErrorMessage;
            }
            
            // You should do something, in these section, whether calling a callback function, 
            // or just directly modify the DOM
            
        }, sqlFail);
}, txFail);

// If you do something right here, just like showing the detail using DOM modification,
// the query might be not completed and you just see few data.

As Tim said, the database operation is asynchronous, so you need to mention a callback function (closure), or just directly outputing it  inside the onSuccessHandler..

New Contributor
Posts: 7
Registered: ‎01-18-2011
My Device: simulator 6

Re: Html5 Sqlite problem ?

Thanks kemasD

 

Please can u give me one example regarding my problem . I dont Know what is callback function. Please give me one example .

 

Regards

Siva

Developer
Posts: 37
Registered: ‎01-18-2011
My Device: Huron 8800

Re: Html5 Sqlite problem ?

You can refer to this solution HTML5 SQlite

New Contributor
Posts: 7
Registered: ‎01-18-2011
My Device: simulator 6

Re: Html5 Sqlite problem ?

Thanks KemasD

 

         I have tried with ur code also but  iam using  javascript and ajax(instead of  jQuery) so same thing is happening. Is there any concept in javascript like threads in java to wait that function until completion of function it should stay. If u have any idea please send one example, or how to use  callback function in javascript and my scenario.

 

 

Regards

Siva

Developer
Posts: 37
Registered: ‎01-18-2011
My Device: Huron 8800

Re: Html5 Sqlite problem ?

Here's one great example that lead me to achieve synchronous database call in javascript, hope it'll help you too Sync Database Call Javascript

New Contributor
Posts: 7
Registered: ‎01-18-2011
My Device: simulator 6

Re: Html5 Sqlite problem ?

Thanks KemasD

 

           Thanks a lot kemas with ur suggestions i have successfully finished .My application is working now. once again thanking you for ur valuable guideline.

 

Regards

siva