Kapitaine
2007-03-30 20:29:25 UTC
Hi all,
I have many functions in my CFC that do various things, but one query is a
query that selects absolutely every record from a table.
The thing is, I need to do a query like this in another function to obtain
only a recordcount of the same table used in both separate functions. Instead
of writing the query out again, how can I utilise the function already written?
My question is, how can I invoke and use the results of a query in one
cffunction for another cffunction in the same CFC component?
An example may look like the code attached...
Many thanks for your patience and help!
Mikey.
<cffunction name="getItems" access="remote" returntype="query" hint="Gets All
Website Items That Aren't Deleted">
<cfargument name="item_id" type="numeric" required="yes" default="0" />
<cfquery name="items" datasource="#request.dsn#"
username="#request.username#" password="#request.password#">
SELECT *
FROM #request.tbl_items#
WHERE item_parent_id = <cfqueryparam value="#arguments.item_id#"
cfsqltype="cf_sql_integer" />
AND item_deleted = 'No'
ORDER BY item_order ASC
</cfquery>
<cfreturn items />
</cffunction>
<cffunction name="update" access="remote" returntype="query" hint="My Query
using the function above">
<cfargument name="item_id" type="numeric" required="yes" default="0" />
<cfquery name="items" datasource="#request.dsn#"
username="#request.username#" password="#request.password#">
UPDATE item_id
SET item_number
WHERE some_other_column = ####### THE INVOKED RECORDCOUNT OF getItems WOULD
BE HERE #######
</cfquery>
<cfreturn items />
</cffunction>
** The update query is not a real one so things are a bit wrong but I hope you
get the idea of using results from one query in another **
I have many functions in my CFC that do various things, but one query is a
query that selects absolutely every record from a table.
The thing is, I need to do a query like this in another function to obtain
only a recordcount of the same table used in both separate functions. Instead
of writing the query out again, how can I utilise the function already written?
My question is, how can I invoke and use the results of a query in one
cffunction for another cffunction in the same CFC component?
An example may look like the code attached...
Many thanks for your patience and help!
Mikey.
<cffunction name="getItems" access="remote" returntype="query" hint="Gets All
Website Items That Aren't Deleted">
<cfargument name="item_id" type="numeric" required="yes" default="0" />
<cfquery name="items" datasource="#request.dsn#"
username="#request.username#" password="#request.password#">
SELECT *
FROM #request.tbl_items#
WHERE item_parent_id = <cfqueryparam value="#arguments.item_id#"
cfsqltype="cf_sql_integer" />
AND item_deleted = 'No'
ORDER BY item_order ASC
</cfquery>
<cfreturn items />
</cffunction>
<cffunction name="update" access="remote" returntype="query" hint="My Query
using the function above">
<cfargument name="item_id" type="numeric" required="yes" default="0" />
<cfquery name="items" datasource="#request.dsn#"
username="#request.username#" password="#request.password#">
UPDATE item_id
SET item_number
WHERE some_other_column = ####### THE INVOKED RECORDCOUNT OF getItems WOULD
BE HERE #######
</cfquery>
<cfreturn items />
</cffunction>
** The update query is not a real one so things are a bit wrong but I hope you
get the idea of using results from one query in another **