Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prepared Statements 1

Status
Not open for further replies.

evergrean100

Technical User
Dec 1, 2006
115
US
Does Cold Fusion support PreparedStatements?

I use them in Java and was wondering if Cold Fusion also has them for SQL inserts and updates into Oracle and Access databases?
 
evergrean100,

Cf uses a tag called cfqueryparam to achieve this, with my limited knowledge of jsp.

a query like:

Code:
<cfquery datasource="..">
  INSERT INTO tblOne (ID, Title)
  VALUES (10, 'TEST')
</cfquery>

would become:

Code:
<cfquery datasource="..">
  INSERT INTO tblOne (ID, Title)
  VALUES (<cfqueryparam cfsqltype="cf_sql_integer" value="10">, <cfqueryparam cfsqltype="cf_sql_varchar" value="TEST">)
</cfquery>

If you have debug turned on then you will see the statement that is sent to the database is near to the jsp syntax, with the above queryparams being replaced with question marks, and the values below those. This is mainly because CF compiles down to java.

The above will work on any database platform that you have a driver for, and cf ships with drivers for oracle and access.

If you want to know more about the queryparam tag have a look on live docs:


You can also use stored procedures if you want to, which work in the same sort of way:

Code:
<cfstoredproc datasource="..." procedure="sp_insert">
	<cfprocparam type="in" cfsqltype="cf_sql_integer" value="10">
	<cfprocparam type="in" cfsqltype="cf_sql_varchar" value="Test">
</cfstoredproc>

Live docs:
Hope this helps!

Tony
 
Thanks, good info. I assume from your example the queryparam is equal to a preparedStatement in Java.
 
The best way to determine how the statements are handled is to enable tracing and review the actual statements sent to the database. IIRC MS SQL for example does an sp_prepexec call for queries containing cfqueryparam. Subsequent calls of the query are run through sp_execute. I don't know about stored procedures.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top