> I am so use to using MX and CFCs that now I have to work on a CF5
> server for a client and 
> 
> Is there a good way of setting up a DAO in CF5 so I can reuse SQL
> code and not have to retype the CFQueryies each time I need them?
> 
> Should I use CFModule?  CFInclude?  A custom tag <CF_ProductDAO>?

Before I offer my thoughts on the actual question, I just wanted to stop
real briefly and mention, because it seemed like you got a couple responses
from folks who may not have been using ColdFusion since as far back as
ColdFusion 5 (or were distracted and didn't notice this was a CF5
question or remember offhand what CF5 supported). 

The cffunction tag was added in ColdFusion version 6. Prior to 6,
versions 5 and 5.5 (iirc), UDFs couldn't include any tags because they
had to be declared entirely in cfscript and there's never been any way
to embed tags in cfscript. So the suggestion of using UDF's is moot
(although I remember really *wanting* to do that in CF5). :) 

I actually had at the time created the first version of the SQL
abstraction layer that's in the onTap framework on ColdFusion 5 using
cfmodule. Though it was way more complicated than you likely need for
your purposes. That being said, you may find it easier to use custom
tags if you have access to the custom tags directory -- which in the
past I had always avoided like the plague, but given that if/when you
upgrade it will probably be to ColdFusion 8 where you can assign the
custom tag diretory in-application, the upgrade plan then makes that
transition easier. Using <cf_productDAO> for example would be a bit
easier to find if you needed to perform a multi-file search in your code,
than would be <cf_module template="../productDAO.cfm">. It's also fewer
keystrokes, which is another bonus. If/when you upgrade, you can then
rewrite the custom tags internally to use CFC-based DAO's, but in the
interrim, the custom tag syntax should make your work a bit less tedious
and give you a bit of flexibility to do things like sub-tags if you
found yourself in a situation where you were having difficulty creating
an elegant way of getting "argument" data into a "method". 

I might do something like this internally within the DAO tag: 

<cfparam name="attributes.method" type="string">
<cfset here = getDirectoryFromPath(getCurrentTemplatePath())>

<cfif fileExists(here & "productdao/" & attributes.method & ".cfm">
  <cfinclude template="#attributes.method#.cfm">
</cfif>

<cfif structKeyExists(variables,"result")>
  <cfparam name="attributes.return" type="string" default="">
  <cfif len(trim(attributes.return))>
    <cfset caller[attributes.return] = variables.result>
  </cfif>
</cfif>

The idea behind this structure is to give you a consistent interface for
the "methods". Each method has its own template and you'll know that
whatever it is you need to return goes in the "variables.result" variable
within that template and will then be returned by the custom tag, so you
don't have to keep rewriting the code that returns the result variable. 

anyway, that's my take,
hth,

ike

-- 
s. isaac dealey  ^  new epoch
 isn't it time for a change? 
     ph: 503.236.3691

http://onTap.riaforge.org/blog



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:295802
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to