Tally List : mailing list management, archiving, and analysis
click for archive home
 
Archive of:
CFtipsPlus
Cold Fusion tips email (external)
 
home
24 hour view
quick stats
weekly updates
 
all tallylists
corporate solutions
archive your favorite
help / feedback


Search the Tallylist search by keyword:

About Cold Fusion Tips :
product's home
product's list home
 
  Archived TallyList / CFtipsPlus: 
Subject: CF010102 | CFSWITCH | Scroll Background | SQL and Single Quotes
Nathan Stanford (23p/+0r)     Posted: Saturday 13 Jan 2001
This post: 173 views, +0 rating

============== ColdFusion TIPS PLUS ColdFusion 01 Volume 01 Issue 02 =============================================================== http://www.cftipsplus.com ============== Issue 00041 ============== I. Comments:

II. ColdFusion Tip: Making the case for <CFSWITCH> By Kevin Schmidt, Web Technology Manager Allaire Certified Cold Fusion Developer schmidt@pwb.com

III. JavaScript Tip: Scroll Background Image Kimon Tinker ktinker@go.com

IV. ColdFusion Tip: SQL and Single Quotes By Michael Smith michael@teratech.com

============== I. Comments: Recently I was diagnosed with Type 2 Diabetes and have been to a control diabetes class. Learning to live with it will be a challenge and will require some lifestyle changes.

We appreciate the tips we have been receiving from some of you. If you have solved a problem while at work change the DSN and the Variable names and tell us what the problem was and how you solved it. If you would like and it is chosen we will put your name and email on the tip we send out.

Keep me in your prayers, Nathan Stanford

=============================================================== If you have any suggestions please email me at cftips@nsnd.com. ===============================================================

=============================================================== II. ColdFusion Tip: Making the case for <CFSWITCH> By Kevin Schmidt, Web Technology Manager Allaire Certified Cold Fusion Developer schmidt@pwb.com =============================================================== <CFSWITCH> is often times overlooked in ColdFusion however it is a very powerful tag and many people don't realize the benefits it accords. The official definition of the tag is as follows: the <CFSWITCH> tag evaluates a passed expression and passes control to the CFCASE tag that matches the expression result. (From the Allaire Documentation) Lets look at the syntax of the tag first.

<CFSWITCH> has two required attributes and one optional one. The first required attribute is EXPRESSION. EXPRESSION is any CF expression that yields a scalar value. So numbers, dates, booleans, and strings all work fine. The next required attribute is VALUE. VALUE is actually contained in the <CFCASE> tag nested inside of <CFSWTICH>. VALUE contains the constant value that is compared to the expression value. The <CFCASE> tag also contains the conditional code that is to be executed when the VALUE attribute matches the EXPRESSION attribute. The final and optional attribute is DELIMETERS. It specifies the character that separates multiple values in a list. The default separator is a comma (,).

So exactly when might you want to use this tag? The best case for the use of this tag is to take the place of multiple <CFIF> statements. By using <CFSWITCH> rather than multiple <CFIF> statements you gain a slight improvement in performance. So lets look at an example. Suppose you have a user who is submitting a form and on the next page you need to show code based on what they chose. You could use <CFIF> statements to in order to determine what to display but by using the code from below you will save some time and as stated before pick up a slight performance gain.

<CFSWITCH EXPRESSION="#form.expression#"> <CFCASE VALUE="condition1"> <!--- Code to execute ---> </CFCASE>

<CFCASE VALUE="condition2"> <!--- Code to execute ---> </CFCASE>

<CFCASE VALUE="condition3"> <!--- Code to execute ---> </CFCASE>

<CFDEFAULTCASE> <!--- Code to execute ---> </CFDEFAULTCASE> </CFSWITCH>

In the above code I used the <CFDEFAULTCASE> tag which I haven't explained yet. This tag specifies a default case in the event that the value of the expression is not matched in any of the <CFCASE> tags. As a general rule I use <CFSWITCH> any time I have more than two <CFIF> statements. Well now you are ready to try this one out for yourself. If you have any questions feel free to email me at mailto:schmidt@pwb.com

Until next time Happy CFing.

Kevin Schmidt, Web Technology Manager Allaire Certified Cold Fusion Developer ============== III. JavaScript Tip: Scroll Background Image Kimon Tinker ktinker@go.com ============== Here is some JavaScript that I like...it scrolls the background image slowly downward. You adjust the '450' in this script to match the height in pixels of your background image. I borrowed it from somewhere, so I don't know where to give credit. <script language="JavaScript"> <!-- Begin

var backgroundOffset = 0;

var bgObject = eval('document.body');

function scrollBG(maxSize) { backgroundOffset = backgroundOffset + 1; if (backgroundOffset > maxSize) backgroundOffset = 0; bgObject.style.backgroundPosition = "0 " + backgroundOffset; }

var ScrollTimer = window.setInterval("scrollBG(450)",66);

// End --> </script>

============== IV. ColdFusion Tip: SQL and Single Quotes By Michael Smith michael@teratech.com ============== http://www.teratech.com/coldcuts/cutdetail.cfm?cutid=118 ==============

How do you to create a workaround for single quote characters when using them in a where statement of SQL?

Example:

form.fieldparam = "Phillip O'Grady"

note the single quote in O'GradyÂ…

SQL statement:

SELECT * FROM tablename WHERE field = '#form.fieldparam#'

Use the PreserveSingleQuotes function in CF. This doubles up the single quotes and that is the SQL escape sequence to pass a single quote within a string.

WHERE field = '#PreserveSingleQuotes(form.fieldparam)#'

Instead of WHERE field ='Phillip O'Grady'

you will get WHERE field = 'Phillip O''Grady'

============== Publisher and Creator: Nathan Stanford, mailto:admin@cftipsplus.com Web Developer: Dain Anderson, mailto:danderson@cftipsplus.com ============== Copyright (c) 2000 - 2001 CFTIPSPLUS.COM and NSND.COM Permission is granted to circulate this publication via MANUAL forwarding by email to friends provided that the text is forwarded in its entirety and no fee is charged. ==============

============== To unsubscribe: unsubscribe-cftips@nsnd.com

To subscribe: subscribe-cftips@nsnd.com ==============

____________________________________________________________ T O P I C A -- Learn More. Surf Less. Newsletters, Tips and Discussions on Topics You Choose. http://www.topica.com/partner/tag01


Similar Subject Line Posts (+/- two weeks of this post)
CF010102 | CFSWITCH | Scroll Background | SQL and Single Quotes  13 Jan 2001 (this post)   (173 v/ +0 r)
 

Send a reply to the CFtipsPlus list!
click to send a reply! NOTE: Many lists will reject your post unless you have already registered with them. Also - don't forget the right account to send from (for those with multiple emails!)

Feedback: If this post was exceptionally helpful, please help by giving this post a positive review.

 

TallyList : copyright Ububik - 2000