Hi Rob,

the official XQuery functions are limited to non-updating function
arguments. Enabling MIXUPDATES is the only way out, because you would
otherwise be able to write code that is both updating and
non-updating:

  for $f in (db:output#1, count#1)
  return apply($f, [1])

Hope this helps,
Christian



On Wed, Aug 30, 2017 at 7:37 AM, Rob Stapper <r.stap...@lijbrandt.nl> wrote:
> Hi Michael and Marco,
>
> Thanx for the feedback.
>
> @Marco, setting MIXUPDATES is an efficient work around for suppressing the 
> error message but the cost is that you lose the updating-checks completely.  
> Updating-checks are very useful.
> @Michael, I'll dive into the XQUF 3.0. Sounds interesting.
>
> Fact stays that the updating check doesn't work, as I see it, properly on the 
> apply-function. Something for Christian to dive into when he is back on 
> holidays ;-)
>
> Again thanx for the replies.
>
> Have fun,
>
> Rob
>
>
> -----Oorspronkelijk bericht-----
> Van: basex-talk-boun...@mailman.uni-konstanz.de 
> [mailto:basex-talk-boun...@mailman.uni-konstanz.de] Namens Michael Seiferle
> Verzonden: dinsdag 29 augustus 2017 21:08
> Aan: Marco Lettere
> CC: basex-talk@mailman.uni-konstanz.de
> Onderwerp: Re: [basex-talk] Fwd: Re: using apply-function within an updating 
> function
>
> Hi Rob,
> hi Marco,
>
>
> First: sorry for not coming back to you earlier.
>
> Glad it worked using mixupdates, but I think there might be a way to make it 
> work using the new XQUF 3.0 "invoke updating" capabilities  :-) Christian is 
> currently on holiday, I am sure he will report back on this.
>
>
> Best from Konstanz,
>
> Michael
>
> Von meinem iPhone gesendet
>
>> Am 29.08.2017 um 15:17 schrieb Marco Lettere <m.lett...@gmail.com>:
>>
>> Hi Rob,
>> I suppose that if you add MIXUPDATES=true below #LOCAL OPTIONS in the .basex 
>> file that you will find in your basex install directory and restart your 
>> GUI, the error will not show up any longer in the GUI itself.
>> Regards,
>> Marco.
>>
>>> On 29/08/2017 15:07, r.stap...@lijbrandt.nl wrote:
>>> Hi Michael,
>>>
>>> Though the GUI still gives an error onth the use of the apply-function 
>>> within an updating function, my webservices do work correctly. Just added 
>>> the MIXUPDATES-option in the web.xml file.
>>>
>>> Best Rob.
>>>
>>> -------- Oorspronkelijke bericht --------
>>> Onderwerp: Re: [basex-talk] using apply-function within an updating
>>> function
>>> Datum: 29.08.2017 08:06
>>> Afzender: r.stap...@lijbrandt.nl
>>> Ontvanger: Michael Seiferle <m...@basex.org>
>>> Kopie: BaseX <basex-talk@mailman.uni-konstanz.de>
>>>
>>> Hi Michael,
>>>
>>> Th point is that I am looking for a generic solution which I thought I had 
>>> found with the use of the apply-function.
>>> Most of my webservices take a record with more than one fieldvalue. By 
>>> putting the fieldvalues in an json-formatted array on the client side and 
>>> the use of the apply-function on the serverside, see [1], I thought I had 
>>> found a nice and clean generic solution. Unfortunately this soultion gives 
>>> me the error: "Function body must be an updating expression".
>>>
>>> The issue is that the error is, in my opinion, falsely triggered by the use 
>>> of the apply-function within updating function. An updating-error-situation 
>>> should, in my opinion, be determined based on the function that is called 
>>> by the apply function. In this case though the apply function calls an 
>>> updating function, Basex still triggeres an updating error.
>>>
>>> I cann't use MIXEDUPDATES because my webservices are in a module.
>>>
>>> I really would like to use the apply-function here. What to do?
>>>
>>> [1]
>>> declare
>>>  %rest:path("/cFactBank/request/new")
>>>  %rest:PUT("{$dataRec}")
>>>  %input:json("format=map")
>>>
>>>  %updating
>>>  function _:request.new
>>>      ( $dataRec as array(*)
>>>      )
>>>      {
>>>        apply( request:new#6
>>>             , $dataRec
>>>             )
>>>      } ;
>>>
>>>
>>> Greetings,
>>> Rob
>>>
>>>
>>> Michael Seiferle schreef op 28.08.2017 18:20:
>>>> Hi Rob,
>>>>
>>>> may I ask what you intented to do? Looks like you expect $dataRec to
>>>> contain exactly one value, right?
>>>> At least I think so because you called `db:create#1` in `fn:apply`
>>>> which implies you expect the array to contain a single value.
>>>>
>>>> To create a single database use:
>>>>
>>>>> ```
>>>>> db:create($dataRec => array:get(1)) ```
>>>>
>>>> …or… if you want to create a database for each of the array
>>>> values:
>>>>
>>>>> for $db in ($dataRec => array:flatten()) (: Flatten array to a
>>>>> sequence :)
>>>>> return db:create($db).                            (: create one
>>>>> database per array item :)
>>>>
>>>> …and… last but not least, for "Dynamic Updating Function
>>>> Invocation“[1] you might use:
>>>>
>>>>> let $create  := db:create#1
>>>>> for $db in ($dataRec => array:flatten()) return invoke updating
>>>>> $create($db)
>>>>
>>>> I could not wrap my head around using array:for-each(#2) and dynamic
>>>> updating function invocation; this could make for a more readable
>>>> solution, but I can not seem to get the syntax right; if we already
>>>> fully support it at all ;-)
>>>>
>>>> I hope I did not get you all wrong, feel free to ask for more help!
>>>> ;-)
>>>>
>>>> Best
>>>> Michael
>>>>
>>>> [1]
>>>> https://www.w3.org/TR/xquery-update-30/#id-dynamic-updating-function
>>>> -invocation
>>>>
>>>>> Am 28.08.2017 um 16:42 schrieb r.stap...@lijbrandt.nl:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I want to use the apply function within an updating webfunction,
>>>>> see[1] How can this be done?
>>>>>
>>>>> TIA,
>>>>>
>>>>> Rob Stapper
>>>>>
>>>>> [1]
>>>>> declare
>>>>> %rest:path("/cFactBank/dbCreate")
>>>>> %rest:PUT("{$dataRec}")
>>>>> %input:json("format=map")
>>>>>
>>>>> %updating
>>>>> function _:cFactBank.dbCreate
>>>>> (  $dataRec as array(*)
>>>>> )
>>>>> {
>>>>> apply( db:create#1
>>>>> , $dataRec
>>>>> )
>>>>> } ;
>>
>>
>

Reply via email to