apply variable bindings to command scripts

Friday, 11 April 2014 · 6 messages · last reply 26 May 2014
FE
Fabrice Etanchaud11 Apr 2014 15:57 #
Dear all, Currently, in order to obtain tailored command scripts, I found the following solution : A template test.bxs file :
<commands>
  <open name='${DBNAME}'/>
  <xquery>
        <![CDATA[
                (/document)[1]
        ]]>
  </xquery>
  <close/>
</commands>
A bash script test.sh: #!/bin/bash DBNAME=de-dpma-u-meta eval "cat <<EOF $(<$1) EOF " | basex -c- And then call : ./test.sh test.bxs Could it be possible for the variable bindings to be applied also to script commands, So basex -bDBNAME=de-dpma-u-meta test.bxs does the whole job ? that would work also for commands' sequences like :
<set option='bindings'>.....
<execute> or <run>
Merci ! Best regards, Fabrice
CG
Christian Grün14 Apr 2014 11:44 #
Hi Fabrice, I've recorded your feature request in a new issue: https://github.com/BaseXdb/basex/issues/929 Christian
Quoted text · Fabrice Etanchaud · 91 lines
On Fri, Apr 11, 2014 at 3:57 PM, Fabrice Etanchaud <fetanchaud at questel.com> wrote: > Dear all, > > > > Currently, in order to obtain tailored command scripts, I found the > following solution : > > > > A template test.bxs file : > > > > <commands> > > <open name='${DBNAME}'/> > > <xquery> > > <![CDATA[ > > (/document)[1] > > ]]> > > </xquery> > > <close/> > > </commands> > > > > A bash script test.sh: > > > > #!/bin/bash > > > > DBNAME=de-dpma-u-meta > > > > eval "cat <<EOF > > $(<$1) > > EOF > > " | basex -c- > > > > And then call : > > > > ./test.sh test.bxs > > > > > > Could it be possible for the variable bindings to be applied also to script > commands, > > So basex -bDBNAME=de-dpma-u-meta test.bxs > > does the whole job ? > > > > that would work also for commands' sequences like : > > <set option='bindings'>..... > > <execute> or <run> > > > > Merci ! > > > > Best regards, > > Fabrice
CG
Christian Grün4 May 2014 22:08 #
Hi Fabrice, I'm still hesitant to introduce more features to the command script syntax, as all of them will be BaseX-specific. But we could interpret all input as XQuery and execute the resulting XML as BaseX commands. This way, we could write things like..
  <commands>{
    for $n in 1 to 10
    return <create-db name='db{ $n }'/>
  }</commands>
