XQuery Update to return values

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

XQuery Update to return values

Wu, Emma

Hi,

 

The problem I am trying to solve is that with XQuery Update faicility, I will update an element and at the same time, I want the same element to be returned. Something like the following:

 

1. update a book element’s author

2. return the updated book element

 

Is there a way to do it in one query instead of two separate queries? And it looks like update expression does not return anything

 

Thanks,

Emma

 

 

 

 

Reply | Threaded
Open this post in threaded view
|

Re: XQuery Update to return values

Carmelo Montanez
Emma:

If I am not mistaken, you can use a Transform expression, which will return a value back.
Something like this:

let $var := fn:doc("works-mod.xml")/works[1]/employee[1]
let $var1 := <pnum>P1-1</pnum>
return
 transform
  copy $newVar := $var
  modify do replace $newVar/pnum[1] with $var1
  return $newVar

Thanks,
Carmelo


At 02:02 PM 7/26/2007, Wu, Emma wrote:
Hi,
 
The problem I am trying to solve is that with XQuery Update faicility, I will update an element and at the same time, I want the same element to be returned. Something like the following:
 
1. update a book elementÂ’s author
2. return the updated book element
 
Is there a way to do it in one query instead of two separate queries? And it looks like update expression does not return anything
 
Thanks,
Emma
 
 
 
 
Reply | Threaded
Open this post in threaded view
|

RE: XQuery Update to return values

Wu, Emma

The query below does not change the original document. Only the copied var $newVar is updated.
I need the $var to be updated and return the updated $var as well. Any idea? Thanks.

Emma


-----Original Message-----
From: Carmelo Montanez [mailto:[hidden email]]
Sent: Fri 7/27/2007 9:41 AM
To: Wu, Emma; [hidden email]
Subject: Re: XQuery Update to return values
 
Emma:

If I am not mistaken, you can use a Transform expression, which will
return a value back.
Something like this:

let $var := fn:doc("works-mod.xml")/works[1]/employee[1]
let $var1 := <pnum>P1-1</pnum>
return
  transform
   copy $newVar := $var
   modify do replace $newVar/pnum[1] with $var1
   return $newVar

Thanks,
Carmelo


At 02:02 PM 7/26/2007, Wu, Emma wrote:

>Hi,
>
>The problem I am trying to solve is that with XQuery Update
>faicility, I will update an element and at the same time, I want the
>same element to be returned. Something like the following:
>
>1. update a book element's author
>2. return the updated book element
>
>Is there a way to do it in one query instead of two separate
>queries? And it looks like update expression does not return anything
>
>Thanks,
>Emma
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: XQuery Update to return values

Jonathan Robie-2

Hi Emma,

In the current spec, you can either change a data model instance with a
query that generates a pending update list, or do a transform or a
query, but you can't do both. And all expressions in an update are
evaluated within one snapshot.

The Scripting Extensions for XQuery will introduce statements, allowing
expressions to be evaluated after an update has been made. Only the
requirements document currently exists:

http://www.w3.org/TR/xquery-sx-10-requirements/

In the meantime, you can do this if you embed XQuery in a procedural
language.

Hope this helps!

Jonathan

Wu, Emma wrote:

> The query below does not change the original document. Only the copied var $newVar is updated.
> I need the $var to be updated and return the updated $var as well. Any idea? Thanks.
>
> Emma
>
>
> -----Original Message-----
> From: Carmelo Montanez [mailto:[hidden email]]
> Sent: Fri 7/27/2007 9:41 AM
> To: Wu, Emma; [hidden email]
> Subject: Re: XQuery Update to return values
>  
> Emma:
>
> If I am not mistaken, you can use a Transform expression, which will
> return a value back.
> Something like this:
>
> let $var := fn:doc("works-mod.xml")/works[1]/employee[1]
> let $var1 := <pnum>P1-1</pnum>
> return
>   transform
>    copy $newVar := $var
>    modify do replace $newVar/pnum[1] with $var1
>    return $newVar
>
> Thanks,
> Carmelo
>
>
> At 02:02 PM 7/26/2007, Wu, Emma wrote:
>  
>> Hi,
>>
>> The problem I am trying to solve is that with XQuery Update
>> faicility, I will update an element and at the same time, I want the
>> same element to be returned. Something like the following:
>>
>> 1. update a book element's author
>> 2. return the updated book element
>>
>> Is there a way to do it in one query instead of two separate
>> queries? And it looks like update expression does not return anything
>>
>> Thanks,
>> Emma
>>
>>
>>
>>
>>    
>
>
>
>  


