124 | Chapter 4: AIR Mini-Cookbook
Solution
Database data can be queried using SQL92 and the
SQLStatement class.
Discussion
Traditional SELECT statements can be run using a
SQLStatementobject that has been referenced against an exist-
ing database. Asuccessful execution of theSELECTstatement
invokes the registeredSQLResultEvent.RESULTevent handler.
That event handler will get aSQLResultEventobject which
contains the result data:
function doStmtResult( event )
{
var elem = null;
var results = stmt.getResult();
if( results.data != null )
{
for( var c = 0; c < results.data.length; c++ )
{
elem = document.createElement( "div" );
elem.innerText = results.data[c].first + " " +
results.data[c].last;
document.body.appendChild( elem );
}
}
}
TIP
This snippet forgoes much of the state management,
event registration and database connectivity covered in
other sections. Please review that content, or the exam-
ple at the end of this section, for complete coverage of the
topic.
To get any result data, the SQLStatement.getResult() is
called, which returns aSQLResultobject. TheSQLResult.data
property is an Array of the results, if any. TheSQLResult.data