I am wondering what my filtered method (say getByFilter()) would look
like in my DAO without explicitly specifying the parameters available
to filter by?
LISTING 1
-----------------------------------------------------
<cffunction name="getByAttributes" access="public" output="false"
returntype="query">
<cfargument name="articleid" type="Numeric" required="false" />
<cfargument name="artcategoryid" type="Numeric" required="false" />
<cfargument name="artauthorid" type="Numeric" required="false" />
<cfargument name="title" type="String" required="false" />
<cfargument name="summary" type="String" required="false" />
<cfargument name="content" type="String" required="false" />
<cfargument name="views" type="Numeric" required="false" />
<cfargument name="islive" type="Numeric" required="false" />
<cfargument name="isfeatured" type="Numeric" required="false" />
<cfargument name="orderby" type="string" required="false" />
<cfset var qList = "" />
<cfquery name="qList" datasource="#variables.dsn#">
SELECT
articleid,
artcategoryid,
artauthorid,
title,
summary,
content,
views,
islive,
isfeatured
FROM article
WHERE 0=0
<cfif structKeyExists(arguments,"articleid") and len(arguments.articleid)>
AND articleid = <cfqueryparam value="#arguments.articleid#"
CFSQLType="cf_sql_integer" />
</cfif>
<cfif structKeyExists(arguments,"artcategoryid") and
len(arguments.artcategoryid)>
AND artcategoryid = <cfqueryparam value="#arguments.artcategoryid#"
CFSQLType="cf_sql_integer" />
</cfif>
<cfif structKeyExists(arguments,"artauthorid") and len(arguments.artauthorid)>
AND artauthorid = <cfqueryparam value="#arguments.artauthorid#"
CFSQLType="cf_sql_integer" />
</cfif>
<cfif structKeyExists(arguments,"title") and len(arguments.title)>
AND title = <cfqueryparam value="#arguments.title#"
CFSQLType="cf_sql_varchar" />
</cfif>
<cfif structKeyExists(arguments,"summary") and len(arguments.summary)>
AND summary = <cfqueryparam value="#arguments.summary#"
CFSQLType="cf_sql_longvarchar" />
</cfif>
<cfif structKeyExists(arguments,"content") and len(arguments.content)>
AND content = <cfqueryparam value="#arguments.content#"
CFSQLType="cf_sql_longvarchar" />
</cfif>
<cfif structKeyExists(arguments,"views") and len(arguments.views)>
AND views = <cfqueryparam value="#arguments.views#"
CFSQLType="cf_sql_integer" />
</cfif>
<cfif structKeyExists(arguments,"islive") and len(arguments.islive)>
AND islive = <cfqueryparam value="#arguments.islive#"
CFSQLType="cf_sql_integer" />
</cfif>
<cfif structKeyExists(arguments,"isfeatured") and len(arguments.isfeatured)>
AND isfeatured = <cfqueryparam value="#arguments.isfeatured#"
CFSQLType="cf_sql_integer" />
</cfif>
<cfif structKeyExists(arguments, "orderby") and len(arguments.orderBy)>
ORDER BY #arguments.orderby#
</cfif>
</cfquery>
<cfreturn qList />
</cffunction>