22.08.2013 Views

ColdFusion Developer's Guide

ColdFusion Developer's Guide

ColdFusion Developer's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta<br />

Optimizing database use<br />

Poor database design and incorrect or inefficient use of the database are among the most<br />

common causes of inefficient applications. Consider the different methods that are available<br />

for using databases and information from databases when you design your application. For<br />

example, if you need to average the price of a number of products from an SQL query, it is<br />

more efficient to use SQL to get the average than to use a loop in <strong>ColdFusion</strong>.<br />

Two important <strong>ColdFusion</strong> tools for optimizing your use of databases are the cfstoredproc<br />

tag and the cfquery tag cachedWithin attribute.<br />

Using stored procedures<br />

The cfstoredproc tag lets <strong>ColdFusion</strong> use stored procedures in your database management<br />

system. A stored procedure is a sequence of SQL statements that is assigned a name,<br />

compiled, and stored in the database system. Stored procedures can encapsulate programming<br />

logic in SQL statements, and database systems are optimized to execute stored procedures<br />

efficiently. As a result, stored procedures are faster than cfquery tags.<br />

You use the cfprocparam tag to send parameters to the stored procedure, and the<br />

cfprocresult tag to get the record sets that the stored procedure returns.<br />

The following example executes a Sybase stored procedure that returns three result sets, two of<br />

which the example uses. The stored procedure returns the status code and one output<br />

parameter, which the example displays.<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

The output param value: '#foo#'<br />

<br />

The Results Information<br />

356 Designing and Optimizing a <strong>ColdFusion</strong> Application

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!