Bugs item #2744564, was opened at 2009-04-08 19:43
Message generated for change (Comment added) made by shcheklein
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=713730&aid=2744564&group_id=129076

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Triggers
>Group: Sedna (current)
Status: Open
>Resolution: Accepted
Priority: 5
Private: No
Submitted By: Konstantin (drideru)
>Assigned to: Ivan Shcheklein (shcheklein)
Summary: INSERT trigger is called upon UPDATE REPLACE

Initial Comment:
The INSERT BEFORE TRIGGER is called when the UPDATE REPLACE is executed. Found 
out because there might be another bug, which I will post separately.

CREATE TRIGGER "rwipinfdir:500_insert_site_before"  
BEFORE INSERT  
ON doc("infrastructure")//site  
FOR EACH NODE  
DO  
{

        let $node:=$NEW

(:insert new id:)
        let $node:=
                <site>
                        {$node/@*,
                         attribute {"id"} {concat("site_id_", $idnext)},
                         $node/*}
                </site>

(:insert name:)
        let $node:=
                <site>
                        {$node/@*, $node/*}
                        <name>new site</name>
                </site>

(:insert description:)
        let $node:=
                <site>
                        {$node/@*, $node/*}
                        <description>The new site was created but the 
information was not customized yet.</description>
                </site>

(:insert log:)
        ...
        let $node:=
                        <site>
                                {$node/@*, $node/*}
                                <log>
                                        
<createdBy>{string($partner/@id)}</createdBy>
                                        
<createTimestamp>{$timestamp}</createTimestamp>
                                        
<modifiedBy>{string($partner/@id)}</modifiedBy>
                                        
<modifyTimestamp>{$timestamp}</modifyTimestamp>
                                </log>
                        </site>

        
        return $node;    

}

The INSERT operation is working nicely

UPDATE INSERT <site/> into doc("mydoc")


The UPDATE REPLACE operation strangely (at least for me) executes also the 
INSERT BEFORE trigger. With that only section with LOG creates the error.

2009/04/08 17:31:31 database query/update failed (SEDNA Message: ERROR SE3205
Trigger action tries to update a document/collection that is currently updating 
by the outer update statement.
Details: mydoc

----------------------------------------------------------------------

>Comment By: Ivan Shcheklein (shcheklein)
Date: 2009-04-15 12:53

Message:
I've reproduced the issue. 

1. Update replace statement may fire insert trigger by design. See Sedna
Programmer’s Guide, XQuery Triggers, Figure 1.

2. Seems there is a problem with locking in triggers. While executing "let
$partner:=doc("test")//partn...@id=$user]" Sedna tries to get lm_x on
"test". This raises SE3205.

----------------------------------------------------------------------

Comment By: Konstantin (drideru)
Date: 2009-04-09 19:00

Message:
Some more info.
I created a trigger

CREATE TRIGGER "rwipinfdir:000_replace_node_with_log_before"  
BEFORE REPLACE  
ON doc("test")//* 
FOR EACH NODE  
DO  
{

...
(:access the same "test" document here:)
let $var:=doc("test)/whatever

}


this with the replace generates an error that the trigger is trying to
modify/update (where?) the same document while the document is already
being updated.

I think at least querying the same document in the trigger must be
possible. I don't know if updating the same document error is a bug. I
would expect it to be.

----------------------------------------------------------------------

Comment By: Konstantin (drideru)
Date: 2009-04-09 00:15

Message:
Instead of "SYSTEM" please use your username if necessary.

----------------------------------------------------------------------

Comment By: Konstantin (drideru)
Date: 2009-04-09 00:15

Message:
Hi, Ivan!

here is the code to execute.

---------------------------- CREATE AN EMPTY DOCUMENT
-------------------------------
create document "test"

---------------------------- CREATE TRIGGER
-----------------------------------------

declare namespace testns="TEST_UPDATE_REPLACE";

CREATE TRIGGER "testns:500_insert_site_before"  
BEFORE INSERT  
ON doc("test")//site  
FOR EACH NODE  
DO  
{

        let $node:=$NEW

(:first check if there are some elements:)
(:that are not allowed to be insert by the user:)

(:insert required subnodes and attributes if they are missing:)

(:insert name:)
        let $node:=if(empty($node/name))
        then
                <site>
                        {$node/@*, $node/*}
                        <name>new site</name>
                </site>
        else $node

(:insert description:)
        let $node:=if(empty($node/description))
        then
                <site>
                        {$node/@*, $node/*}
                        <description>The new site was created but the 
information was not
customized yet.</description>
                </site>
        else $node

(:insert log:)
        let $user := se:get-property("$user")
        let $partner:=doc("test")//partn...@id=$user]
        let $timestamp:=adjust-dateTime-to-timezone(current-dateTime(),
xs:dayTimeDuration('PT0H'))
        
        let $node:=if(empty($node/log))
        then (
                if(exists($partner))
                then
                        <site>
                                {$node/@*, $node/*}
                                <log>
                                        
<createdBy>{string($partner/@id)}</createdBy>
                                        
<createTimestamp>{$timestamp}</createTimestamp>
                                        
<modifiedBy>{string($partner/@id)}</modifiedBy>
                                        
<modifyTimestamp>{$timestamp}</modifyTimestamp>
                                </log>
                        </site>
                else
                        error(xs:QName("testns:insert_site_before"),
                                concat("Failed to locate the partner node for 
the current user '",
$user, "'."))
        )
        else $node
        
        return $node;    

}

------------------------------- INSERT NEW NODES
------------------------------------

update insert <partner id="SYSTEM"/> into doc("test")
update insert <site/> into doc("test")

------------------------------- UPDATE THE NODE
------------------------------------

update replace $site in doc("test")/site with
<site>
 <name>new site</name>
 <description>The new site was created but the information was not
customized yet.</description>
</site>



----------------------------------------------------------------------

Comment By: Ivan Shcheklein (shcheklein)
Date: 2009-04-08 23:45

Message:
Konstantin, could you provide us an example of the document and exact
queries to reproduce the issue on? 

----------------------------------------------------------------------

Comment By: Konstantin (drideru)
Date: 2009-04-08 19:49

Message:
Oh no, will not post the other bug/?. it is already described here. it
appears when the <log> section is inserted. it has two levels.

it does not appear if only <name> or <description> is inserted (UPDATE
REPLACE only).

So totally two bugs.
TRIGGER INSERT BEFORE is called upon UPDATE REPLACE.
Adding a subnode of more than one level deep in this trigger, when it is
called upon UPDATE REPLACE, causes the error SE3205.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=713730&aid=2744564&group_id=129076

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Sedna-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sedna-discussion

Reply via email to