5Introducing the CFX API
Working with Queries
Any CFX tag may return queries to the ColdFusion page that is calling the tag. The queries can
then be used in ColdFusion code, just like the results of a
<cfquery> or any other tag that returns a
recordset. For instance, the queries can be used as the
query parameter of a <cfloop> or <cfoutput>
tag; they can even be re-queried or joined with other recordsets using in-memory-queries (where
you set
dbtype=”query” in a separate <cfquery> tag; also known as “query-of-queries”). Table 30.6
shows the Java methods for working with queries, and Table 30.7 shows the C++ versions.
NOTE
Any CFX tag can return any number of queries to the calling template, but it can only access the data in one query that already exists
in the calling template. To put it another way, multiple queries can be passed out from the CFX, but only one can be passed in.
Table 30.6 Java Methods for Working with Queries
METHOD DESCRIPTION
response.addQuery(name, columns) Creates a new query, which will be available in the
calling ColdFusion page when the CFX tag finishes
executing. Specify the
name of the query as a string,
and specify its
columns as an array of strings.
query.addRow() Adds a row to the query. You can then fill the
individual cells (columns) of the new row using
setData(). Returns the row number of the new
row, as an
int.
query.setData(row, col, value) Places the value (which must be a string) into the
query at the row and column position you specify.
Rows and columns are both numbered beginning
with 1. You can get the value for
col using
getColumnIndex().
request.getQuery() Retrieves the query (if any) that was passed to the
CFX tag. Returns a
Query object, or null if no
QUERY attribute was provided.
query.getColumnIndex(name) Returns the column index (position) of the column
with the given name. You can then use the index to
specify columns to
getData() and setData().
Returns
-1 if the column doesn’t exist.
query.getColumns() Returns the names of the query’s columns, as an
array of strings.
query.getData(row, col) Returns the value in the query at the given row and
column position. The value is always returned as a
string.
query.getName() Returns the name of the query (as a string), as it is
known in the calling ColdFusion page.
query.getRowCount() Returns the number of rows in the query, as an int.
Comentários a estes Manuais