
About Query of Queries
455
•
You can obtain drill-down, master-detail information for which you do not access the database
for the details.
For example, you can select information about departments and employees in a query, and
cache the results. You can then display the employees’ names. When users select an employee,
the application displays the employee’s details by selecting information from the cached query,
without accessing the database.
Performing a Query of Queries
There are four steps to perform a Query of Queries.
To perform a Query of Queries:
1
Generate a record set.
You can write a normal query using a tag or function that creates a record set. This is
sometimes called a
master query
. For more information, see
“Creating a record set”
on page 452
.
2
Write a
detail query
—a query that specifies
dbtype=
"
query"
in its
cfquery
tag.
3
In the detail query, write a SQL statement that retrieves the relevant records. Specify the names
of one or more existing queries as the table names in your SQL code. Do not specify a
datasource
attribute.
4
If the database content does not change rapidly, use the
cachedwithin
attribute of the master
query to cache the query results between page requests. This way, ColdFusion accesses the
database on the first page request, and does not query the database again until the specified time
expires. You must use the
CreateTimeSpan
function to specify the
cachedwithin
attribute
value (in days, hours, minutes, seconds format).
The detail query generates a new query results set, identified by the value of the
name
attribute of
the detail query. The following example illustrates the use of a master query and a single detail
query that extracts information from the master.
To use the results of a query in a query:
1
Create a ColdFusion page with the following content:
<body>
<h1>Employee List</h1>
<!--- LastNameSearch (normally generated interactively) --->
<cfset LastNameSearch="Doe">
<!--- Master Query --->
<cfquery datasource="CompanyInfo" name="master"
cachedwithin=#CreateTimeSpan(0,1,0,0)#>
SELECT * from Employee
</cfquery>
<!--- Detail Query (dbtype=query, no data source) --->
<cfquery dbtype="query" name="detail">
SELECT Emp_ID, FirstName, LastName
FROM master
WHERE LastName=<cfqueryparam value="#LastNameSearch#"
cfsqltype="cf_sql_char" maxLength="20"></cfquery>
Содержание ColdFusion MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...