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
mikehughesc
Posts: 35
Registered: ‎12-28-2010
My Device: Bold 9780
Accepted Solution

Database transaction object properies???

db.transaction(function(tx) {
	tx.executeSql("SELECT stuff FROM table1", [], dbSuccess, dbError);
});

function dbSuccess(tx, r) {
	// what can I do with tx here?
}

The SQL Transaction object, as passed to the success and error callbacks of executeSQL, appears to have no properties or methods other than executeSQL.  How can I (for example) retrieve the SQL command which was executed - e.g. something like:

function dbSuccess(tx, r) {
    alert(tx.sqlStatement + " completed OK! - rows affected: " + r.rowsAffected);
}

The r.rowsAffected bit works fine.  But the tx argument appears to be useless.

 

If something along the lines of the above is not possible, what is the point of the first argument of the callback?

 

 

BlackBerry Development Advisor
twindsor
Posts: 832
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Database transaction object properies???

The tx argument allows you to chain statements together in a single transaction, so it's extremely useful, though in many cases you probably won't need that.

 

However, because it's javascript, you coud add properties to it as you go. You could add a 'lastSQL' property and set it to your SQL when you call executeSQL for example.

Tim Windsor
Open Source Technical Lead
BlackBerry Development Advisor
twindsor
Posts: 832
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Database transaction object properies???

I meant to also include a link to the spec: http://www.w3.org/TR/webdatabase/#asynchronous-database-api

Tim Windsor
Open Source Technical Lead
Contributor
mikehughesc
Posts: 35
Registered: ‎12-28-2010
My Device: Bold 9780

Re: Database transaction object properies???

OK, yeah, that's clever, hadn't thought of that!