Updating after using FLWOR queries

Hi

I’ve written a simple VB.NET app which pulls data from a Tamino db into a datagrid for update. The data appears fine, and is updateable without problems when the query I use to initially retrieve the data is along the lines of “input()/ enquiry” (ie it just relates to a document). However, the structure I want to edit is fairly complex and I want to shield the user from having to navigate through it, so I’ve created a FLWOR expression as follows:

for $b in input()/enquiry
where $b/enquiry-no=‘204122’
return { $b/enquiry-no,
$b/service-data/description,
$b/customer-data/forename,
$b/customer-data/surname,
$b/customer-data/paon,
$b/customer-data/street-name,
$b/customer-data/locality,
$b/customer-data/town,
$b/customer-data/postcode,
$b/status,
$b/comments }

The data is retrieved as desired, but when I make a change to the data and attempt an ‘update’ against my TaminoDataAdapter object, it just hangs until the timeout catches it.

Can I use a FLWOR expression as above in an updateable dataset? If so, then can you give me some ideas as to why this isn’t working? I’ve read about the mapping that’s sometimes required for updating subtrees - do I need these setting?

Thanks in advance. Rgds

As there is no tie between the documents and the original Tamino documents, you can’t update Tamino documents directly from this type of query.

Thanks for the prompt reply. It’s not what I wanted to hear, but I can understand why it won’t work (I just hoped the API would be able to work it out!). The structure of the XML is too unwieldy for our end-users to navigate as it stands, so I need to find a way to simplify it - I’d appreciate anyone’s views on how this might best be done.

My current thoughts are along the lines of using the .NET API to extract the data in the form I want (ie. using FLWOR), but then sending the user-updated XML stream back via a webservice which is forwarded to a Mediator sequence which can extract the data and insert it into the correct positions in the database. Does this sound feasible? Anyone any other ideas of how I could still achieve this using the .NET API?

Rgds, Matt.

My thought would be to include the ino:id (or application unique id for the documents) in the set for the documents. When the update is requested, obtain each modified document via the ino:id/uqid from the dataset and use the Update command or a FLWU update XQUERY to modify the documents.

Thanks for the reply. I’m a relative newcomer to XML so may need some hand-holding through this one, but I’ll give it a go as per your suggestion. Thanks for your help so far - very much appreciated. Rgds, Matt.

I think that the TaminoDataAdapter was intended to allow the user to query subtrees, manipulate them + update them. You’ll need to help identify the subtrees for updating.

Have look under the DataSetSamples QueryItemMapping.

Hi. I’m progressing slowly on this, but now have the data being returned to a datagrid in VB.NET, and am now at the point where I want to push updates back into Tamino. I have a unique attribute to search on (the ‘enquiry-no’), and have constucted the following XQuery as a test in the interactive interface (to help me understand updating data in Tamino)

update for $b in input()/enquiry
where $b/enquiry-no=‘204148’
do replace $b/comments
with attribute comments {‘MJB Test’}

However, when I run this I get a message stating “It is not possible to open a cursor with XQuery Update Request.”. Anyone have any idea why?

is “comments” an attribute or not? You are asking to replace an element ($b/comments) with an attribute “with attribute comments…”.

Hi,

I assume you try this from Tamino Interactive Interface. The problem is that you cannot open a cursor with update statements (they do not give back any documents). Tamino Interactive Interface tries to open a cursor, however, if the “pos” field is checked

Hope this helps

Regards

Harald

Douglas, Harald- Thanks both for your responses; you were each correct and I’ve now got my updates working from the Interactive Interface as a result. I just need to try and transpose this into Visual Studio now… don’t go too far away…

Thanks.

One last thing: I’ve written the following:

update for $b in input()/enquiry
where $b/enquiry-no=‘204149’
do replace $b/comments
with element comments {‘MJB Test’}

which works fine. However, how would I update two elements at the same time (eg. element name ‘status’)? I’ve tried:

update for $b in input()/enquiry
where $b/enquiry-no=‘204149’
do replace $b/comments
with element comments {‘MJB Test’}, status{‘Closed’}

but it fails with a syntax error. Could someone tell me what the correct syntax for this would be?

update for $b in input()/enquiry
where $b/enquiry-no=‘204149’
do (
replace $b/comments with element comments {‘MJB Test’}
replace $b/status with element status{‘Closed’}
)

Thanks for that Douglas; works a treat. That’s me finished on this work for now - I’ve got a working prototype to put to the business for their comment. Thanks for all your help.

Back already I’m afraid… I’ve got an element in my XML which reads:

When I use a FLWOR query to extract this (albeit blank) value, eg.

for $b in input()/enquiry
where $b/queue-description = ‘xxxx’
return {$b/ContractorCommentsTextarea}

I get:

As expected, it returns an empty value, but it also returns the ‘description’ (attribute?) and its value. Unfortunately, the dataGrid control in .NET interprets this as a new table and my wonderful app falls apart.

Is there a syntax for just extracting the value of the element without the ‘description’ attribute (if ‘attribute’ is the correct term for this)? I’d like to get the following in my output:

(or myText for when there’s a value to return).

I’ll really stop bothering you soon… :slight_smile:

If oyu extract an element, you get the value and all attributes, that is what happened to you. In order to get just the value, you can extract the value only and add the element tags by yourself, as in the following query:
for $b in input()/enquiry
where $b/queue-description = ‘xxxx’
return {$b/ContractorCommentsTextarea/text()}

Regards

Harald

The /text() function works fine, but how do I create the element tags? I’ve tried the following:

… return {“comments”,$b/enquiry-data/ContractorCommentsTextarea/text(),“”}

and although I get the correct format out, my browser (and my app’s dataset) don’t recognise this as an element; they ‘know’ it’s a fake! Is there a way to define this text so it appears as an element name/tag?

By sheer chance I’ve managed to find the solution:

{$b/enquiry-data/ContractorCommentsTextarea/text()}

Thanks for your help. Rgds.

There are constructors in XQuery, which use teh same syntax as in XML:

return example value

There is an alternative form:

return element mynewElement {“example value”}