About Query of Queries
457
Reviewing the code
The master query retrieves the entire Employee table from the CompanyInfo data source (the
CompanyInfo database). The detail query selects only the three columns to display for employees
with the specified last name. The following table describes the code and its function:
Displaying record set data incrementally
If your database is large, you can limit the number of rows displayed at one time. The following
example shows how to use the
currentRow
query variable of a Query of Queries to do this. For
more information on query variables, see
“Getting information about query results” on page 433
.
To display record set data incrementally:
1
Create a ColdFusion page with the following content:
<html>
<head>
<title>QoQ with incremental row return</title>
</head>
<body>
<h3>QoQ with incremental row return</h3>
<!--- define startrow and maxrows to facilitate 'next N' style browsing --->
<cfparam name = "MaxRows" default = "5">
<cfparam name = "StartRow" default = "1">
Code
Description
cfset LastNameSearch="Doe"
Sets the last name to use in the detail query. In a
complete application, this information comes
from user interaction.
<cfquery datasource="CompanyInfo"
name="master"
cachedwithin=#CreateTimeSpan(0,1,0,0)#>
SELECT * from Employee
</cfquery>
Queries the CompanyInfo data source and
selects all data in the Employees table. Caches
the query data between requests to this page,
and does not query the database if the cached
data is less than an hour old.
<cfquery dbtype="query" name="detail">
SELECT Emp_ID, FirstName, LastName
FROM master
WHERE LastName=<cfqueryparam
value=”#LastNameSearch#"
cfsqltype=”cf_sql_char”
maxLength="20"></cfquery>
Uses the master query as the source of the data
in a new query, named detail. This new query
selects only entries that match the last name
specified by the
LastNameSearch
variable. The
query also selects only three columns of data:
employee ID, first name, and last name. The
query uses the
cfqueryparam
tag to prevent
passing erroneous or harmful code.
<cfoutput query=detail>
#Emp_ID#: #FirstName# #LastName# <br>
</cfoutput>
Uses the detail query to display the list of
employee IDs, first names, and last names.
<cfoutput>
#master.columnlist#<br>
</cfoutput>
Lists all the columns returned by the master
query.
<cfoutput>
#detail.columnlist#<br>
</cfoutput>
Lists all the columns returned by the detail
query.
Summary of Contents for COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......