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 Developer
cobusbenade
Posts: 22
Registered: ‎08-13-2009
My Device: 9900

executeSql not always executing

I trying to write a twiiter client using webworks for the playbook. I use JSON, I want to put the parsed data in a DB for usage later. Problem is sometimes the executeSql command runs, sometimes it doesnt, as example:

 

TwitterDB.transaction(
function (transaction) {
alert("Creating tables");

 

transaction.executeSql('CREATE TABLE IF NOT EXISTS VIEWS(VIEW_ID TEXT NOT NULL PRIMARY KEY, VIEW_DESC TEXT NOT NULL);', [], nullDataHandler, errorHandler);
transaction.executeSql('CREATE TABLE IF NOT EXISTS TWEET_TO_VIEWS(VIEW_ID TEXT NOT NULL, TWEET_ID TEXT NOT NULL, PRIMARY KEY (VIEW_ID, TWEET_ID));', [], nullDataHandler, errorHandler);
transaction.executeSql('CREATE TABLE IF NOT EXISTS TWEETER_DETAILS(TWEETER_ID TEXT NOT NULL PRIMARY KEY, NAME TEXT, FOLLOWING BOOLEAN, SCREEN_NAME TEXT);', [], nullDataHandler, errorHandler);
transaction.executeSql('CREATE TABLE IF NOT EXISTS TWEET_MAIN(TWEET_ID TEXT NOT NULL PRIMARY KEY, IN_REPLY_TO_USER_NAME TEXT, TWEET_SOURCE TEXT, IN_REPLY_TO_STATUS_ID TEXT, RETWEETED BOOLEAN, RETWEET_ID TEXT, TWEETER_ID TEXT, FOREIGN KEY (TWEETER_ID) REFERENCES TWEETER_DETAILS(TWEETER_ID));', [],nullDataHandler, errorHandler);
}
);
When using Ripple and I run the debugger I step through the code, I have the alert, and then it skips all the other code. Ive tested the SQL and it creates the tables. Later in my code I do checks in the content of some of the tables, and depending on the results ill maybe do a insert, but then the queries all fail because the tables might not exists or values ive inserted did go in.
Thanks in advance!
Developer
jdnoprada
Posts: 68
Registered: ‎03-01-2011
My Device: Not Specified

Re: executeSql not always executing

Hello cobusbenade,

 

You should be careful handling this asynchronous data. Your table might not have been initialized yet by the time made the insert on it. You could ensure that you're table was created by adding an alert or something on the success callback of your transaction.

 

Hope this helps.