C# Client - Updating query

Tuesday, 29 November 2016 · 5 messages
CS
Chris Speare29 Nov 2016 14:49 #
Hi all, Trying to use the C# client available from https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/c%23 to perform an update query, however I must be missing the obvious - query runs and no exceptions are raised, however the XML remains un-changed. Code snippet (as this is held on a different machine):
String base_update_query = @"xquery version '3.0';
                let $invoice := db:open('{0}')/CommercialDocument[Customer/@id={1}]
                return replace value of node $invoice/InvoiceNumber with '{2}'";
.... Session session = new Session("localhost", 1984, "admin", "my_pass"); Query q = session.Query( String.Format( base_update_query, String.Concat("billing_run_", billing_run_id), customer_id, invoice_number ) ); .... From the BaseX logs I then see entries:
QUERY[1] xquery version '3.0'; let $invoice := db:open('billing_run_506')/CommercialDocument[Customer/@id=437] return replace value of node $invoice/InvoiceNumber with '28443'
so I know the query reached the server, and the response seems to be "not error" as no exception is being raised - however the XML document hasn't been updated. Yet if I run the same query in either the client or web client it works (document updates) - provided I switch the query to "updating" not read-only. Is there a flag I've missed, or is .Query of Session the wrong method to use Kind regards Chris Speare The information contained in the email and any files transmitted with it is confidential and intended for the addressee only. If you have received this email in error please accept our apologies and notify the originator. Any disclosure, copying, distribution or any other use of this communication is strictly prohibited and may be unlawful. We reserve the right to monitor and intercept communications for lawful business purposes. Wireless Innovation Ltd , Unit D2, Churcham Business Park, Churcham, Gloucestershire, GL2 8AX, Great Britain. Company Registration Number 5240202, Place of Registration Companies House Cardiff.
CG
Christian Grün29 Nov 2016 14:54 #
Hi Chris, You’ll probably need to call q.Execute (see [1] for an example). Hope this helps, Christian Cheers, Christian [1] https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/c%23/QueryBindExample.cs
Quoted text · Chris Speare · 62 lines
> Trying to use the C# client available from > https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/c%23 to > perform an update query, however I must be missing the obvious - query runs > and no exceptions are raised, however the XML remains un-changed. Code > snippet (as this is held on a different machine): > > String base_update_query = @"xquery version '3.0'; > let $invoice := > db:open('{0}')/CommercialDocument[Customer/@id={1}] > return replace value of node $invoice/InvoiceNumber with > '{2}'"; > > .... > > Session session = new Session("localhost", 1984, "admin", "my_pass"); > > Query q = session.Query( > String.Format( > base_update_query, > String.Concat("billing_run_", billing_run_id), customer_id, > invoice_number > ) > ); > > .... > > From the BaseX logs I then see entries: > > QUERY[1] xquery version '3.0'; let $invoice := > db:open('billing_run_506')/CommercialDocument[Customer/@id=437] return > replace value of node $invoice/InvoiceNumber with '28443' > > so I know the query reached the server, and the response seems to be "not > error" as no exception is being raised - however the XML document hasn't > been updated. Yet if I run the same query in either the client or web > client it works (document updates) - provided I switch the query to > "updating" not read-only. > > Is there a flag I've missed, or is .Query of Session the wrong method to use > > Kind regards > > Chris Speare > > > > The information contained in the email and any files transmitted with it is > confidential and intended for the addressee only. If you have received this > email in error please accept our apologies and notify the originator. Any > disclosure, copying, distribution or any other use of this communication is > strictly prohibited and may be unlawful. We reserve the right to monitor and > intercept communications for lawful business purposes. > > > > Wireless Innovation Ltd , Unit D2, Churcham Business Park, Churcham, > Gloucestershire, GL2 8AX, Great Britain. > > Company Registration Number 5240202, Place of Registration Companies House > Cardiff. > >
CS
Chris Speare29 Nov 2016 15:18 #
Christian, Many thanks - I had actually been planning to update to a bind after I got the initial parts working (eye roll) however now getting a different error. New code:
String base_update_query = @"xquery version '3.0';
   let $invoice := db:open('{ $resource
}')/CommercialDocument[Customer/@id={ $customer_id }]
   return replace value of node $invoice/InvoiceNumber with '{
