Friday, March 19, 2010    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Apr 2007 >>
S M T W T F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          

Search

Categories
 • Acrobat (3) [RSS]
 • Adobe (90) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (66) [RSS]
 • AdobeMAX09 (39) [RSS]
 • AdobeMAX10 (1) [RSS]
 • AIR (219) [RSS]
 • Appearances (191) [RSS]
 • Books (72) [RSS]
 • CFEclipse (15) [RSS]
 • ColdFusion (1381) [RSS]
 • Data Services (34) [RSS]
 • Fish Tank (5) [RSS]
 • Flash (197) [RSS]
 • Flex (498) [RSS]
 • Home Automation (5) [RSS]
 • Jobs (116) [RSS]
 • JRun (14) [RSS]
 • Labs (43) [RSS]
 • LiveCycle (34) [RSS]
 • MAX (232) [RSS]
 • Mobile (120) [RSS]
 • Regular Expressions (17) [RSS]
 • RIA (21) [RSS]
 • SQL (40) [RSS]
 • Stuff (536) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (162) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • Mark Doherty
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
April 29, 2007

Using Scorpio ArgumentsCollection

CFML is a tag based language. When tags need arguments or options passed to them, they are passed as attributes. This is an integral part of what makes CFML so easy and so productive. But sometimes, having to pass attributes can be a hindrance. Consider a simple example, a <CFQUERY> where you sometimes just need basic attributes (NAME and DATASOURCE perhaps) but other times want additional optional attributes (like USERNAME and PASSWORD). There is no way to conditionally include attributes in a tag, and so you end up having to write code like this:

<CFIF some condition>
    <CFQUERY NAME="myQuery" DATASOURCE="myDSN">
    ...
    </CFQUERY>
<CFELSE>
    <CFQUERY NAME="myQuery" DATASOURCE="myDSN"
            USERNAME="#SESSION.username#"
            PASSWORD="#SESSION.password#">

    ...
    </CFQUERY>
</CFIF>

It's just an example, but it's not pretty at all. And this same is true if you conditionally want to add query caching, or specify an SMTP server in <CFMAIL>, and so on.

Scorpio solves this problem in the simple and elegant fashion we've come to expect from ColdFusion. In Scorpio you can pass all tag attributes as a single structure, an ARGUMENTSCOLLECTION. Here is a simple <CFQUERY>:

<CFSET args=StructNew()>
<CFSET args.name="myQuery">
<CFSET args.datasource="myDSN">
<CFQUERY ARGUMENTSCOLLECTION="#args#">
...
</CFQUERY>

As structure members can be added conditionally, passing optional attributes becomes a simple matter of conditionally adding members, as seen here:

<CFSET args=StructNew()>
<CFSET args.name="myQuery">
<CFSET args.datasource="myDSN">
<CFIF some condition>
    <CFSET args.username=SESSION.username>
    <CFSET args.password=SESSION.password>
</CFIF>
<CFIF condition that determines that caching is needed>
    <CFSET args.cachedwithin=CreateTimeSpan(0,0,0,1,0,0)>
</CFIF>
<CFQUERY ARGUMENTSCOLLECTION="#args#">
...
</CFQUERY>

This new syntax can be used by all sorts of tags, including <CFCONTENT>, <CFFILE>, <CFFTP>, <CFIMAGE>, <CFMAIL>, <CFXML>, and many more.

Related Blog Entries

TrackBacks
Scorpio Adds ArgumentsCollection to Tags
Ben Forta just posted an entry talking about a new feature to be available in Scorpio. It gives a great example on his blog that many CF developers come across in every one of their database integrated applications.
Tracked by Kyle Hayes | Tracked on 4/30/07 9:52 AM

No trackback URL. Trackbacks are only allowed via interactive form.

Comments

  © Copyright 1997-2009 Ben Forta, All Rights Reserved