Title: CFC base class with arbitray arguments calling a virtual function

Greetings,

I have a base class for our data access which defines a "GetRecordset" method. This method can have any number of arguments passed to it. The GetRecordset is in the base class and it calls a pseudo-virtual method to get the table specific SQL.

I need to pass the arguments from GetRecordset to the virtual function so the developer creating the table specific class can parse the arguments for the dynamic SQL.

Note: I left the <CFARGUMENT tags out of both functions on purpose because i am unsure what to put.

Any ideas?


Here's a sample of the code:

<cfcomponent name="basecomponent">

        <cfset THIS.errormsg = "">
        <cfset THIS.dsn = "">

        <cffunction name="Init" returntype="boolean">
                <cfargument name="dsn" type="string" required="false">

                <cfset retval = True>
                <cftry>
                        <!--- set datasource --->
                        <cfif THIS.dsn IS "">
                                <cfif isdefined("ARGUMENTS.dsn")>
                                        <cfset THIS.dsn = "#ARGUMENTS.dsn#">
                                </cfif>
                        </cfif>
                        <cfcatch>
                                <cfscript>
                                        SaveErrorInfo(CFCATCH);
                                </cfscript>
                                <cfset retval = False>
                        </cfcatch>
                </cftry>
                <cfreturn retval>
        </cffunction>

        <cffunction name="GetRecordset" displayname="Get Recordset as query variable">

                <cfif THIS.dsn IS NOT "">
                        <cftry>
                                <cfquery datasource="#THIS.dsn#" name="qryGetRecordset">
                                        #OnGetRecordset()#
                                </cfquery>
                                <cfcatch type="database">              
                                        <cfscript>
                                                SaveErrorInfo(CFCATCH);
                                        </cfscript>
                                </cfcatch>
                        </cftry>
                </cfif>
       
                <cfreturn qryGetRecordset>
        </cffunction>

        <!--- virtual method --->
        <cffunction name="OnGetRecordset">
        </cffunction>

        <cffunction name="SaveErrorInfo" access="private">
                <cfargument name="catchobject" type="any" required="true">
                <cfset THIS.errormsg = "CFCATCH.message=" & ARGUMENTS.catchobject.message
                        & "<br>cfcatch.NativeErrorCode=" & ARGUMENTS.catchobject.NativeErrorCode
                        & "<br>cfcatch.SQLState=" & ARGUMENTS.catchobject.SQLState & "<br>" & ARGUMENTS.catchobject.detail>

        </cffunction>
</cfcomponent>

<cfcomponent extends="basecomponent" name="tablespecific">
        <cffunction name="OnGetRecordset">
                SELECT DELIVERY_CODE, DELIVERY_TYPE FROM FITSOWNER.DELIVERY_DATA_CODES
                <cfif isdefined("ARGUMENTS.code")>
                        where DELIVERY_CODE = '#ARGUMENTS.code#'
                <cfelseif isdefined("ARGUMENTS.type")>
                        where DELIVERY_TYPE = '#ARGUMENTS.type#'
                </cfif>
        </cffunction>
</cfcomponent>



Roy Hinkle
Advanced Information Engineering Systems (formerly Veridian)
301.863.4352 (phone)
301.863.4443 (fax)
[EMAIL PROTECTED]


Reply via email to