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
Trusted Contributor
NitishSubudhi
Posts: 166
Registered: ‎12-09-2011
My Device: 9550,9300,9800,9700,9900,9850,9860

Problem in execution of transaction in for loop in Webworks Smartphone

Hi

i am facing problem in "db.transaction(function(tx)".
I have to execute this function in a for loop, so that I can insert dynamic data to the table,
but it is executing only for the last time and the last data value is only inserting..

Please help me if any one have any solution or code for solving this problem...

Thanks & Regards,

Nitish Subudhi 

Thanks & Regards,
Nitish Subudhi

Feel Free To Press The Like Button On The Right Side To Thank The User That Helped You.
Please Mark Posts As Solved If You Found a Solution.
Please use plain text.
Retired
astanley
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Problem in execution of transaction in for loop in Webworks Smartphone

The transaction() method is asyncronous, so it does not run or complete in any given order.  Could there be a timing issue with inserting data too quickly  or a conflict with the unique DB key you use to add rows to the table?

 

Do you have a transaction error callback method - if so is it generating any error messages?  

 

Finally please post a code snippet that shows how you are executing this transaction.

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Please use plain text.
Developer
nunodonato
Posts: 313
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha

Re: Problem in execution of transaction in for loop in Webworks Smartphone

Place that before the for loop, and the execute call inside. Should work :smileyhappy:

Nuno
theBBthing.wordpress.com - my BlackBerry development blog: news, tips and tutorials
bitoutsidethebox.com - re-imagining digital solutions


Please use plain text.
Trusted Contributor
NitishSubudhi
Posts: 166
Registered: ‎12-09-2011
My Device: 9550,9300,9800,9700,9900,9850,9860

Re: Problem in execution of transaction in for loop in Webworks Smartphone

Hi astanley,

 

I think there is some timing issue. B'coz some times its executing all inside a for loop and some time it is overlapping and executing only the last value.
And for the same I didn't getting any types of error. 

 

I am using the code given below:

 

function GalleryTable(ImageID, Photos, Imagepath, imageTitle){
if (db) {
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS PhotoGalleryImages (PhotoId VARCHAR PRIMARY KEY, Photo VARCHAR, ImagePath VARCHAR, ImageTitle VARCHAR)',[]);
tx.executeSql('SELECT * FROM PhotoGalleryImages WHERE PhotoId=?', [ImageID], function(tx, result) {
dataset = result.rows;
if(dataset.length > 0){
tx.executeSql('UPDATE PhotoGalleryImages SET PhotoId = ?, Photo = ?, ImagePath = ?, ImageTitle = ?, WHERE PhotoId = ?', [ImageID, Photos, Imagepath, imageTitle, ImageID]);
}
else{
tx.executeSql('INSERT INTO PhotoGalleryImages (PhotoId, Photo, ImagePath, ImageTitle) VALUES (?, ?, ?, ?)', [ImageID, Photos, Imagepath, imageTitle]);
}

});
});

}


And declaring the function inside a for loop..

please help me if any one having any code or solution....

Thanks & Regards,
Nitish Subudhi

Feel Free To Press The Like Button On The Right Side To Thank The User That Helped You.
Please Mark Posts As Solved If You Found a Solution.
Please use plain text.
Trusted Contributor
NitishSubudhi
Posts: 166
Registered: ‎12-09-2011
My Device: 9550,9300,9800,9700,9900,9850,9860

Re: Problem in execution of transaction in for loop in Webworks Smartphone

Hi nuno,
I am doing exactly you said.
But m facing problem due to timing issue as per I know..But can't find solution regarding this matter...
Please help me if you know the solution.. 

Thanks & Regards,
Nitish Subudhi

Feel Free To Press The Like Button On The Right Side To Thank The User That Helped You.
Please Mark Posts As Solved If You Found a Solution.
Please use plain text.
Developer
nunodonato
Posts: 313
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha

Re: Problem in execution of transaction in for loop in Webworks Smartphone

Hi!

If you have all that inside the function and you are calling it inside the for loop, then you are not following what I said.

 

The for loop should be inside this

if (db) {
  db.transaction(function (tx) {
   // loop code
  }
}

 let me know if it worked

Nuno
theBBthing.wordpress.com - my BlackBerry development blog: news, tips and tutorials
bitoutsidethebox.com - re-imagining digital solutions


Please use plain text.
Trusted Contributor
NitishSubudhi
Posts: 166
Registered: ‎12-09-2011
My Device: 9550,9300,9800,9700,9900,9850,9860

Re: Problem in execution of transaction in for loop in Webworks Smartphone

Hi nuno,
I am trying as you have describe.
If this will the solution then I will surely post here.
Thanks for your valuable reply. 

Thanks & Regards,
Nitish Subudhi

Feel Free To Press The Like Button On The Right Side To Thank The User That Helped You.
Please Mark Posts As Solved If You Found a Solution.
Please use plain text.