Reply | Threaded
Open this post in threaded view
|

RE: XQuery Update to return values

Wu, Emma
In reply to this post by Wu, Emma

Hi Martin,

What is the syntax that X-Hive/DB supports for returning values? Or are
there any documents I can have a look at? Thanks.

Emma

-----Original Message-----
From: Martin Probst [mailto:[hidden email]]
Sent: Saturday, July 28, 2007 3:09 AM
To: Jonathan Robie
Cc: Wu, Emma; Carmelo Montanez; [hidden email]
Subject: Re: XQuery Update to return values

> In the current spec, you can either change a data model instance with
a
> query that generates a pending update list, or do a transform or a
> query, but you can't do both.

When I implemented the XQuery update spec for X-Hive/DB I deliberately
chose not to follow that path, but rather to allow update expressions to
return values. I still can't see any need or technical merit in that
limitation, and it really hurts if you want to do something as simple as
returning how many items were changed. I think there should still be an
open bug in W3C's bugzilla about that issue.

Best regards,
Martin Probst


Reply | Threaded
Open this post in threaded view
|

RE: XQuery Update to return values

Daniel Engovatov
In reply to this post by Wu, Emma

Can not do this in the current version of the update facility.

This use case was accepted to be resolved as part of the Scripting Extension facility work – part 3.4 of the requirements: http://www.w3.org/TR/xquery-sx-10-requirements/#functionalities – returning values from expressions that have side-effects.

 

Daniel;

 

 


From: [hidden email] [mailto:[hidden email]] On Behalf Of Wu, Emma
Sent: Thursday, July 26, 2007 11:02 AM
To: [hidden email]
Subject: XQuery Update to return values

 

Hi,

 

The problem I am trying to solve is that with XQuery Update faicility, I will update an element and at the same time, I want the same element to be returned. Something like the following:

 

1. update a book element’s author

2. return the updated book element

 

Is there a way to do it in one query instead of two separate queries? And it looks like update expression does not return anything

 

Thanks,

Emma

 

 

 

 


Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.
Reply | Threaded
Open this post in threaded view
|

Re: XQuery Update to return values

Martin Probst
In reply to this post by Wu, Emma

Hi Emma,

> What is the syntax that X-Hive/DB supports for returning values? Or  
> are
> there any documents I can have a look at? Thanks.

X-Hive simply allows to mix updating statements with non-updating  
statements, i.e.

declare updating function local:foo() as xs:integer
{
   let $items := ...
   return (
     do delete $items,
     count($items))
}

You can download X-Hive/DB from http://www.x-hive.com/products/db/,  
the download includes documentation.

Regards,
Martin

--
Martin Probst
X-Hive Corporation
[hidden email]



Reply | Threaded
Open this post in threaded view
|

RE: XQuery Update to return values

Daniel Engovatov

>X-Hive simply allows to mix updating statements with non-updating  
>statements, i.e.

It's nice not having to worry about any other possible implementations.
:)

D;


Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

Reply | Threaded
Open this post in threaded view
|

Re: XQuery Update to return values

Martin Probst

>> X-Hive simply allows to mix updating statements with non-updating
>> statements, i.e.
>
> It's nice not having to worry about any other possible  
> implementations.
> :)

Well, I've always adhered to anything in the standard, so I really  
had a bad feeling about this. Still, I think it should be possible to  
do such easy things as getting the number of items deleted without  
resorting to some scripting language etc. Also, I'm not sure how it  
turns out, but if the single steps in an XQuery "script" really run  
transactionally separated, getting this information might still be  
problematic...

Martin

--
Martin Probst
X-Hive Corporation
[hidden email]