No matter what my functions are doing, they almost all universally
return a structure.
That way, each element in the struct can be different types. I
frequently reserve one for a 1 or 0 "success" value, another one will
return the arguments scope (what was submitted to the function in the
first place - good for debugging), and then one or more for each of the
database query result sets that the function pulled.
Alan Holden
(at work)
On 3/15/2012 2:30 PM, Jeff Lucido wrote:
Unfortunately no. As Matt mentioned previously it can only be one
value (again, array, struct, single query, etc.). Without knowing your
SQL structure (assuming you are using a RDBMS) could you not use joins
to pull this information together into one query result from your
database? If not, you can use the handy query of query function in
CFML to combine these query resultsets into one.
http://www.openbd.org/manual/?/tag/CFQUERY
Good luck,
-JSLucido
On Thu, Mar 15, 2012 at 4:09 PM, Jason King<[email protected]> wrote:
Thanks. On the cfreturn.. What if there are multiple queries? lets say the
queries are
photoInfo
folderInfo
photoDetailInfo
Would I do this?
<cfreturn photoInfo folderInfo photoDetailInfo />
On Thu, Mar 15, 2012 at 4:06 PM, Matthew Woodward<[email protected]>
wrote:
On Thu, Mar 15, 2012 at 1:59 PM, Jason King<[email protected]>
wrote:
Probably not the smartest question, but just want to be sure.
No such thing as a dumb question!
Do I need to declare a variable for each value I expect to be returned? I
only need a single argument (photo id), but I might have 15 variables
returned (photo url, filename, created date, caption, etc). Is this what
gets put in the<cfreturn> block?
Well you can only return one value from a function with CFRETURN (i.e.
there is no CFRETURN *block*, it's just<cfreturn myVar /> and that's it),
so you need to bundle that stuff up in a data container of some sort, be
that an array, struct, query object, whatever.
For instance, the query would generate a variable of queryName.photo_url.
Do I need to set a value of 'getPhoto.photo_url' = queryName.photo_url so
that when I want to actually use that value I don't have to use the variable
name that the query generated? Does this make sense?
You can return the entire query object if you want. Just be aware for
thread safety that you need to var scope any variables generated within the
function, or turn on auto-var scoping in OpenBD.
I don't have any idea about your data, etc. so this may not be exactly
right but here's the gist of it:
<cffunction name="getPhoto" access="public" output="false"
returntype="query">
<cfargument name="photoID" type="numeric" required="true" />
<cfset var photoInfo = 0 />
<cfquery name="photoInfo" datasource="whatever">
SELECT * FROM photo WHERE id =<cfqueryparam
value="#arguments.photoID#" cfsqltype="cf_sql_integer" />
</cfquery>
<cfreturn photoInfo />
</cffunction>
If you want to return a different datatype change the returntype in the
opening function tag and obviously get your query data and put that into
whatever data structure you want to return.
--
Matthew Woodward
[email protected]
http://blog.mattwoodward.com
identi.ca / Twitter: @mpwoodward
Please do not send me proprietary file formats such as Word, PowerPoint,
etc. as attachments.
http://www.gnu.org/philosophy/no-word-attachments.html
--
online documentation: http://openbd.org/manual/
google+ hints/tips: https://plus.google.com/115990347459711259462
http://groups.google.com/group/openbd?hl=en
--
online documentation: http://openbd.org/manual/
google+ hints/tips: https://plus.google.com/115990347459711259462
http://groups.google.com/group/openbd?hl=en
--
online documentation: http://openbd.org/manual/
google+ hints/tips: https://plus.google.com/115990347459711259462
http://groups.google.com/group/openbd?hl=en