Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

<CFFUNCTION> ans <CFRETURN>

Community Beginner ,
Apr 02, 2008 Apr 02, 2008
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>














TOPICS
Getting started
509
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2008 Apr 02, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2008 Apr 02, 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.















Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2008 Apr 02, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2008 Apr 02, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 03, 2008 Apr 03, 2008
> The return variable is what made it a function, as opposed to a subroutine.

Anything that runs in a different memory space/scope (for lack of a better
term) is a "subroutine". Two different types of sub-routine are:
- functions (return a value)
- procedures (don't return a value)

CF doesn't specifically implement "procedures"; the closest thing being a
custom tag, I guess.

A function which doesn't return a value is simply that: a function that
doesn't return a value.

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 03, 2008 Apr 03, 2008
LATEST
Thank you so much guys!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources