CUD Problem

View: New views
2 Messages — Rating Filter:   Alert me  

CUD Problem

by AppleII717 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I implement a cud process similar to what is in the documentation  
describing cud using a local method as the processor and think I found  
a minor problem or I don't understand something.

My incomplete local method with some debugging:

method "cudAssessment"($cudAction; $cudPhase; $cudTable; $cudResult;  
$params; $cudTimestampField; $cudTimestamp)
        writebr('$cudAction $cudPhase $cudResult')
        case of
                :($cudPhase = "query")
                        query([assessments]; [assessments]id = num($params{"assessment.id"}))
                :($cudPhase = "update")
                        buildFromParams("assessments";$params)
                :($cudPhase = "delete")
                        // delete questions and answers
        end case
        return ("success")
end method

What I noticed is that my record was not being updated, (action =  
update) but it was returning "success". I put the writebr in and saw  
that it only did the query phase and the cleanup phase. That pointed  
out that I had an error in my query as it reported missing out of  
query. It then it fell through to the cleanup phase, which was  
successful and the overall result was success.

Looking at the code for cud, that is exactly what will happen if your  
processor does not respond to the cleanup phase.

" If you are not using transactions, most of the time you will ignore  
this phase."

That leads me to believe that:

1 - You can't ignore the cleanup phase since any error would be  
overwritten in the cleanup phase if not handled.
2 - If the status is not success before calling the cleanup phase, it  
should report that result.

Steve Alex
_______________________________________________
Active4D-dev mailing list
Active4D-dev@...
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Re: CUD Problem

by aparajita :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Steve,

> method "cudAssessment"($cudAction; $cudPhase; $cudTable; $cudResult;  
> $params; $cudTimestampField; $cudTimestamp)
> writebr('$cudAction $cudPhase $cudResult')
> case of
> :($cudPhase = "query")
> query([assessments]; [assessments]id =  
> num($params{"assessment.id"}))
> :($cudPhase = "update")
> buildFromParams("assessments";$params)
> :($cudPhase = "delete")
> // delete questions and answers
> end case
> return ("success")
> end method
>
> What I noticed is that my record was not being updated, (action =  
> update) but it was returning "success". I put the writebr in and saw  
> that it only did the query phase and the cleanup phase. That pointed  
> out that I had an error in my query as it reported missing out of  
> query. It then it fell through to the cleanup phase, which was  
> successful and the overall result was success.

> That leads me to believe that:
>
> 1 - You can't ignore the cleanup phase since any error would be  
> overwritten in the cleanup phase if not handled.
> 2 - If the status is not success before calling the cleanup phase,  
> it should report that result.

Good point. Conceptually cleanup is not an action that has a result,  
so in fact the status returned by cleanup should just be ignored.  
Change the end of a4d.utils.cud to this:

$cudPhase := "cleanup"
$cudResult_ := $cudResult

if ($cudInclude)
     include($cudProcessor)
else
     call method($cudProcessor; $cudAction; $cudPhase; $cudTable;  
$cudResult; $attributes; $cudTimestampField; $cudTimestamp)
end if
       
return ($cudResult_)


Kind regards,

    Aparajita
    www.aparajitaworld.com

    "If you dare to fail, you are bound to succeed."
    - Sri Chinmoy   |   www.srichinmoy.org

_______________________________________________
Active4D-dev mailing list
Active4D-dev@...
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/