ColdFusion Iterating Business Objects (IBOs) From The Ground-Up

<!--- Build a test query. --->
<cfset qGirl = QueryNew(
	"id, name, sexyness_factor",
	"CF_SQL_INTEGER, CF_SQL_VARCHAR, CF_SQL_DECIMAL"
	) />
 
 
<!--- Add rows to the test query. --->
<cfset QueryAddRow( qGirl, 3 ) />
 
<!--- Set the row data for the query. --->
<cfset qGirl[ "id" ][ 1 ] = JavaCast( "int", 1 ) />
<cfset qGirl[ "name" ][ 1 ] = JavaCast( "string", "Sarah" ) />
<cfset qGirl[ "sexyness_factor" ][ 1 ] = JavaCast( "float", 10.0 ) />
 
<cfset qGirl[ "id" ][ 2 ] = JavaCast( "int", 2 ) />
<cfset qGirl[ "name" ][ 2 ] = JavaCast( "string", "Libby" ) />
<cfset qGirl[ "sexyness_factor" ][ 2 ] = JavaCast( "float", 8.5 ) />
 
<cfset qGirl[ "id" ][ 3 ] = JavaCast( "int", 3 ) />
<cfset qGirl[ "name" ][ 3 ] = JavaCast( "string", "Alex" ) />
<cfset qGirl[ "sexyness_factor" ][ 3 ] = JavaCast( "float", 7.5 ) />
 
 
<!---
	Create the IBO and load in the query. Notice that I can
	chain these two actions together, which the original
	IBO could not. Just a neat little feature.
--->
<cfset objIBO = CreateObject(
	"component",
	"GirlIBO"
	).Init().LoadQuery( qGirl ) />
 
 
<!---
	Loop over the IBO. You might want to run a First() call
	before iterating, but for this demo, that is not
	required.
--->
<cfloop condition="objIBO.IsRecord()">
 
	<!--- Set the name just to test the set as fn. --->
	<cfset objIBO.Set(
		"name",
		objIBO.Get( "name" )
		) />
 
	<p>
		#objIBO.Get( "full_name" )# ::
		#objIBO.Get( "sexyness_factor" )#
	</p>
 
	<!--- Go to the next record. --->
	<cfset objIBO.Next() />
</cfloop>

For Cut-and-Paste