Prev | Current Page 549 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

The
ResultSet object also provides the means to export the contained data in a List object for easy
integration into functions and methods that accept the List object as a parameter.
If you need to access specific records in a ResultSet and would prefer access to the records via an
index, then you can quite comfortably convert the ResultSet into an array, as shown in this example:
class DBArray
{
public static function main()
{
var dbLoc = ???Wrox.db3???;
arrayFromDB( dbLoc );
}
public static function arrayFromDB( loc : String )
{
// open database connection
var cnx = neko.db.Sqlite.open( loc );
(continued)
286
Part II: Server Side, JavaScript, and Flash: Oh My!
var sql = ???SELECT * FROM Author???;
// execute query
var rec = cnx.request( sql );
// convert ResultSet to an array
var arr = Lambda.array( rec.results() );
// loop through array while printing values
for ( i in 0...arr.length )
{
neko.Lib.print( i + ???: ??? + arr[i].var_username );
neko.Lib.print( ???\t??? + arr[i].var_password + ???\n??? );
}
// close the connection
cnx.


Pages:
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561