Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 416

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Accessing and Using Data
Note: The terms "recordset" and "query object" are often used synonymously when discussing recordsets for queries. For
more information, see
"Using Query of
When retrieving data from a database, perform the following tasks:
• To tell ColdFusion how to connect to a database, use the
• To specify the data that you want to retrieve from the database, write SQL commands inside the
• Reference the query object and use its data values in any tag that presents data, such as
, or
.
cfgraph
cftree
The cfquery tag
The
tag is one of the most frequently used CFML tags. You use it to retrieve and reference the data returned
cfquery
from a query. When ColdFusion encounters a
• Connects to the specified data source.
• Performs SQL commands that are enclosed within the block.
• Returns result set values to the page in a query object.
The cfquery tag syntax
The following code shows the syntax for the
<cfquery name="EmpList" datasource="cfdocexamples">
SQL code...
</cfquery>
In this example, the query code tells ColdFusion to do the following:
• Connect to the cfdocexamples data source (the cfdocexamples.mdb database).
• Execute SQL code that you specify.
• Store the retrieved data in the query object EmpList.
When creating queries to retrieve data, keep in mind the following guidelines:
• Use opening
<cfquery>
• Enter the query
and
name
• To tell the database what to process during the query, place SQL statements inside the
• When referencing text literals in SQL, use single-quotation marks ('). For example,
WHERE FirstName='Jacob'
• Surround attribute values with double quotation marks ("attrib_value").
• Make sure that a data source exists in the ColdFusion Administrator before you reference it in a
• Columns and tables that you refer to in your SQL statement must exist, otherwise the query fails.
• Reference the query data by naming the query in one of the presentation tags, such as
, or
.
cfgraph
cftree
• When ColdFusion returns database columns, it removes table and owner prefixes. For example, if you query
Employee.Emp_ID in the query, the Employee, is removed and returns as Emp_ID. You can use an alias to handle
duplicate column names; for more information, see
• You cannot use SQL reserved words, such as MIN, MAX, COUNT, in a SQL statement. Because reserved words are
database-dependent, see the documentation of your database for a list of reserved words.
Queries" on page 428.
tag on a page, it does the following:
cfquery
tag:
cfquery
and ending
tags, because the
</cfquery>
attributes within the opening
datasource
selects every record from mytable in which the first name is Jacob.
"Using Query of
Last updated 1/20/2012
tag on a page.
cfquery
cfoutput
tag is a block tag.
cfquery
tag.
cfquery
SELECT * FROM mytable
cfoutput
Queries" on page 428.
block.
cfquery
,
,
,
cfgrid
cftable
block.
cfquery
tag.
cfquery
,
,
,
cfgrid
cftable
411

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents