6 CHAPTER 30 Extending ColdFusion with CFX
Table 30.7 C++ Methods for Working with Queries
METHOD DESCRIPTION
pRequest->AddQuery(name, columns) Creates a new query. Specify the name of the query
as a
LPCSTR, and columns as a CCFXStringSet
(similar to an array of strings).
pQuery->AddRow() Adds a row to the query.
pQuery->SetData(row, col, value) Places the value (which must be a LPCSTR) into the
query at the row and column position you specify.
pRequest->GetQuery() Retrieves the query (if any) that was passed to the
CFX tag. Returns a
CCFXQuery object, or null if no
QUERY attribute was provided to the tag.
pQuery->GetColumns() Returns the names of the query’s columns, as a
CFXStringSet, which is similar conceptually to an
array of strings. You can use any of the methods
listed in Table 30.8 on the returned
CFXStringSet.
For instance, you can use
GetIndexForString() to
find the index position of a column by name; that
index position could then be used in the
GetData()
or SetData() functions.
pQuery->GetData(row, col) Returns the value in the query at the given row and
column position. The value is always returned as a
LPCSTR.
pQuery->GetName() Returns the name of the query (as a LPCSTR), as it is
known in the calling ColdFusion page.
pQuery->GetRowCount() Returns the number of rows in the query, as an int.
To pass a query to a CFX tag, the name of the query must be specified as an attribute named QUERY
(you don’t get to determine the name of the attribute). So, if a query=”FilmsQuery” attribute is sup-
plied when the tag is called, then the
getQuery() method will grab the query for use inside of the
CFX tag. You can then use
getRecordCount(), getColumns(), and getData() to refer to the data in
the query.
Because standard C++ doesn’t have a built-in notion of an ordered set of strings, the CFX API
includes an additional class type called
CFXStringSet, which is similar conceptually to an array of
strings in Java. An object of this type is returned if you call the
GetAttributes() method listed in
Table 30.3 or the
GetColumns() method from Table 30.7. Similarly, to create a new query object,
you first create a new
CFXStringSet, add column names to the string set using AddString(), then
pass the string set to the
AddQuery() method (also listed in Table 30.7). The methods supported by
this class are listed in Table 30.8.
NOTE
This part of the CFX API is only included in the C++ version. There is no need for it in Java, which already includes the notion of a
string set (the
String[] type).
Commenti su questo manuale