Deleting Data with ColdFusion


ColdFusion is very efficient at adding and updating data, but not at deleting it. DELETE is always a dangerous operation, and the ColdFusion developers didn't want to make it too easy to delete data by mistake.

To delete data in a ColdFusion template, you must use the SQL DELETE statement, as shown in Listing 14.12. The code first checks to ensure that a FilmID was passed; if the URL.FilmID field isn't present, the statement terminates. If a FilmID is passed, a <cfquery> is used to pass a SQL DELETE statement to the data source.

See Chapter 6 for an explanation of the DELETE statement.


Listing 14.12. delete1.cfmDeleting Table Data with SQL DELETE
 <!--- Name:        delete1.cfm Author:      Ben Forta (ben@forta.com) Description: Table row delete demo Created:     12/21/04 ---> <!--- Check that FilmID was provided ---> <cfif NOT IsDefined("FilmID")>  <h1>You did not specify the FilmID</h1>  <cfabort> </cfif> <!--- Delete a movie ---> <cfquery datasource="ows"> DELETE FROM Films WHERE FilmID=#FilmID# </cfquery> <!--- Page header ---> <cfinclude template="header.cfm"> <!--- Feedback ---> <h1>Movie deleted</h1> <!--- Page footer ---> <cfinclude template="footer.cfm"> 

No <cfdelete> tag exists in ColdFusion. The only way to delete rows is to use a SQL DELETE.



Macromedia Coldfusion MX 7 Web Application Construction Kit
Macromedia Coldfusion MX 7 Web Application Construction Kit
ISBN: 321223675
EAN: N/A
Year: 2006
Pages: 282

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net