You have the right idea. I would just be concerned with cfc bloat since you
could be mirroring methods.

If you'd like to stay clear of this you can consider breaking out your
components into folders that represent the database engine itself.

Below is an example:
dao
  + mssql
      + customerDAO.cfc
      + userDAO.cfc
  + mysql
      + customerDAO.cfc
      + userDAO.cfc
  + oracle
      + customerDAO.cfc
      + userDAO.cfc

This would allow you to keep the cfc's nice a clean and your switch can
simply be what database engine (folder) to use. You could always build a
simple service (like daoService.cfc) that can gather the desired cfc.

Below is an example (note: not tested):
<cfcomponent>

    <cfset variables.dbengine = "" />

    <cffunction name="init" returntype="any">
        <cfargument name="dbengine" type="string" required="true" />
        <cfset variables.dbengine = arguments.dbengine />
        <cfreturn this />
    </cffunction>

    <cffunction name="getDAO" returntype="any">
        <cfargument name="dao" type="string" required="true" />
        <cfreturn createObject( "component",
"dao.#variables.dbengine#.#arguments.dao#").init() />
    </cffunction>

</cfcomponent>

Doing this allows you the simplicity to have one place where your database
engine variable exists. It would keep your code clean as well as your cfc's.

This may not be everyone's approach, but it's one I use plenty and it pays
off in the end.

-Pat (patweb99)

On Sat, Oct 24, 2009 at 4:18 PM, Ramon Ecung <[email protected]> wrote:

>
> Just curious how others handle making their programs capable of being run
> on multiple databases. I'm currently running Oracle XE and MySQL and I want
> to develop my next application for both databases mainly for the experience,
> but also so I can learn more about the differences between MySQL and Oracle.
>
> My main thought on this was to create two functions in my cfc for every
> where/transaction I need (one for Oracle, one for MySQL) and just have a
> variable in my allplication.cfc that tells the code which function to call.
>
> Is this the best way? Does anyone else have experience doing something like
> this?
>
> -Ramon Ecung II
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:327654
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to