20.22. Querying a Database with Server-Side ActionScript

Problem

You want to use Server-Side ActionScript (SSAS) to query a database.

Solution

Make sure the database is registered as a datasource with ColdFusion or JRun, and then use the query( ) method of the SSAS CF object.

Discussion

Server-Side ActionScript allows you to query any registered datasource by way of the CF.query( ) method. The first step is to make sure that your database has been properly registered with ColdFusion or JRun. If you are not sure how to do this, then you should consult your ColdFusion or JRun documentation.

The CF.query( ) method allows you to pass it the following arguments as either positional or named parameters:

datasource

The name of the datasource as registered with ColdFusion or JRun.

sql

The SQL command.

username

If the datasource requires a username, you can specify it with this parameter.

password

If the datasource requires a password, you can specify it with this parameter.

maxrows

You can optionally specify the maximum number of records to return.

timeout

An optional number of milliseconds to wait before timing out.

When you use the CF.query( ) method with positional parameters, you can specify one or more optional parameters in the following orders:

CF.query(datasource, sql);
CF.query(datasource, sql, maxrows);
CF.query(datasource, sql, username, password);
CF.query(datasource, sql, username, password, maxrows);

You can use the timeout parameter only if you used named parameters. Otherwise, ...

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.