I have a naively implemented but useful helper function I use quite often:
<cffunction name="declarativeQuery" access="public" output="false"
returntype="query">
<cfargument name="cols" type="string" required="true" />
<cfargument name="data" type="array" required="true" />
<cfset var row = null />
<cfset var field = null />
<cfset var result = queryNew(arguments.cols) />
<cfset arguments.cols = listToArray(arguments.cols) />
<cfloop from="1" to="#arrayLen(arguments.data)#" index="row">
<cfset queryAddRow(result) />
<cfloop from="1" to="#arrayLen(arguments.data[row])#" index="field">
<cfset querySetCell(result, arguments.cols[field],
arguments.data[row][field]) />
</cfloop>
</cfloop>
<cfreturn result />
</cffunction>
I find this useful enough that I would like to suggest that the native
queryNew() function actually support this implicitly. I.e. add a
"dataarray" parameter to allow you to pass in an array of the data to load
into the created query. It should obviously do some stuff I am not doing
(error checking, handling datatypes, etc.), but semantically it seems to
make perfect sense that you would often want to do something like the
following when using queryNew():
queryNew(
namelist="id,name,description",
typelist="integer,varchar,varchar", <!--- if you wanted to specify column
types --->
dataarray= [
[1, "example 1", "example description 1"],
[1, "example 2", "example description 2"],
]
)
I have found this to be incredibly useful in certain scenarios and it
appears to me at least that this could be added without breaking backwards
compatibility.
Just a suggestion.
--
online documentation: http://openbd.org/manual/
http://groups.google.com/group/openbd?hl=en