It appears, since I am brand new to cfcs, that I didn't know enough yet
to ask the right questions so here it goes.
========= APPLICATION.CFM ==========
<!--- Set Global DSN --->
<cfset request.dsn = "mydatabase" />
<!--- Instantiate Inventory Objects --->
<cfif not isDefined("application.init") or isDefined("url.reinit")>
<cfset application.inventory =
createObject("component","cfcs.inventory").init(request.dsn) />
<cfset application.init = true>
</cfif>
======== INVENTORY.CFM =========
<cfsilent>
<cfparam name="selSortBy" default="Name">
<cfparam name="selInventoryID" default="0">
<cfparam name="selClass_Name" default="">
<cfparam name="selSubClass_Name" default="">
<cfparam name="selSize" default="">
<cfparam name="selStartRow" default="1">
<cfparam name="selMaxRows" default="75">
<cfset qryInventory =
application.inventory.getInventory('#selSortBy#','#selInventoryID#','#selClass_Name#','#selSubClass_Name#','#selSize#')
/>
</cfsilent>
========== INVENTORY.CFC ==============
<cfcomponent hint="Inventory Object">
<cfset variables.dsn = "" />
<cfset variables.inventory = "" />
<cffunction name="init" access="public" returnType="inventory"
output="false" hint="I instantiate qry">
<cfargument name="dsn" type="string" required="yes" />
<!--- initiate value(s) --->
<cfset variables.dsn = arguments.dsn />
<cfset variables.inventory = "none" />
<cfreturn this />
</cffunction>
<!--- getInventory - List inventory method --->
<cffunction name="getInventory" returntype="query" access="public"
HINT="Returns all inventory as 'qryInventory', can pass optionally
selSortBy to sort query">
<cfargument name="selSortBy" required="false" type="string"
default="Class, Class_Name" />
<cfargument name="selInventoryID" required="false" type="numeric"
default="0" />
<cfargument name="selClass_Name" required="false" type="string"
default="" />
<cfargument name="selSubClass_Name" required="false" type="string"
default="" />
<cfargument name="selSize" required="false" type="string" default="" />
<cfquery name="qryInventory" datasource="#variables.dsn#">
SELECT
InventoryID, Class, Class_Name, SubClass_Code, SubClass_Name,
Brand, Name, [Size],
Regular_Whse_Case, Whse_Case, Whse_Bottle, Regular_Store_Bottle,
Store_Bottle, Broker_Name, Broker_Phone
FROM
Inventory
WHERE Class_Name is not null
<cfif arguments.selInventoryID neq 0>
and InventoryID = <cfqueryparam cfsqltype="CF_SQL_INTEGER"
value="#arguments.selInventoryID#" />
</cfif>
<cfif arguments.selClass_Name neq "">
and Class_Name = <cfqueryparam cfsqltype="CF_SQL_VARCHAR"
value="#arguments.selClass_Name#" />
</cfif>
<cfif arguments.selSubClass_Name neq "">
and SubClass_Name = <cfqueryparam cfsqltype="CF_SQL_VARCHAR"
value="#arguments.selSubClass_Name#" />
</cfif>
<cfif arguments.selSize neq "">
and Size like <cfqueryparam cfsqltype="CF_SQL_VARCHAR"
value="%#arguments.selSize#%" />
</cfif>
Order by
<!--- Filter SQL Injection --->
<cfelseif arguments.selSortBy eq "Class">
Class
<cfelseif arguments.selSortBy eq "Class Desc">
Class Desc
<cfelseif arguments.selSortBy eq "Class, SubClass_Name">
Class, SubClass_Name
<cfelseif arguments.selSortBy eq "Class Desc, SubClass_Name Desc">
Class Desc, SubClass_Name Desc
<cfelse>
Class, Class_Name
</cfif>
</cfquery>
<cfreturn qryInventory />
</cffunction>
</cfcomponent>
I am late to CFCs, which is perfectly obvious. I'm now looking to get
it "right" out of the gate this time so everyone's help thus far is very
much appreciated!
If I add a new method in inventory.cfc called addInventory(), do I need
to worry about resetting/refreshing the query qryInventory which is
returned by the method getInventory? If so why and how and if not
should I do this differently because there is a better, more optimal way
that does require a refresh?
Thanks,
Vince
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Check out the new features and enhancements in the
latest product release - download the "What's New PDF" now
http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:288986
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4