O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required