Skip to main content
Inspiring
April 18, 2008
Question

Another CFC question

  • April 18, 2008
  • 8 replies
  • 484 views
Ok, so I'm still working on getting this CFC thing down... :)

Azadi gave me some good pointers, and I've tried to follow them. Now I want
to see if I can add something. I have:

<cfcomponent displayname="duplicate" hint="Duplicates local club
tournaments">
<!--- This function retrieves all customers from the database --->
<cffunction name="getinfo"
hint="Gets all tournament info from the database" returntype="boolean"
output="no">
<cfargument name="tid" required="yes" type="numeric">
<cfset var DuplicateTournamentList = "">
<cfset var result = true>
<!--- Sends TournID to have the new tournament date calculated --->
<cfinvoke component="components.dateCalc" method="calcDate"
returnvariable="nDate">
<cfinvokeargument name="id" value="#arguments.tid#">
</cfinvoke>

<cftry>
<cfquery name="DuplicateTournamentList" datasource="SalleBoise">
INSERT INTO clubtournaments( TournName, TournDesc, TournFoilEvent,
TournEpeeEvent, EventType, TournDateTime, TournDuplicated )
SELECT TournName, TournDesc, TournFoilEvent, TournEpeeEvent, EventType,
DATE_ADD( TournDateTime, INTERVAL 2
MONTH ) AS TournDateTime, 0 AS TournDuplicated
FROM clubtournaments
WHERE TournID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#arguments.tid#">
</cfquery>

Which does a good job of duplicating the event, but the problem is I need to
have the new event on the 1st Saturday, 2 months from the original event.

I worked out, with the help of another CF person, something along the lines
of:

<cfcomponent displayname="DOM" hint="Sets new date for new tournament">
<cffunction name="calcDate" access="public" returntype="string"
hint="Returns 1st Saturday of Month">
<cfargument name="id" type="date" required="yes">

<cfquery name="GetTournDate" datasource="SalleBoise">
select TournDateTime
from clubtournaments
where TournID=<cfqueryparam cfsqltype="cf_sql_integer"
value="#arguments.id#">
</cfquery>


<cfset var testDay =
dateformat(GetTournDate.TournDateTime,"mm/dd/yyyy")>
<cfset var left_testDay=left(testDay,2)>
<cfset var right_testDay=right(testDay,4)>
<cfset var combo_testDay="#left_testDay#" & "/" & "01" & "/" &
"#right_testDay#">
<cfset var NewtestDay=dateadd("m",2,combo_testDay)>

<cfloop condition="dayOfWeek(NewtestDay) NEQ 7">
<cfset NewtestDay = dateAdd("d",NewtestDay,1)>
</cfloop>

<cfset var newDate=NewtestDay>
<cfreturn newDate>
</cffunction>
</cfcomponent>

Now, I have 3 questions:
1) Can I call invoke a CFC from within a CFC such as <cfinvoke
component="components.dateCalc" method="calcDate" returnvariable="nDate">
<cfinvokeargument name="id" value="#arguments.tid#">
</cfinvoke>

2) How can I determine if the 2nd CFC is processing data?
3) With the inputting of data in the 1st CFC, how can I get the newly
calculated data to be input rather than the DATE_ADD( TournDateTime,
INTERVAL 2
MONTH ) AS TournDateTime