What do you think? Christian
Quoted text · Christian Grün · 103 lines
On Mon, Apr 14, 2014 at 11:44 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Fabrice, > > I've recorded your feature request in a new issue: > > https://github.com/BaseXdb/basex/issues/929 > > Christian > > > > On Fri, Apr 11, 2014 at 3:57 PM, Fabrice Etanchaud > <fetanchaud at questel.com> wrote: >> Dear all, >> >> >> >> Currently, in order to obtain tailored command scripts, I found the >> following solution : >> >> >> >> A template test.bxs file : >> >> >> >> <commands> >> >> <open name='${DBNAME}'/> >> >> <xquery> >> >> <![CDATA[ >> >> (/document)[1] >> >> ]]> >> >> </xquery> >> >> <close/> >> >> </commands> >> >> >> >> A bash script test.sh: >> >> >> >> #!/bin/bash >> >> >> >> DBNAME=de-dpma-u-meta >> >> >> >> eval "cat <<EOF >> >> $(<$1) >> >> EOF >> >> " | basex -c- >> >> >> >> And then call : >> >> >> >> ./test.sh test.bxs >> >> >> >> >> >> Could it be possible for the variable bindings to be applied also to script >> commands, >> >> So basex -bDBNAME=de-dpma-u-meta test.bxs >> >> does the whole job ? >> >> >> >> that would work also for commands' sequences like : >> >> <set option='bindings'>..... >> >> <execute> or <run> >> >> >> >> Merci ! >> >> >> >> Best regards, >> >> Fabrice
FE
Fabrice Etanchaud5 May 2014 09:11 #
Dear Christian, That would be great ! In order to allow for parameters, do you think one could declare external variables before the commands element ? Is it to say that a command file could be any xquery script generateding xml ? Best regards, Fabrice -----Message d'origine-----
Quoted text · Christian Grün · 116 lines
De : Christian Grün [mailto:christian.gruen at gmail.com] Envoyé : dimanche 4 mai 2014 22:08 À : Fabrice Etanchaud Cc : basex-talk at mailman.uni-konstanz.de Objet : Re: [basex-talk] apply variable bindings to command scripts Hi Fabrice, I'm still hesitant to introduce more features to the command script syntax, as all of them will be BaseX-specific. But we could interpret all input as XQuery and execute the resulting XML as BaseX commands. This way, we could write things like.. <commands>{ for $n in 1 to 10 return <create-db name='db{ $n }'/> }</commands> What do you think? Christian On Mon, Apr 14, 2014 at 11:44 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Fabrice, > > I've recorded your feature request in a new issue: > > https://github.com/BaseXdb/basex/issues/929 > > Christian > > > > On Fri, Apr 11, 2014 at 3:57 PM, Fabrice Etanchaud > <fetanchaud at questel.com> wrote: >> Dear all, >> >> >> >> Currently, in order to obtain tailored command scripts, I found the >> following solution : >> >> >> >> A template test.bxs file : >> >> >> >> <commands> >> >> <open name='${DBNAME}'/> >> >> <xquery> >> >> <![CDATA[ >> >> (/document)[1] >> >> ]]> >> >> </xquery> >> >> <close/> >> >> </commands> >> >> >> >> A bash script test.sh: >> >> >> >> #!/bin/bash >> >> >> >> DBNAME=de-dpma-u-meta >> >> >> >> eval "cat <<EOF >> >> $(<$1) >> >> EOF >> >> " | basex -c- >> >> >> >> And then call : >> >> >> >> ./test.sh test.bxs >> >> >> >> >> >> Could it be possible for the variable bindings to be applied also to >> script commands, >> >> So basex -bDBNAME=de-dpma-u-meta test.bxs >> >> does the whole job ? >> >> >> >> that would work also for commands' sequences like : >> >> <set option='bindings'>..... >> >> <execute> or <run> >> >> >> >> Merci ! >> >> >> >> Best regards, >> >> Fabrice
CG
Christian Grün7 May 2014 11:49 #
Hi Fabrice,
Quoted text · Fabrice Etanchaud · 2 lines
> In order to allow for parameters, do you think one could declare external variables before the commands element ? > Is it to say that a command file could be any xquery script generateding xml ?
Exactly; your command file will be evaluated the same as any other XQuery expression. The main challenge will be to detect if the command script contains command strings or an XQuery expression. In some cases, there is no unique way to do that. For example, the following script... "info" is both a valid BaseX command and an XQuery expression. Currently, the input is evaluated as XML command script when the input starts with "<". Cheers, Christian
CG
Christian Grün26 May 2014 00:45 #
Hi Fabrice, due to the ambiguities that would be caused by executing all command scripts as XQuery, we decided to close Issue 929 [1]. However, some good news: if you experience a little with the existing features of BaseX, you will see that command scripts can easily be created via XQuery and executed on the fly. An example: Command-line call: basex -b max=3 create-bxs.xq.xq | basex -c - File create-bxs.xq:
  declare variable $max external;
  <commands>{
    for $n in 1 to $max
    return <create-db name='db{ $n }'/>
  }</commands>
Hope this helps, Christian [1] https://github.com/BaseXdb/basex/issues/929
Quoted text · Christian Grün · 22 lines
On Wed, May 7, 2014 at 11:49 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Fabrice, > >> In order to allow for parameters, do you think one could declare external variables before the commands element ? >> Is it to say that a command file could be any xquery script generateding xml ? > > Exactly; your command file will be evaluated the same as any other > XQuery expression. > > The main challenge will be to detect if the command script contains > command strings or an XQuery expression. In some cases, there is no > unique way to do that. For example, the following script... > > "info" > > is both a valid BaseX command and an XQuery expression. Currently, the > input is evaluated as XML command script when the input starts with > "<". > > Cheers, > Christian

⚡Generated with XQuery