Skip to main content
Known Participant
April 2, 2008
Question

<CFFUNCTION> ans <CFRETURN>

  • April 2, 2008
  • 3 replies
  • 560 views
Within my cfloop I have cfswitch cfcase statement and within each cfcase I need to do some SQL insert and update. Instead of writing cfquery within every cfcase I'm thinking of writing a function call, passing 2 parameters needed for the insert and update done inside my function.

I don't know how to call a function that does not a return a value and in CFFUNCTION I need to have CFRETURN but I don't need to return any value.Is there anyway to do this?

<CFLOOP query name="My Query" datasource="myDSN">

<CFSWITCH expression="#LCode#">
<CFCASE value="A">
Instead of writing cfqueries for insert and update for each CFCASE, I'm thinking of
writing a function call. I don't need a return value from the CFFunction
<cfoutput>myFunction( parameter1, parameter2)</cfoutput>
</CFCASE>
<CFCASE value="B">
<cfoutput>myFunction( parameter1, parameter2)</cfoutput>
</CFCASE>
<CFCASE value="C">
<cfoutput>myFunction( parameter1, parameter2)</cfoutput>
</CFCASE>
<CFCASE value="D">
<cfoutput>myFunction( parameter1, parameter2)</cfoutput>
</CFCASE>
<CFCASE value="E">
<cfoutput>myFunction( parameter1, parameter2)</cfoutput>
</CFCASE>
</CFSWITCH>

</CFLOOP>

<CFFUNCTION name="myFunction>
<cfargument name="param1" type="numeric" required="true">
<cfargument name="param2" type="string" required="true">

<!--- cfquery for my sql statemtent in here --->
<cfquery name="NeedInsert" datasource="MyDB>
Insert Into myTable (column1,2,3)
Values (#Value1#, #Value2#, #Value3#
</cfquery>

<cfquery name="NeedUpdate" datasource="MyDB>
Update myOtherTable SET Columni=#Value1#
</cfquery>

</CFFUNCTION>














This topic has been closed for replies.

3 replies

Inspiring
April 2, 2008
> I don't know how to call a function that does not a return a value

<cfset f()>

> and in
> CFFUNCTION I need to have CFRETURN

No you don't.

> but I don't need to return any value.Is
> there anyway to do this?

Set the returntype to VOID, and either just <cfreturn>, or omit the tag
completely.

Although I'm like Dan: I *very rarely* write a function that doesn't at
least return a boolean true. I'm not sure why... it's probably a hangover
from CS-101 (ie: I was usually hungover for that class, so don't remember
the reason ;-)

--
Adam
Inspiring
April 3, 2008
quote:

Originally posted by: Newsgroup User
Although I'm like Dan: I *very rarely* write a function that doesn't at
least return a boolean true. I'm not sure why... it's probably a hangover
from CS-101 (ie: I was usually hungover for that class, so don't remember
the reason ;-)

--
Adam


The return variable is what made it a function, as opposed to a subroutine.
Inspiring
April 2, 2008
quote:

Originally posted by: alecken
Within my cfloop I have cfswitch cfcase statement and within each cfcase I need to do some SQL insert and update. Instead of writing cfquery within every cfcase I'm thinking of writing a function call, passing 2 parameters needed for the insert and update done inside my function.

I don't know how to call a function that does not a return a value and in CFFUNCTION I need to have CFRETURN but I don't need to return any value.Is there anyway to do this?


My personal preference is to have all functions return something. In your case, I would return true.















Inspiring
April 2, 2008
alecken wrote:
>
> <CFFUNCTION name="myFunction>
> <cfargument name="param1" type="numeric" required="true">
> <cfargument name="param2" type="string" required="true">
>
> <!--- cfquery for my sql statemtent in here --->
> <cfquery name="NeedInsert" datasource="MyDB>
> Insert Into myTable (column1,2,3)
> Values (#Value1#, #Value2#, #Value3#
> </cfquery>
>
> <cfquery name="NeedUpdate" datasource="MyDB>
> Update myOtherTable SET Columni=#Value1#
> </cfquery>
>
> </CFFUNCTION>
>

Looks pretty good, except there is no relationship between the
arguments, param1 and param2 and the variables used in the SQL
statements, Value1, Value2 and Value 3. I suspect you cut and pasted
the SQL and did not modify as required to used the passed in parameters.