Thanks!!

    This topic has been closed for replies.

    8 replies

    Inspiring
    April 23, 2008
    Here ya go:

    <cfcomponent displayname="duplicate" hint="Duplicates local club
    tournaments">
    <!--- This function retrieves all customers from the database --->
    <cffunction name="getinfo"
    hint="Gets all tournament info from the database" returntype="boolean"
    output="no">
    <cfargument name="tid" required="yes" type="numeric">
    <cfset var DuplicateTournamentList = "">
    <cfset var result = true>
    <cfset var NewTournDate = calcDate(arguments.tid)>
    <cftry>
    <cfquery name="DuplicateTournamentList" datasource="SalleBoise">
    INSERT INTO clubtournaments( TournName, TournDesc, TournFoilEvent,
    TournEpeeEvent, EventType, TournDateTime, TournDuplicated )
    SELECT TournName, TournDesc, TournFoilEvent, TournEpeeEvent, EventType,
    <cfqueryparam cfsqltype="cf_sql_date" value="#NewTournDate#"> AS
    TournDateTime, 0 AS TournDuplicated
    FROM clubtournaments
    WHERE TournID = <cfqueryparam cfsqltype="cf_sql_integer"
    value="#arguments.tid#">
    </cfquery>
    <cfcatch type="any">
    <cfset result = false>
    </cfcatch>
    </cftry>
    <cfreturn result />
    </cffunction>

    <cffunction name="calcDate" access="public" returntype="date" hint="Returns
    1st Saturday of Month">
    <cfargument name="id" type="numeric" required="yes">
    <cfset var GetTournDate = "">
    <cfset var tourndate = "">
    <cfset var FirstOfMonth2MonthsAhead = "">
    <cfset NewTournDate = "">
    <cfquery name="GetTournDate" datasource="SalleBoise">
    select TournDateTime
    from clubtournaments
    where TournID=<cfqueryparam cfsqltype="cf_sql_integer"
    value="#arguments.id#">
    </cfquery>
    <cfset tourndate = GetTournDate.TournDateTime>
    <cfset FirstOfMonth2MonthsAhead = createdatetime(year(dateadd('m', 2,
    tourndate)), month(dateadd('m', 2, tourndate)), day(tourndate),
    hour(tourndate),
    minute(tourndate), second(tourndate))>
    <cfset NewTournDate = dateadd('d',
    7-dayofweek(FirstOfMonth2MonthsAhead), FirstOfMonth2MonthsAhead)>
    <cfreturn NewTournDate />
    </cffunction>
    </cfcomponent>



    "Azadi" <azadi@sabai-dee.com> wrote in message
    news:funinl$fil$1@forums.macromedia.com...
    > Steve Grosz wrote:
    >> Does the return type date only handle the 'date' and not the date &
    >> time????
    >>
    >
    > no, as BKBK already mentioned in another thread.
    > i am stumped a bit by this.
    > can you please post your current cfc code? i suspect there may be a typo
    > or some other error in there somewhere, because the code worked fine in
    > my tests...
    >
    >
    >
    > Azadi Saryev
    > Sabai-dee.com
    > http://www.sabai-dee.com/
    >

    Inspiring
    April 23, 2008
    Steve Grosz wrote:
    > Does the return type date only handle the 'date' and not the date &
    > time????
    >

    no, as BKBK already mentioned in another thread.
    i am stumped a bit by this.
    can you please post your current cfc code? i suspect there may be a typo
    or some other error in there somewhere, because the code worked fine in
    my tests...



    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Inspiring
    April 23, 2008
    Does the return type date only handle the 'date' and not the date & time????

    "Azadi" <azadi@sabai-dee.com> wrote in message
    news:fukaev$qem$1@forums.macromedia.com...
    > Hi Steve,
    >
    > 1)
    > <cfcomponent displayname="DOM" hint="Sets new date for new tournament">
    > <cffunction name="calcDate" access="public" returntype="string"
    > hint="Returns 1st Saturday of Month">
    > <cfargument name="id" type="date" required="yes">
    > <cfquery name="GetTournDate" datasource="SalleBoise">
    > select TournDateTime
    > from clubtournaments
    > where TournID=<cfqueryparam cfsqltype="cf_sql_integer"
    > value="#arguments.id#">
    > </cfquery>
    > ...
    >
    > this function, calcDate, seems to accept a DATE as argument, but then
    > you are using that argument as INTEGER in your query. that will surely
    > throw errors at you.
    >
    > furthermore, you probably want to set RETURNTYPE of calcDate function to
    > DATE instead of STRING if you need a date... make sure it actually
    > returns a date then, though...
    >
    > the whole setting of new tournament date code seems very clumsy with all
    > those loops... this is a lot nicer (complete function code):
    >
    > <cffunction name="calcDate" access="public" returntype="date"
    > hint="Returns 1st Saturday of Month">
    > <cfargument name="id" type="numeric" required="yes">
    > <cfset var GetTournDate = "">
    > <cfset var tourndate = "">
    > <cfset var FirstOfMonth2MonthsAhead = "">
    > <cfset NewTournDate = "">
    > <cfquery name="GetTournDate" datasource="SalleBoise">
    > select TournDateTime
    > from clubtournaments
    > where TournID=<cfqueryparam cfsqltype="cf_sql_integer"
    > value="#arguments.id#">
    > </cfquery>
    > <cfset tourndate = GetTournDate.TournDateTime>
    > <cfset FirstOfMonth2MonthsAhead = createdatetime(year(dateadd('m', 2,
    > tourndate)), month(dateadd('m', 2, tourndate)), 01, hour(tourndate),
    > minute(tourndate), second(tourndate))>
    > <cfset NewTournDate = dateadd('d',
    > 7-dayofweek(FirstOfMonth2MonthsAhead), FirstOfMonth2MonthsAhead)>
    > <cfreturn NewTournDate />
    > </cffunction>
    >
    >
    > 2) if you put this calcDate function in same cfc where your 'getinfo'
    > function is, then you can call it without cfinvoke (see code below).
    >
    > assuming the calcDate function is in same cfc as getinfo function,
    > accepts a NUMERIC argument and returns a DATE (as code above):
    >
    > <cffunction name="getinfo"
    > hint="Gets all tournament info from the database" returntype="boolean"
    > output="no">
    > <cfargument name="tid" required="yes" type="numeric">
    > <cfset var DuplicateTournamentList = "">
    > <cfset var result = true>
    > <cfset var NewTournDate = calcDate(arguments.tid)>
    > <cftry>
    > <cfquery name="DuplicateTournamentList" datasource="SalleBoise">
    > INSERT INTO clubtournaments( TournName, TournDesc, TournFoilEvent,
    > TournEpeeEvent, EventType, TournDateTime, TournDuplicated )
    > SELECT TournName, TournDesc, TournFoilEvent, TournEpeeEvent, EventType,
    > <cfqueryparam cfsqltype="cf_sql_date" value="#NewTournDate#"> AS
    > TournDateTime, 0 AS TournDuplicated
    > FROM clubtournaments
    > WHERE TournID = <cfqueryparam cfsqltype="cf_sql_integer"
    > value="#arguments.tid#">
    > </cfquery>
    >
    >
    > 3) extra tip: if you need the ID of the duplicated tournament, set a
    > RESULT attribute in the DuplicateTournamentList query, set the
    > returntype of 'getinfo' function to numeric, and return
    > resultname.GENERATED_KEY (for mysql db - check cf docs for correct
    > variable to return for other db types) where RESULTNAME is the value of
    > the RESULT attribute of the query.
    >
    > hth
    >
    > Azadi Saryev
    > Sabai-dee.com
    > http://www.sabai-dee.com/
    >

    Inspiring
    April 23, 2008
    Nevermind, figured out that problem...... but for one reason or another, the
    new datetime isn't showing the time portion when its added to the
    database....

    "Steve Grosz" <boise_bound@hotmail.com> wrote in message
    news:fuldn5$4d7$1@forums.macromedia.com...
    > Why would it be modifying the date of the original item to today's date
    > and time??
    >
    > "Azadi" <azadi@sabai-dee.com> wrote in message
    > news:fukaev$qem$1@forums.macromedia.com...
    >> Hi Steve,
    >>
    >> 1)
    >> <cfcomponent displayname="DOM" hint="Sets new date for new tournament">
    >> <cffunction name="calcDate" access="public" returntype="string"
    >> hint="Returns 1st Saturday of Month">
    >> <cfargument name="id" type="date" required="yes">
    >> <cfquery name="GetTournDate" datasource="SalleBoise">
    >> select TournDateTime
    >> from clubtournaments
    >> where TournID=<cfqueryparam cfsqltype="cf_sql_integer"
    >> value="#arguments.id#">
    >> </cfquery>
    >> ...
    >>
    >> this function, calcDate, seems to accept a DATE as argument, but then
    >> you are using that argument as INTEGER in your query. that will surely
    >> throw errors at you.
    >>
    >> furthermore, you probably want to set RETURNTYPE of calcDate function to
    >> DATE instead of STRING if you need a date... make sure it actually
    >> returns a date then, though...
    >>
    >> the whole setting of new tournament date code seems very clumsy with all
    >> those loops... this is a lot nicer (complete function code):
    >>
    >> <cffunction name="calcDate" access="public" returntype="date"
    >> hint="Returns 1st Saturday of Month">
    >> <cfargument name="id" type="numeric" required="yes">
    >> <cfset var GetTournDate = "">
    >> <cfset var tourndate = "">
    >> <cfset var FirstOfMonth2MonthsAhead = "">
    >> <cfset NewTournDate = "">
    >> <cfquery name="GetTournDate" datasource="SalleBoise">
    >> select TournDateTime
    >> from clubtournaments
    >> where TournID=<cfqueryparam cfsqltype="cf_sql_integer"
    >> value="#arguments.id#">
    >> </cfquery>
    >> <cfset tourndate = GetTournDate.TournDateTime>
    >> <cfset FirstOfMonth2MonthsAhead = createdatetime(year(dateadd('m', 2,
    >> tourndate)), month(dateadd('m', 2, tourndate)), 01, hour(tourndate),
    >> minute(tourndate), second(tourndate))>
    >> <cfset NewTournDate = dateadd('d',
    >> 7-dayofweek(FirstOfMonth2MonthsAhead), FirstOfMonth2MonthsAhead)>
    >> <cfreturn NewTournDate />
    >> </cffunction>
    >>
    >>
    >> 2) if you put this calcDate function in same cfc where your 'getinfo'
    >> function is, then you can call it without cfinvoke (see code below).
    >>
    >> assuming the calcDate function is in same cfc as getinfo function,
    >> accepts a NUMERIC argument and returns a DATE (as code above):
    >>
    >> <cffunction name="getinfo"
    >> hint="Gets all tournament info from the database" returntype="boolean"
    >> output="no">
    >> <cfargument name="tid" required="yes" type="numeric">
    >> <cfset var DuplicateTournamentList = "">
    >> <cfset var result = true>
    >> <cfset var NewTournDate = calcDate(arguments.tid)>
    >> <cftry>
    >> <cfquery name="DuplicateTournamentList" datasource="SalleBoise">
    >> INSERT INTO clubtournaments( TournName, TournDesc, TournFoilEvent,
    >> TournEpeeEvent, EventType, TournDateTime, TournDuplicated )
    >> SELECT TournName, TournDesc, TournFoilEvent, TournEpeeEvent, EventType,
    >> <cfqueryparam cfsqltype="cf_sql_date" value="#NewTournDate#"> AS
    >> TournDateTime, 0 AS TournDuplicated
    >> FROM clubtournaments
    >> WHERE TournID = <cfqueryparam cfsqltype="cf_sql_integer"
    >> value="#arguments.tid#">
    >> </cfquery>
    >>
    >>
    >> 3) extra tip: if you need the ID of the duplicated tournament, set a
    >> RESULT attribute in the DuplicateTournamentList query, set the
    >> returntype of 'getinfo' function to numeric, and return
    >> resultname.GENERATED_KEY (for mysql db - check cf docs for correct
    >> variable to return for other db types) where RESULTNAME is the value of
    >> the RESULT attribute of the query.
    >>
    >> hth
    >>
    >> Azadi Saryev
    >> Sabai-dee.com
    >> http://www.sabai-dee.com/
    >
    >
    >

    Inspiring
    April 22, 2008
    Why would it be modifying the date of the original item to today's date and
    time??

    "Azadi" <azadi@sabai-dee.com> wrote in message
    news:fukaev$qem$1@forums.macromedia.com...
    > Hi Steve,
    >
    > 1)
    > <cfcomponent displayname="DOM" hint="Sets new date for new tournament">
    > <cffunction name="calcDate" access="public" returntype="string"
    > hint="Returns 1st Saturday of Month">
    > <cfargument name="id" type="date" required="yes">
    > <cfquery name="GetTournDate" datasource="SalleBoise">
    > select TournDateTime
    > from clubtournaments
    > where TournID=<cfqueryparam cfsqltype="cf_sql_integer"
    > value="#arguments.id#">
    > </cfquery>
    > ...
    >
    > this function, calcDate, seems to accept a DATE as argument, but then
    > you are using that argument as INTEGER in your query. that will surely
    > throw errors at you.
    >
    > furthermore, you probably want to set RETURNTYPE of calcDate function to
    > DATE instead of STRING if you need a date... make sure it actually
    > returns a date then, though...
    >
    > the whole setting of new tournament date code seems very clumsy with all
    > those loops... this is a lot nicer (complete function code):
    >
    > <cffunction name="calcDate" access="public" returntype="date"
    > hint="Returns 1st Saturday of Month">
    > <cfargument name="id" type="numeric" required="yes">
    > <cfset var GetTournDate = "">
    > <cfset var tourndate = "">
    > <cfset var FirstOfMonth2MonthsAhead = "">
    > <cfset NewTournDate = "">
    > <cfquery name="GetTournDate" datasource="SalleBoise">
    > select TournDateTime
    > from clubtournaments
    > where TournID=<cfqueryparam cfsqltype="cf_sql_integer"
    > value="#arguments.id#">
    > </cfquery>
    > <cfset tourndate = GetTournDate.TournDateTime>
    > <cfset FirstOfMonth2MonthsAhead = createdatetime(year(dateadd('m', 2,
    > tourndate)), month(dateadd('m', 2, tourndate)), 01, hour(tourndate),
    > minute(tourndate), second(tourndate))>
    > <cfset NewTournDate = dateadd('d',
    > 7-dayofweek(FirstOfMonth2MonthsAhead), FirstOfMonth2MonthsAhead)>
    > <cfreturn NewTournDate />
    > </cffunction>
    >
    >
    > 2) if you put this calcDate function in same cfc where your 'getinfo'
    > function is, then you can call it without cfinvoke (see code below).
    >
    > assuming the calcDate function is in same cfc as getinfo function,
    > accepts a NUMERIC argument and returns a DATE (as code above):
    >
    > <cffunction name="getinfo"
    > hint="Gets all tournament info from the database" returntype="boolean"
    > output="no">
    > <cfargument name="tid" required="yes" type="numeric">
    > <cfset var DuplicateTournamentList = "">
    > <cfset var result = true>
    > <cfset var NewTournDate = calcDate(arguments.tid)>
    > <cftry>
    > <cfquery name="DuplicateTournamentList" datasource="SalleBoise">
    > INSERT INTO clubtournaments( TournName, TournDesc, TournFoilEvent,
    > TournEpeeEvent, EventType, TournDateTime, TournDuplicated )
    > SELECT TournName, TournDesc, TournFoilEvent, TournEpeeEvent, EventType,
    > <cfqueryparam cfsqltype="cf_sql_date" value="#NewTournDate#"> AS
    > TournDateTime, 0 AS TournDuplicated
    > FROM clubtournaments
    > WHERE TournID = <cfqueryparam cfsqltype="cf_sql_integer"
    > value="#arguments.tid#">
    > </cfquery>
    >
    >
    > 3) extra tip: if you need the ID of the duplicated tournament, set a
    > RESULT attribute in the DuplicateTournamentList query, set the
    > returntype of 'getinfo' function to numeric, and return
    > resultname.GENERATED_KEY (for mysql db - check cf docs for correct
    > variable to return for other db types) where RESULTNAME is the value of
    > the RESULT attribute of the query.
    >
    > hth
    >
    > Azadi Saryev
    > Sabai-dee.com
    > http://www.sabai-dee.com/


    Inspiring
    April 22, 2008
    Hi Steve,

    1)
    <cfcomponent displayname="DOM" hint="Sets new date for new tournament">
    <cffunction name="calcDate" access="public" returntype="string"
    hint="Returns 1st Saturday of Month">
    <cfargument name="id" type="date" required="yes">
    <cfquery name="GetTournDate" datasource="SalleBoise">
    select TournDateTime
    from clubtournaments
    where TournID=<cfqueryparam cfsqltype="cf_sql_integer"
    value="#arguments.id#">
    </cfquery>
    ...

    this function, calcDate, seems to accept a DATE as argument, but then
    you are using that argument as INTEGER in your query. that will surely
    throw errors at you.

    furthermore, you probably want to set RETURNTYPE of calcDate function to
    DATE instead of STRING if you need a date... make sure it actually
    returns a date then, though...

    the whole setting of new tournament date code seems very clumsy with all
    those loops... this is a lot nicer (complete function code):

    <cffunction name="calcDate" access="public" returntype="date"
    hint="Returns 1st Saturday of Month">
    <cfargument name="id" type="numeric" required="yes">
    <cfset var GetTournDate = "">
    <cfset var tourndate = "">
    <cfset var FirstOfMonth2MonthsAhead = "">
    <cfset NewTournDate = "">
    <cfquery name="GetTournDate" datasource="SalleBoise">
    select TournDateTime
    from clubtournaments
    where TournID=<cfqueryparam cfsqltype="cf_sql_integer"
    value="#arguments.id#">
    </cfquery>
    <cfset tourndate = GetTournDate.TournDateTime>
    <cfset FirstOfMonth2MonthsAhead = createdatetime(year(dateadd('m', 2,
    tourndate)), month(dateadd('m', 2, tourndate)), 01, hour(tourndate),
    minute(tourndate), second(tourndate))>
    <cfset NewTournDate = dateadd('d',
    7-dayofweek(FirstOfMonth2MonthsAhead), FirstOfMonth2MonthsAhead)>
    <cfreturn NewTournDate />
    </cffunction>


    2) if you put this calcDate function in same cfc where your 'getinfo'
    function is, then you can call it without cfinvoke (see code below).

    assuming the calcDate function is in same cfc as getinfo function,
    accepts a NUMERIC argument and returns a DATE (as code above):

    <cffunction name="getinfo"
    hint="Gets all tournament info from the database" returntype="boolean"
    output="no">
    <cfargument name="tid" required="yes" type="numeric">
    <cfset var DuplicateTournamentList = "">
    <cfset var result = true>
    <cfset var NewTournDate = calcDate(arguments.tid)>
    <cftry>
    <cfquery name="DuplicateTournamentList" datasource="SalleBoise">
    INSERT INTO clubtournaments( TournName, TournDesc, TournFoilEvent,
    TournEpeeEvent, EventType, TournDateTime, TournDuplicated )
    SELECT TournName, TournDesc, TournFoilEvent, TournEpeeEvent, EventType,
    <cfqueryparam cfsqltype="cf_sql_date" value="#NewTournDate#"> AS
    TournDateTime, 0 AS TournDuplicated
    FROM clubtournaments
    WHERE TournID = <cfqueryparam cfsqltype="cf_sql_integer"
    value="#arguments.tid#">
    </cfquery>


    3) extra tip: if you need the ID of the duplicated tournament, set a
    RESULT attribute in the DuplicateTournamentList query, set the
    returntype of 'getinfo' function to numeric, and return
    resultname.GENERATED_KEY (for mysql db - check cf docs for correct
    variable to return for other db types) where RESULTNAME is the value of
    the RESULT attribute of the query.

    hth

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Inspiring
    April 21, 2008
    Oh, probably just my bad thinking..... ;)

    1 question, if the data is being added to the database by

    <cfquery name="DuplicateTournamentList" datasource="SalleBoise">
    INSERT INTO clubtournaments( TournName, TournDesc, TournFoilEvent,
    TournEpeeEvent, EventType, TournDateTime, TournDuplicated )
    SELECT TournName, TournDesc, TournFoilEvent, TournEpeeEvent, EventType,
    DATE_ADD( TournDateTime, INTERVAL 2
    MONTH ) AS TournDateTime, 0 AS TournDuplicated
    FROM clubtournaments
    WHERE TournID = <cfqueryparam cfsqltype="cf_sql_integer"
    value="#arguments.tid#">
    </cfquery>

    Then how can I override that info from the 'select' statement and use the
    return variable data??

    "Dan Bracuk" <webforumsuser@macromedia.com> wrote in message
    news:fuilth$3gv$1@forums.macromedia.com...
    > The answer to question 1 is yes.
    >
    > The answer to question 3 is to use the return variable from the cfinvoke.
    >
    > If you are successful, you will know the answer to question 2.
    >
    > Now I have a question for you. Why are you converting dates into strings?
    >


    Inspiring
    April 21, 2008
    The answer to question 1 is yes.

    The answer to question 3 is to use the return variable from the cfinvoke.

    If you are successful, you will know the answer to question 2.

    Now I have a question for you. Why are you converting dates into strings?