Hi Abhinav,

I was able to build and run your sort code, and it seemed to be behaving
as you expected it to, but the test case still seemed to be generating
the wrong code, such that the "when" clause was accessing the value of
the ID column instead of accessing the value of the STATUS column.)

I feel like part of the problem is that the method

        DataDictionaryImpl.getTriggerActionString()

is trying to do two different things:

1) It is computing the set of columns that are referenced by the parse node

2) And it is using that set of columns to generate the trigger action SQL

I think that the source of the bug is that we FIRST need to do task (1)
for both the trigger action node and the trigger when node, and THEN
do task (2) for both the trigger action node and the trigger when node.

But since the two tasks are bundled into a single routine, we end up
doing them in this order:

(1) (for the action node)
(2) (for the action node)
(1) (for the WHEN clause)
(2) (for the WHEN clause)

Instead of doing them in this order:

(1) (for the action node)
(1) (for the WHEN clause)
(2) (for the action node)
(2) (for the WHEN clause)

I think that if we re-factored getTriggerActionString() into
two different routines, for these two different tasks, then
we could have CreateTriggerNode call the code in the order (1,1,2,2)
instead of the order (1,2,1,2), and then that might fix the problem.

So in CreateTriggerNode, instead of code that looks like:

    transformedActionText =
        getDataDictionary().getTriggerActionString(actionNode, ...);

    // If there is a WHEN clause, we need to transform its text too.
    if (whenClause != null)
        transformedWhenText =
             getDataDictionary().getTriggerActionString(whenClause, ...);

We'd have code more like:

    getDataDictionary().examineTriggerNodeAndCols(actionNode,...);
    if (whenClause != null)
        getDataDictionary().examineTriggerNodeAndCols(whenClause,...);

    transformedActionText =
        getDataDictionary().getTriggerActionString(actionNode, ...);

    // If there is a WHEN clause, we need to transform its text too.
    if (whenClause != null)
        transformedWhenText =
             getDataDictionary().getTriggerActionString(whenClause, ...);

What do you think? Is this idea worth trying?

thanks,

bryan

Reply via email to