For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Document Cloud
  • Acrobat DC
  • eSign
  • Stock
  • Elements
  • Marketing Cloud
  • Analytics
  • Audience Manager
  • Campaign
  • Experience Manager
  • Media Optimizer
  • Target
  • See all
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Marketing Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
    • About Us
    • Careers At Adobe
    • Investor Relations
    • Privacy  |  Security
    • Corporate Responsibility
    • Customer Showcase
    • Events
    • Contact Us
News
    • 3/22/2016
      Adobe Summit 2016: Are You An Experience Business?
    • 3/22/2016
      Adobe Announces Cross-Device Co-op to Enable People-Based Marketing
    • 3/22/2016
      Adobe and comScore Advance Digital TV and Ad Measurement
    • 3/22/2016
      Adobe Marketing Cloud Redefines TV Experience
CFML Reference / 

query

Adobe Community Help


Applies to

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

Description

Used to execute a query passing SQL statements to a data source using CFScript.

Syntax

Mode

Syntax

Creating the service

new query() or createObject("component", "query")

Initializing the attributes

Any one of the following:

  • queryService=new query(attribute-value_pair)
  • queryService.setAttributes(attribute-value_pair)
  • queryService.set_AttributeName_(attribute_value)
  • queryService.execute(attribute-value_pair)

Executing the service action

queryService.execute(attribute-value_pair)

Properties

name

blockfactor

cachedafter

cachedwithin

dataSource

dbtype

debug

maxRows

password

result

timeout

username

sql

 

 

 

All attributes supported by the tag cfquery can be used as attribute-value pairs. For example,

<cfquery Name="myName"> </cfquery>

can be used as

queryService.setName("myName");

See also

cfquery, Function summary

History

ColdFusion 9: Added this function.

Methods

  • addParam

    Description

    Used in CFScript to add cfqueryparam tags to:

     

  • Verify the data type of a query parameter
  • For DBMSs that support bind variables, to enable ColdFusion to use bind variables in the SQL statement

    Syntax

    serviceName.addParam(attribute-value pair)

    Returns

    Nothing

    Arguments

    All attributes supported by cfqueryparam tag can be used as attribute-value pairs.

     

  • execute

    Description

    Used to execute SQL statements.

    Returns

    A component with the following properties set:

     

  • Result: For SQL queries that return a result set, for example, a "SELECT" SQL query.
  • Prefix: Equivalent to the result attribute for the cfquerytag.

    Syntax

    queryService.execute(attribute-value pair)

    Arguments

    All attributes supported by the cfquery tag.

     

  • setAttributes

    Description

    Sets attributes for the query function.

    Returns

    Nothing

    Syntax

    queryService.setAttributes (attribute-value pair)

    Arguments

    All attributes supported by the cfquery tag.

     

  • getAttributes

    Description

    Gets attributes that were set for the query function.

    Returns

    Returns a struct with all or some of the attribute values.

    Syntax

    queryService.get_Attributes_ (attributelist)

    Arguments

    A comma-separated list of attributes. If no list is specified, all defined attributes are returned.

     

  • clearAttributes

    Description

    Removes all attributes added for the query function.

    Returns

    Nothing

    Syntax

    queryService.clearAttributes(attribute_list)

    Arguments

    A comma-separated list of attributes.

     

  • clearParams

    Description

    Removes queryparams that were added using the addParam method.

    Returns

    Nothing

    Syntax

    queryService.clearParams()

    Arguments

    None

     

  • clear

    Description

    Removes all attributes and queryparms that were added using the addParam method.

    Returns

    Nothing

    Syntax

    queryService.clear()

    Arguments

    None

     

Usage

This function corresponds to the cfquery tag. For usage information, see Usage details for cfquery.

Example

<cfscript>
/*
This example shows how to create a query service in cfscript, set/get attributes using implict setters/getters, and also
how to execute the query and access the resultset
*/
param MaxRows="10";
param StartRow="1";
/*
Query database for information if cached database information has
not been updated in the last six hours; otherwise, use cached data.
*/
/* create a quey service */
queryService = new query();
/* set properties using implict setters */
queryService.setDatasource("cfdocexamples");
queryService.setName("GetParks");
queryService.setcachedwithin(CreateTimeSpan(0, 6, 0, 0));
/* Add sql queryparams using named and positional notation */
queryService.addParam(name="state",value="MD",cfsqltype="cf_sql_varchar");
queryService.addParam(value="National Capital Region",cfsqltype="cf_sql_varchar");
/* invoke execute() on the query object to execute the query and return a component with properties result and prefix (which can be accessed as implcit getters) */
result = queryService.execute(sql="SELECT PARKNAME, REGION, STATE FROM Parks WHERE STATE = :state and REGION = ? ORDER BY ParkName, State ");
GetParks = result.getResult();
/* getPrefix() returns information like recordcount,sql etc (typically whatever one gets if one uses the result attribute of the cfquery tag */
metaInfo = result.getPrefix();
</cfscript>
<cfoutput>
<h4>Found #metaInfo.recordcount# records for '#metainfo.sqlparameters[2]#' in the state '#metainfo.sqlparameters[1]#' </h4>
</cfoutput>
<!--- Build HTML table to display query. ------------------------->
<table cellpadding="1" cellspacing="1">
<tr>
<td bgcolor="f0f0f0">
&nbsp;
</td>
<td bgcolor="f0f0f0">
<b><i>Park Name</i></b>
</td>
<td bgcolor="f0f0f0">
<b><i>Region</i></b>
</td>
<td bgcolor="f0f0f0">
<b><i>State</i></b>
</td>
</tr>
<!--- Output the query and define the startrow and maxrows parameters.
Use the query variable CurrentCount to keep track of the row you are displaying. ------>
<cfoutput query="GetParks" startrow="#StartRow#" maxrows="#MaxRows#">
<tr>
<td valign="top" bgcolor="ffffed">
<b>#GetParks.CurrentRow#</b>
</td>
<td valign="top">
<font size="-1">#ParkName#</font>
</td>
<td valign="top">
<font size="-1">#Region#</font>
</td>
<td valign="top">
<font size="-1">#State#</font>
</td>
</tr>
</cfoutput>
<!--- If the total number of records is less than or equal to the total number of rows,
then offer a link to the same page, with the startrow value incremented by maxrows
(in the case of this example, incremented by 10). --------->
<tr>
<td colspan="4">
<cfif (StartRow + MaxRows) LTE GetParks.RecordCount>
<cfoutput><a href="#CGI.SCRIPT_NAME#?startrow=#Evaluate(StartRow + MaxRows)#">
See next #MaxRows# rows</a></cfoutput>
</cfif>
</td>
</tr>

 

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Southeast Asia (Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam) - English
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2016 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices