Using the CF.query function



You use the CF.query function in your server-side ActionScript to retrieve data from a ColdFusion data source. This function lets you perform queries against any ColdFusion data source.

Note: The CF.query function maps closely to the cfquery CFML tag, although it currently supports a subset of the cfquery attributes.

Use the CF.query function to do the following:

  • Identify the data source you want to query.

  • Pass SQL statements to the data source.

  • Pass other optional parameters to the database.

For reference information about the CF.query function, see CF.query in the CFML Reference.

About CF.query function syntax

You can write the CF.query ActionScript function using either named arguments or positional arguments. The named argument style is more readable, but it requires more code. Although the positional argument style supports a subset of CF.query arguments, it allows a more compact coding style that is more appropriate for simple expressions of the CF.query function.

Using CF.query named argument syntax

The CF.query function accepts the following named arguments:

// CF.query named argument syntax 
CF.query 
    ({ 
        datasource:"data source name",  
        sql:"SQL stmts",  
        username:"username",  
        password:"password",  
        maxrows:number,  
        timeout:milliseconds  
    })
Note: The named argument style requires curly brackets {} to surround the function arguments.

Using CF.query positional argument syntax

Positional arguments support a subset of CF.query arguments, and you can create more efficient code. The following is the syntax for the positional argument style:

// CF.query positional argument syntax 
CF.query(datasource, sql); 
CF.query(datasource, sql, maxrows); 
CF.query(datasource, sql, username, password); 
CF.query(datasource, sql, username, password, maxrows);
Note: When using positional arguments, do not use curly braces {}.

About the CF.query record set

The CF.query function returns a RecordSet object, which is an instance of the RecordSet class of objects. The RecordSet class provides a wide range of functions for handling record set data.

You use methods in the RecordSet ActionScript class in your client-side ActionScript to change data returned in the CF.query record set.

Currently, the following methods are available in the RecordSet class:

Method

Description

addItem

Appends a record to the end of the specified RecordSet

addItemAt

Inserts a record at the specified index

addView

Requests notification of changes in a RecordSet object’s state

filter

Creates a RecordSet object that contains selected records from the original RecordSet object

getColumnNames

Returns the names of all the columns of the RecordSet

getItemAt

Retrieves a record from a RecordSet object

getItemID

Gets the unique ID corresponding to a record

getLength

Returns the total number of records in a RecordSet object

getNumberAvailable

Returns the number of records that have been downloaded from the server

isFullyPopulated

Determines whether a RecordSet object can be edited or manipulated

isLocal

Determines whether a RecordSet object is local or server-associated

removeAll

Removes all records from the RecordSet object

removeItemAt

Removes a specified record

replaceItemAt

Replaces the entire contents of a record

setDeliveryMode

Changes the delivery mode of a server-associated record set

setField

Replaces one field of a record with a new value

sort

Sorts all records by a specified compare function

sortItemsBy

Sorts all the records by a selected field

These functions are available for every RecordSet object returned by the CF.query function to the Flash client. You run these functions as follows:

objectName.functionName();

For example, in the result function that you create to handle record set data returned by the CF.query function, you can reference the database column names returned in the record set using the getColumnNames RecordSet function:

function selectData_Result ( result ) 
{ 
    //result holds the query data; employeesView is a Flash list box 
    stringOutput.text = result.getColumnNames(); 
    _root.employeesView.setDataProvider(result); 
}