$invoice_number }'";

Query q = session.Query(base_update_query);
q.Bind("$resource", String.Concat("billing_run_", billing_run_id));
q.Bind("$customer_id",
myXmlNode.FirstChild["Customer"].GetAttribute("id"));
q.Bind("$invoice_number", invoice_number);
q.Execute();
From the logs: BIND[1] $resource=billing_run_506 BIND[1] $customer_id=1011 BIND[1] $invoice_number=28458 Stopped at ., 2/90: [XPST0003] Comparison is incomplete. So annoyingly close.....
Quoted text · Christian Grün · 77 lines
On 29/11/16 13:54, Christian Grün wrote: > Hi Chris, > > You’ll probably need to call q.Execute (see [1] for an example). > > Hope this helps, > Christian > > Cheers, > Christian > > [1] https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/c%23/QueryBindExample.cs > > > >> Trying to use the C# client available from >> https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/c%23 to >> perform an update query, however I must be missing the obvious - query runs >> and no exceptions are raised, however the XML remains un-changed. Code >> snippet (as this is held on a different machine): >> >> String base_update_query = @"xquery version '3.0'; >> let $invoice := >> db:open('{0}')/CommercialDocument[Customer/@id={1}] >> return replace value of node $invoice/InvoiceNumber with >> '{2}'"; >> >> .... >> >> Session session = new Session("localhost", 1984, "admin", "my_pass"); >> >> Query q = session.Query( >> String.Format( >> base_update_query, >> String.Concat("billing_run_", billing_run_id), customer_id, >> invoice_number >> ) >> ); >> >> .... >> >> From the BaseX logs I then see entries: >> >> QUERY[1] xquery version '3.0'; let $invoice := >> db:open('billing_run_506')/CommercialDocument[Customer/@id=437] return >> replace value of node $invoice/InvoiceNumber with '28443' >> >> so I know the query reached the server, and the response seems to be "not >> error" as no exception is being raised - however the XML document hasn't >> been updated. Yet if I run the same query in either the client or web >> client it works (document updates) - provided I switch the query to >> "updating" not read-only. >> >> Is there a flag I've missed, or is .Query of Session the wrong method to use >> >> Kind regards >> >> Chris Speare >> >> >> >> The information contained in the email and any files transmitted with it is >> confidential and intended for the addressee only. If you have received this >> email in error please accept our apologies and notify the originator. Any >> disclosure, copying, distribution or any other use of this communication is >> strictly prohibited and may be unlawful. We reserve the right to monitor and >> intercept communications for lawful business purposes. >> >> >> >> Wireless Innovation Ltd , Unit D2, Churcham Business Park, Churcham, >> Gloucestershire, GL2 8AX, Great Britain. >> >> Company Registration Number 5240202, Place of Registration Companies House >> Cardiff. >> >>
The information contained in the email and any files transmitted with it is confidential and intended for the addressee only. If you have received this email in error please accept our apologies and notify the originator. Any disclosure, copying, distribution or any other use of this communication is strictly prohibited and may be unlawful. We reserve the right to monitor and intercept communications for lawful business purposes. Wireless Innovation Ltd , Unit D2, Churcham Business Park, Churcham, Gloucestershire, GL2 8AX, Great Britain. Company Registration Number 5240202, Place of Registration Companies House Cardiff.
CG
Christian Grün29 Nov 2016 15:21 #
Hi Chris,
Quoted text · Chris Speare · 1 line
> }')/CommercialDocument[Customer/@id={ $customer_id }]
Your XQuery expression is invalid; values in comparisons cannot be wrapped into curly braces. Maybe it helps to run your query in the GUI or on command-line first, and then see what happens if you use it in the C# binding. Cheers, Christian
Quoted text · Chris Speare · 129 lines
> return replace value of node $invoice/InvoiceNumber with '{ > $invoice_number }'"; > > Query q = session.Query(base_update_query); > q.Bind("$resource", String.Concat("billing_run_", billing_run_id)); > q.Bind("$customer_id", > myXmlNode.FirstChild["Customer"].GetAttribute("id")); > q.Bind("$invoice_number", invoice_number); > q.Execute(); > > From the logs: > > BIND[1] $resource=billing_run_506 > > BIND[1] $customer_id=1011 > > BIND[1] $invoice_number=28458 > > Stopped at ., 2/90: [XPST0003] Comparison is incomplete. > > So annoyingly close..... > > > > On 29/11/16 13:54, Christian Grün wrote: >> >> Hi Chris, >> >> You’ll probably need to call q.Execute (see [1] for an example). >> >> Hope this helps, >> Christian >> >> Cheers, >> Christian >> >> [1] >> https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/c%23/QueryBindExample.cs >> >> >> >>> Trying to use the C# client available from >>> https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/c%23 to >>> perform an update query, however I must be missing the obvious - query >>> runs >>> and no exceptions are raised, however the XML remains un-changed. Code >>> snippet (as this is held on a different machine): >>> >>> String base_update_query = @"xquery version '3.0'; >>> let $invoice := >>> db:open('{0}')/CommercialDocument[Customer/@id={1}] >>> return replace value of node $invoice/InvoiceNumber with >>> '{2}'"; >>> >>> .... >>> >>> Session session = new Session("localhost", 1984, "admin", "my_pass"); >>> >>> Query q = session.Query( >>> String.Format( >>> base_update_query, >>> String.Concat("billing_run_", billing_run_id), customer_id, >>> invoice_number >>> ) >>> ); >>> >>> .... >>> >>> From the BaseX logs I then see entries: >>> >>> QUERY[1] xquery version '3.0'; let $invoice := >>> db:open('billing_run_506')/CommercialDocument[Customer/@id=437] return >>> replace value of node $invoice/InvoiceNumber with '28443' >>> >>> so I know the query reached the server, and the response seems to be "not >>> error" as no exception is being raised - however the XML document hasn't >>> been updated. Yet if I run the same query in either the client or web >>> client it works (document updates) - provided I switch the query to >>> "updating" not read-only. >>> >>> Is there a flag I've missed, or is .Query of Session the wrong method to >>> use >>> >>> Kind regards >>> >>> Chris Speare >>> >>> >>> >>> The information contained in the email and any files transmitted with it >>> is >>> confidential and intended for the addressee only. If you have received >>> this >>> email in error please accept our apologies and notify the originator. Any >>> disclosure, copying, distribution or any other use of this communication >>> is >>> strictly prohibited and may be unlawful. We reserve the right to monitor >>> and >>> intercept communications for lawful business purposes. >>> >>> >>> >>> Wireless Innovation Ltd , Unit D2, Churcham Business Park, Churcham, >>> Gloucestershire, GL2 8AX, Great Britain. >>> >>> Company Registration Number 5240202, Place of Registration Companies >>> House >>> Cardiff. >>> >>> > > > > The information contained in the email and any files transmitted with it is > confidential and intended for the addressee only. If you have received this > email in error please accept our apologies and notify the originator. Any > disclosure, copying, distribution or any other use of this communication is > strictly prohibited and may be unlawful. We reserve the right to monitor and > intercept communications for lawful business purposes. > > > > Wireless Innovation Ltd , Unit D2, Churcham Business Park, Churcham, > Gloucestershire, GL2 8AX, Great Britain. > > Company Registration Number 5240202, Place of Registration Companies House > Cardiff. > >
CS
Chris Speare29 Nov 2016 15:58 #
Christian, Many thanks this was a lack of my understanding of how the bound variable should be used - requiring the declare variable lines before their use. This is now working and processing data as we speak. Many thanks for your assistance :) Cheers Chris Speare (I'll register a different email for future requests to get rid of my company footer as know that's unwanted on the mailing list)
Quoted text · Christian Grün · 141 lines
On 29/11/16 14:21, Christian Grün wrote: > Hi Chris, > >> }')/CommercialDocument[Customer/@id={ $customer_id }] > Your XQuery expression is invalid; values in comparisons cannot be > wrapped into curly braces. > > Maybe it helps to run your query in the GUI or on command-line first, > and then see what happens if you use it in the C# binding. > > Cheers, > Christian > > >> return replace value of node $invoice/InvoiceNumber with '{ >> $invoice_number }'"; >> >> Query q = session.Query(base_update_query); >> q.Bind("$resource", String.Concat("billing_run_", billing_run_id)); >> q.Bind("$customer_id", >> myXmlNode.FirstChild["Customer"].GetAttribute("id")); >> q.Bind("$invoice_number", invoice_number); >> q.Execute(); >> >> From the logs: >> >> BIND[1] $resource=billing_run_506 >> >> BIND[1] $customer_id=1011 >> >> BIND[1] $invoice_number=28458 >> >> Stopped at ., 2/90: [XPST0003] Comparison is incomplete. >> >> So annoyingly close..... >> >> >> >> On 29/11/16 13:54, Christian Grün wrote: >>> Hi Chris, >>> >>> You’ll probably need to call q.Execute (see [1] for an example). >>> >>> Hope this helps, >>> Christian >>> >>> Cheers, >>> Christian >>> >>> [1] >>> https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/c%23/QueryBindExample.cs >>> >>> >>> >>>> Trying to use the C# client available from >>>> https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/c%23 to >>>> perform an update query, however I must be missing the obvious - query >>>> runs >>>> and no exceptions are raised, however the XML remains un-changed. Code >>>> snippet (as this is held on a different machine): >>>> >>>> String base_update_query = @"xquery version '3.0'; >>>> let $invoice := >>>> db:open('{0}')/CommercialDocument[Customer/@id={1}] >>>> return replace value of node $invoice/InvoiceNumber with >>>> '{2}'"; >>>> >>>> .... >>>> >>>> Session session = new Session("localhost", 1984, "admin", "my_pass"); >>>> >>>> Query q = session.Query( >>>> String.Format( >>>> base_update_query, >>>> String.Concat("billing_run_", billing_run_id), customer_id, >>>> invoice_number >>>> ) >>>> ); >>>> >>>> .... >>>> >>>> From the BaseX logs I then see entries: >>>> >>>> QUERY[1] xquery version '3.0'; let $invoice := >>>> db:open('billing_run_506')/CommercialDocument[Customer/@id=437] return >>>> replace value of node $invoice/InvoiceNumber with '28443' >>>> >>>> so I know the query reached the server, and the response seems to be "not >>>> error" as no exception is being raised - however the XML document hasn't >>>> been updated. Yet if I run the same query in either the client or web >>>> client it works (document updates) - provided I switch the query to >>>> "updating" not read-only. >>>> >>>> Is there a flag I've missed, or is .Query of Session the wrong method to >>>> use >>>> >>>> Kind regards >>>> >>>> Chris Speare >>>> >>>> >>>> >>>> The information contained in the email and any files transmitted with it >>>> is >>>> confidential and intended for the addressee only. If you have received >>>> this >>>> email in error please accept our apologies and notify the originator. Any >>>> disclosure, copying, distribution or any other use of this communication >>>> is >>>> strictly prohibited and may be unlawful. We reserve the right to monitor >>>> and >>>> intercept communications for lawful business purposes. >>>> >>>> >>>> >>>> Wireless Innovation Ltd , Unit D2, Churcham Business Park, Churcham, >>>> Gloucestershire, GL2 8AX, Great Britain. >>>> >>>> Company Registration Number 5240202, Place of Registration Companies >>>> House >>>> Cardiff. >>>> >>>> >> >> >> The information contained in the email and any files transmitted with it is >> confidential and intended for the addressee only. If you have received this >> email in error please accept our apologies and notify the originator. Any >> disclosure, copying, distribution or any other use of this communication is >> strictly prohibited and may be unlawful. We reserve the right to monitor and >> intercept communications for lawful business purposes. >> >> >> >> Wireless Innovation Ltd , Unit D2, Churcham Business Park, Churcham, >> Gloucestershire, GL2 8AX, Great Britain. >> >> Company Registration Number 5240202, Place of Registration Companies House >> Cardiff. >> >>
The information contained in the email and any files transmitted with it is confidential and intended for the addressee only. If you have received this email in error please accept our apologies and notify the originator. Any disclosure, copying, distribution or any other use of this communication is strictly prohibited and may be unlawful. We reserve the right to monitor and intercept communications for lawful business purposes. Wireless Innovation Ltd , Unit D2, Churcham Business Park, Churcham, Gloucestershire, GL2 8AX, Great Britain. Company Registration Number 5240202, Place of Registration Companies House Cardiff.

⚡Generated with XQuery