Hey Guys, 

I'm working on some udf's for a cfc.   These functions will either be 
successful, or throw an error.

The way I'm writing them now, there is an explicit error value, as well as 
an explicit success value. 

Each function starts with both being equal to 0. If during the function's 
flow something breaks, the error value will be set to a string describing 
the error. Also, if during the flow, the function is deemed successful 
(error still eq 0 and the work is done with good result) the 'success' 
value will be set to 1. 

I'm wondering though, if the 'success' value is really necessary as through 
every step of the function I check for errors or unsuccesful 
queries/functions and will flag the error variable if anything is caught.  

If the function works, I can safely say that the error variable will remain 
set to '0', so why not just look for 'error eq 0' to determine if the 
function was successful?

Here's an example of a function I've written. 

[code] <cffunction name="checkExistsAPIKey" returntype="struct" output="no" 
access="remote" returnformat="json">
 
  <cfargument name="userID" type="string" required="true" default="" 
hint="user email" />
 <cfset checkExistsAPIKeyResults=StructNew()>
<cfset checkExistsAPIKeyResults.error = 0>
<cfset checkExistsAPIKeyResults.success = 0>
 <cfif not isNumeric(arguments.userID)>
<cfset checkExistsAPIKEYResults.error = 1>
</cfif>
 <cfif checkExistsAPIKEYResults.error eq 0>
 <cfset var local = StructNew()>
<cfset local.userID = "#arguments.userID#">
 <cfquery name="checkExistsAPIKey" datasource="dbAPI" maxRows="1" >
 SELECT keyID
FROM tbl_apiKey
WHERE userID = <cfqueryparam value="#local.userID#">
 </cfquery>
 <cfif checkExistsAPIKey.recordcount eq 0>
<cfset checkExistsAPIKEYResults.error = 1>
<cfelse>
<cfset checkExistsAPIKEYResults.success = 1>
</cfif>
 </cfif>
 <cfreturn checkExistsAPIKEYResults> 
 </cffunction>[/code]

In this function, I think error=0 would return the same result as 
success=1, as for the function to be successful, it must not catch any 
errors. I have at the end of each function a check to make sure the 
function is getting what it's supposed to, and if not, it's flagged as 
error. So if error=0, I know it was successful. 

Or... should I use 'success' and if there is an error, set 'success eq 0'

Thoughts?

-- 
online documentation: http://openbd.org/manual/
 http://groups.google.com/group/openbd?hl=en

Reply via email to