Use db:add from module. no updating expression allowed.

Wednesday, 8 February 2012 · 3 messages
A
andy8 Feb 2012 06:29 #
Hi! If there is a module:
xquery version "1.0";
module namespace
m="http://www.host.ru/xquery/m";
declare variable $m:db :=
"mydb";

declare function m:up() as xs:string {
 let $new-doc :=
<root-element><item>1</item></root-element>
 let $update :=
db:add($m:db, document { $new-doc }, "id1.xml")
 return
 "Result
string"
};
and I use it from python API or basexclient utility. Use as: xquery import module namespace m="http://www.host.ru/xquery/m" at "/tmp/test.xqy"; m:up() I get an error: Stopped at line 8, column 4 in /tmp/test.xqy: [XUST0001] Let expression: no updating expression allowed. What could be the problem?
-- REGARDS, Andrey Ganyushkin
AW
Andreas Weiler8 Feb 2012 08:24 #
Hi there, i guess you have to define the function as updating [1]. -- Andreas [1] http://www.w3.org/TR/xquery-update-10/#id-function-declaration
Quoted text · andy · 34 lines
Am 08.02.2012 um 06:29 schrieb andy: > Hi! > > If there is a module: > > xquery version "1.0"; > module namespace m="http://www.host.ru/xquery/m"; > declare variable $m:db := "mydb"; > > declare function m:up() as xs:string { > let $new-doc := <root-element><item>1</item></root-element> > let $update := db:add($m:db, document { $new-doc }, "id1.xml") > return > "Result string" > }; > > and I use it from python API or basexclient utility. Use as: > > xquery import module namespace m="http://www.host.ru/xquery/m" at "/tmp/test.xqy"; m:up() > > I get an error: > > Stopped at line 8, column 4 in /tmp/test.xqy: > [XUST0001] Let expression: no updating expression allowed. > > What could be the problem? > > -- > Regards, > Andrey Ganyushkin > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
A
andy8 Feb 2012 08:46 #
Many thanks! Is working correctly now. Corrected code:
xquery
version "1.0";
module namespace m="http://www.host.ru/xquery/m";
declare
variable $m:db := "mydb";

declare updating function m:up() {
 let
$new-doc := <root-element><item>1</item></root-element>
 return

db:add($m:db, document { $new-doc }, "id1.xml")
};
Andreas Weiler писал 2012-02-08 11:24:
Quoted text · Andreas Weiler · 2 lines
> Hi there, > i guess you have to define the
function as updating [1].
Quoted text · Andreas Weiler · 2 lines
> -- Andreas > [1]
Quoted text · Andreas Weiler · 7 lines
> > Am 08.02.2012 um 06:29 schrieb andy: > >> Hi! >> >> If there is a
module:
Quoted text · Andreas Weiler · 9 lines
>> >> xquery version "1.0"; >> module namespace m="http://www.host.ru/xquery/m"; >> declare variable $m:db := "mydb"; >> >> declare function m:up() as xs:string { >> let $new-doc := 1 >> let
$update := db:add($m:db, document { $new-doc }, "id1.xml")
Quoted text · Andreas Weiler · 2 lines
>> return >>
"Result string"
Quoted text · Andreas Weiler · 3 lines
>> }; >> >> and I use it from python API or
basexclient utility. Use as:
Quoted text · Andreas Weiler · 2 lines
>> >> xquery import module namespace
m="http://www.host.ru/xquery/m" at "/tmp/test.xqy"; m:up()
Quoted text · Andreas Weiler · 2 lines
>> >> I get
an error:
Quoted text · Andreas Weiler · 3 lines
>> >> Stopped at line 8, column 4 in /tmp/test.xqy: >>
[XUST0001] Let expression: no updating expression allowed.
Quoted text · Andreas Weiler · 2 lines
>> >> What
could be the problem?
Quoted text · Andreas Weiler · 7 lines
>> >> -- >> >> REGARDS, >> Andrey Ganyushkin >> _______________________________________________ >> BaseX-Talk
mailing list
Quoted text · Andreas Weiler · 2 lines
>> BaseX-Talk at mailman.uni-konstanz.de [1] >>
-- REGARDS, Andrey Ganyushkin Links: ------ [1] mailto:BaseX-Talk at mailman.uni-konstanz.de [2] http://www.w3.org/TR/xquery-update-10/#id-function-declaration

⚡Generated with XQuery