sending variables to xquery module via client api (python)
Monday, 16 November 2015 · 9 messages · last reply 17 Nov 2015
CB
Cholfin, Bryan16 Nov 2015 23:08 #
Hi-
Hoping someone can help me with this. I'm trying to write a python script that calls an xquery module in the database. It seems to be pretty easy to use a line such as:
session.execute("run gettext.xqm")
and get back the response I want. What I want to do is pass a bound variable to the module. The client api has a provision to bind a variable to a query object, but I'm not making a query object. I'm simply executing the stored query. I don't find anything in the documentation to suggest that a variable can be added to the run command this way.
Bryan Cholfin
Associate Editor for Digital Projects and Metadata
Harvard University Press
617.496.9116
79 Garden Street | Cambridge, MA 02138-1400
www.hup.harvard.edu<http://www.hup.harvard.edu/>
EF
Etanchaud Fabrice17 Nov 2015 09:08 #
Hi Bryan,
Could http://docs.basex.org/wiki/Options#BINDINGS give you a solution ?
Best regards,
Fabrice
Quoted text · Cholfin, Bryan · 14 lines
De : basex-talk-bounces at mailman.uni-konstanz.de [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de Cholfin, Bryan Envoyé : lundi 16 novembre 2015 23:08 À : basex-talk at mailman.uni-konstanz.de Objet : [basex-talk] sending variables to xquery module via client api (python) Hi- Hoping someone can help me with this. I'm trying to write a python script that calls an xquery module in the database. It seems to be pretty easy to use a line such as: session.execute("run gettext.xqm") and get back the response I want. What I want to do is pass a bound variable to the module. The client api has a provision to bind a variable to a query object, but I'm not making a query object. I'm simply executing the stored query. I don't find anything in the documentation to suggest that a variable can be added to the run command this way. Bryan Cholfin Associate Editor for Digital Projects and Metadata Harvard University Press 617.496.9116 79 Garden Street | Cambridge, MA 02138-1400 www.hup.harvard.edu<http://www.hup.harvard.edu/>
CB
Cholfin, Bryan17 Nov 2015 19:16 #
That almost works. It appears I can pass the variable by executing the 'set bindings' command ahead of the query. But if I use the variable in a test like this:
declare variable $ext_variable as xs:string external;
for $div in collection('waldo')//div[@xml:id=$ext_variable]I get nothing. And yet I've been able to return the variable itself from the module and check its type, and use it in a let assignment. So I can see that the module is receiving the value I send, it just isn't matching for some reason.
Bryan Cholfin
Associate Editor for Digital Projects and Metadata
Harvard University Press
617.496.9116
79 Garden Street | Cambridge, MA 02138-1400
www.hup.harvard.edu<http://www.hup.harvard.edu/>
Quoted text · Etanchaud Fabrice · 22 lines
From: Etanchaud Fabrice <Fabrice.Etanchaud at horanet.com<mailto:Fabrice.Etanchaud at horanet.com>> Date: Tuesday, November 17, 2015 at 4:08 AM To: "Cholfin, Bryan" <bryan_cholfin at harvard.edu<mailto:bryan_cholfin at harvard.edu>>, "basex-talk at mailman.uni-konstanz.de<mailto:basex-talk at mailman.uni-konstanz.de>" <basex-talk at mailman.uni-konstanz.de<mailto:basex-talk at mailman.uni-konstanz.de>> Subject: RE: [basex-talk] sending variables to xquery module via client api (python) Hi Bryan, Could http://docs.basex.org/wiki/Options#BINDINGS<https://urldefense.proofpoint.com/v2/url?u=http-3A__docs.basex.org_wiki_Options-23BINDINGS&d=CwMFAw&c=WO-RGvefibhHBZq3fL85hQ&r=C4uQXgUAXNtbbQkRcZb0vaWguMqZEgRZCutfoNwnQQw&m=-AZnTfqEvRN4z1HbMindlhvsaxlJlHG659XcUZIt8gs&s=SpD3uzuuWn2uibxXkTFXu4Wm7x01rF-GiozkwuutTeA&e=>give you a solution ? Best regards, Fabrice De : basex-talk-bounces at mailman.uni-konstanz.de<mailto:basex-talk-bounces at mailman.uni-konstanz.de> [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de Cholfin, Bryan Envoyé : lundi 16 novembre 2015 23:08 À : basex-talk at mailman.uni-konstanz.de<mailto:basex-talk at mailman.uni-konstanz.de> Objet : [basex-talk] sending variables to xquery module via client api (python) Hi- Hoping someone can help me with this. I'm trying to write a python script that calls an xquery module in the database. It seems to be pretty easy to use a line such as: session.execute("run gettext.xqm") and get back the response I want. What I want to do is pass a bound variable to the module. The client api has a provision to bind a variable to a query object, but I'm not making a query object. I'm simply executing the stored query. I don't find anything in the documentation to suggest that a variable can be added to the run command this way. Bryan Cholfin Associate Editor for Digital Projects and Metadata Harvard University Press 617.496.9116 79 Garden Street | Cambridge, MA 02138-1400 www.hup.harvard.edu<http://www.hup.harvard.edu/>
CG
Christian Grün17 Nov 2015 19:19 #
Quoted text · Cholfin, Bryan · 2 lines
> declare variable $ext_variable as xs:string external; > for $div in collection(‘waldo’)//div[@xml:id=$ext_variable]
What is output on server STDOUT if you trace the variable?..
declare variable $ext_variable as xs:string external;
for $div in collection(‘waldo’)//div[@xml:id=trace($ext_variable)]Quoted text · Cholfin, Bryan · 75 lines
> > I get nothing. And yet I’ve been able to return the variable itself from the > module and check its type, and use it in a let assignment. So I can see that > the module is receiving the value I send, it just isn’t matching for some > reason. > > Bryan Cholfin > > Associate Editor for Digital Projects and Metadata > Harvard University Press > 617.496.9116 > 79 Garden Street | Cambridge, MA 02138-1400 > www.hup.harvard.edu > > > From: Etanchaud Fabrice <Fabrice.Etanchaud at horanet.com> > Date: Tuesday, November 17, 2015 at 4:08 AM > To: "Cholfin, Bryan" <bryan_cholfin at harvard.edu>, > "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> > Subject: RE: [basex-talk] sending variables to xquery module via client api > (python) > > Hi Bryan, > > > > Could http://docs.basex.org/wiki/Options#BINDINGSgive you a solution ? > > > > Best regards, > > Fabrice > > > > De : basex-talk-bounces at mailman.uni-konstanz.de > [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de Cholfin, > Bryan > Envoyé : lundi 16 novembre 2015 23:08 > À : basex-talk at mailman.uni-konstanz.de > Objet : [basex-talk] sending variables to xquery module via client api > (python) > > > > Hi— > > > > Hoping someone can help me with this. I’m trying to write a python script > that calls an xquery module in the database. It seems to be pretty easy to > use a line such as: > > > > session.execute(“run gettext.xqm”) > > > > and get back the response I want. What I want to do is pass a bound variable > to the module. The client api has a provision to bind a variable to a query > object, but I’m not making a query object. I’m simply executing the stored > query. I don’t find anything in the documentation to suggest that a > variable can be added to the run command this way. > > > > Bryan Cholfin > > Associate Editor for Digital Projects and Metadata > Harvard University Press > 617.496.9116 > 79 Garden Street | Cambridge, MA 02138-1400 > www.hup.harvard.edu
CB
Cholfin, Bryan17 Nov 2015 19:56 #
I get this:
13:50:53.282 127.0.0.1:39813 admin REQUEST SET
BINDINGS
journal_id='hc2' 1.02 ms
13:50:53.282 127.0.0.1:39813 admin OK BINDINGS: journal_id='hc2' 0.11 ms 13:50:53.284 127.0.0.1:39813 admin REQUEST RUN
/home/bryan/basex/webapp/waldo/waldotext.xqm 1.86 ms
13:50:53.287 127.0.0.1:39813 admin OK Query "waldotext.xqm" executed in 3.2 ms. 3.63 ms
13:50:53.288 127.0.0.1:39813 admin REQUEST EXIT 0.16 ms
13:50:53.288 127.0.0.1:39813 admin OK 0.09 ms
When I run the module from the gui and set the variable manually, it works as I expect.
Bryan Cholfin
Associate Editor for Digital Projects and Metadata
Harvard University Press
617.496.9116
79 Garden Street | Cambridge, MA 02138-1400
www.hup.harvard.edu <http://www.hup.harvard.edu/>Quoted text · Christian Grün · 96 lines
On 11/17/15, 1:19 PM, "Christian Grün" <christian.gruen at gmail.com> wrote: >> declare variable $ext_variable as xs:string external; >> for $div in collection(Œwaldo¹)//div[@xml:id=$ext_variable] > >What is output on server STDOUT if you trace the variable?.. > > declare variable $ext_variable as xs:string external; > for $div in collection(Œwaldo¹)//div[@xml:id=trace($ext_variable)] > > >> >> I get nothing. And yet I¹ve been able to return the variable itself >>from the >> module and check its type, and use it in a let assignment. So I can see >>that >> the module is receiving the value I send, it just isn¹t matching for >>some >> reason. >> >> Bryan Cholfin >> >> Associate Editor for Digital Projects and Metadata >> Harvard University Press >> 617.496.9116 >> 79 Garden Street | Cambridge, MA 02138-1400 >> www.hup.harvard.edu >> >> >> From: Etanchaud Fabrice <Fabrice.Etanchaud at horanet.com> >> Date: Tuesday, November 17, 2015 at 4:08 AM >> To: "Cholfin, Bryan" <bryan_cholfin at harvard.edu>, >> "basex-talk at mailman.uni-konstanz.de" >><basex-talk at mailman.uni-konstanz.de> >> Subject: RE: [basex-talk] sending variables to xquery module via client >>api >> (python) >> >> Hi Bryan, >> >> >> >> Could http://docs.basex.org/wiki/Options#BINDINGSgive you a solution ? >> >> >> >> Best regards, >> >> Fabrice >> >> >> >> De : basex-talk-bounces at mailman.uni-konstanz.de >> [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de >>Cholfin, >> Bryan >> Envoyé : lundi 16 novembre 2015 23:08 >> À : basex-talk at mailman.uni-konstanz.de >> Objet : [basex-talk] sending variables to xquery module via client api >> (python) >> >> >> >> Hi‹ >> >> >> >> Hoping someone can help me with this. I¹m trying to write a python >>script >> that calls an xquery module in the database. It seems to be pretty easy >>to >> use a line such as: >> >> >> >> session.execute(³run gettext.xqm²) >> >> >> >> and get back the response I want. What I want to do is pass a bound >>variable >> to the module. The client api has a provision to bind a variable to a >>query >> object, but I¹m not making a query object. I¹m simply executing the >>stored >> query. I don¹t find anything in the documentation to suggest that a >> variable can be added to the run command this way. >> >> >> >> Bryan Cholfin >> >> Associate Editor for Digital Projects and Metadata >> Harvard University Press >> 617.496.9116 >> 79 Garden Street | Cambridge, MA 02138-1400 >> www.hup.harvard.edu
CG
Christian Grün17 Nov 2015 19:59 #
Quoted text · Cholfin, Bryan · 2 lines
> I get this: > [...]
This looks like the output that’s stored in the database logs, while trace output is written to STDERR (not STDOUT, as I wrote in my last response, sorry). Do you see anything there?
Quoted text · Cholfin, Bryan · 123 lines
> 13:50:53.282 127.0.0.1:39813 admin REQUEST SET BINDINGS > journal_id='hc2' 1.02 ms > 13:50:53.282 127.0.0.1:39813 admin OK BINDINGS: journal_id='hc2' 0.11 ms > 13:50:53.284 127.0.0.1:39813 admin REQUEST RUN > /home/bryan/basex/webapp/waldo/waldotext.xqm 1.86 ms > 13:50:53.287 127.0.0.1:39813 admin OK Query "waldotext.xqm" executed in > 3.2 ms. 3.63 ms > 13:50:53.288 127.0.0.1:39813 admin REQUEST EXIT 0.16 ms > 13:50:53.288 127.0.0.1:39813 admin OK 0.09 ms > > > When I run the module from the gui and set the variable manually, it works > as I expect. > > > Bryan Cholfin > Associate Editor for Digital Projects and Metadata > Harvard University Press > 617.496.9116 > 79 Garden Street | Cambridge, MA 02138-1400 > www.hup.harvard.edu <http://www.hup.harvard.edu/> > > > > > On 11/17/15, 1:19 PM, "Christian Grün" <christian.gruen at gmail.com> wrote: > >>> declare variable $ext_variable as xs:string external; >>> for $div in collection(Œwaldo¹)//div[@xml:id=$ext_variable] >> >>What is output on server STDOUT if you trace the variable?.. >> >> declare variable $ext_variable as xs:string external; >> for $div in collection(Œwaldo¹)//div[@xml:id=trace($ext_variable)] >> >> >>> >>> I get nothing. And yet I¹ve been able to return the variable itself >>>from the >>> module and check its type, and use it in a let assignment. So I can see >>>that >>> the module is receiving the value I send, it just isn¹t matching for >>>some >>> reason. >>> >>> Bryan Cholfin >>> >>> Associate Editor for Digital Projects and Metadata >>> Harvard University Press >>> 617.496.9116 >>> 79 Garden Street | Cambridge, MA 02138-1400 >>> www.hup.harvard.edu >>> >>> >>> From: Etanchaud Fabrice <Fabrice.Etanchaud at horanet.com> >>> Date: Tuesday, November 17, 2015 at 4:08 AM >>> To: "Cholfin, Bryan" <bryan_cholfin at harvard.edu>, >>> "basex-talk at mailman.uni-konstanz.de" >>><basex-talk at mailman.uni-konstanz.de> >>> Subject: RE: [basex-talk] sending variables to xquery module via client >>>api >>> (python) >>> >>> Hi Bryan, >>> >>> >>> >>> Could http://docs.basex.org/wiki/Options#BINDINGSgive you a solution ? >>> >>> >>> >>> Best regards, >>> >>> Fabrice >>> >>> >>> >>> De : basex-talk-bounces at mailman.uni-konstanz.de >>> [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de >>>Cholfin, >>> Bryan >>> Envoyé : lundi 16 novembre 2015 23:08 >>> À : basex-talk at mailman.uni-konstanz.de >>> Objet : [basex-talk] sending variables to xquery module via client api >>> (python) >>> >>> >>> >>> Hi‹ >>> >>> >>> >>> Hoping someone can help me with this. I¹m trying to write a python >>>script >>> that calls an xquery module in the database. It seems to be pretty easy >>>to >>> use a line such as: >>> >>> >>> >>> session.execute(³run gettext.xqm²) >>> >>> >>> >>> and get back the response I want. What I want to do is pass a bound >>>variable >>> to the module. The client api has a provision to bind a variable to a >>>query >>> object, but I¹m not making a query object. I¹m simply executing the >>>stored >>> query. I don¹t find anything in the documentation to suggest that a >>> variable can be added to the run command this way. >>> >>> >>> >>> Bryan Cholfin >>> >>> Associate Editor for Digital Projects and Metadata >>> Harvard University Press >>> 617.496.9116 >>> 79 Garden Street | Cambridge, MA 02138-1400 >>> www.hup.harvard.edu >
CB
Cholfin, Bryan17 Nov 2015 20:27 #
No—trace doesn’t seem to send anything to stderr. (I even forced a couple of errors just to make sure stderr was going where I thought it was).
Bryan Cholfin
Associate Editor for Digital Projects and Metadata
Harvard University Press
617.496.9116
79 Garden Street | Cambridge, MA 02138-1400
www.hup.harvard.edu <http://www.hup.harvard.edu/>
Quoted text · Christian Grün · 141 lines
On 11/17/15, 1:59 PM, "Christian Grün" <christian.gruen at gmail.com> wrote: >> I get this: >> [...] > >This looks like the output that’s stored in the database logs, while >trace output is written to STDERR (not STDOUT, as I wrote in my last >response, sorry). Do you see anything there? > > > > >> 13:50:53.282 127.0.0.1:39813 admin REQUEST SET BINDINGS >> journal_id='hc2' 1.02 ms >> 13:50:53.282 127.0.0.1:39813 admin OK BINDINGS: >>journal_id='hc2' 0.11 ms >> 13:50:53.284 127.0.0.1:39813 admin REQUEST RUN >> /home/bryan/basex/webapp/waldo/waldotext.xqm 1.86 ms >> 13:50:53.287 127.0.0.1:39813 admin OK Query "waldotext.xqm" >>executed in >> 3.2 ms. 3.63 ms >> 13:50:53.288 127.0.0.1:39813 admin REQUEST EXIT 0.16 ms >> 13:50:53.288 127.0.0.1:39813 admin OK 0.09 ms >> >> >> When I run the module from the gui and set the variable manually, it >>works >> as I expect. >> >> >> Bryan Cholfin >> Associate Editor for Digital Projects and Metadata >> Harvard University Press >> 617.496.9116 >> 79 Garden Street | Cambridge, MA 02138-1400 >> www.hup.harvard.edu <http://www.hup.harvard.edu/> >> >> >> >> >> On 11/17/15, 1:19 PM, "Christian Grün" <christian.gruen at gmail.com> >>wrote: >> >>>> declare variable $ext_variable as xs:string external; >>>> for $div in collection(Œwaldo¹)//div[@xml:id=$ext_variable] >>> >>>What is output on server STDOUT if you trace the variable?.. >>> >>> declare variable $ext_variable as xs:string external; >>> for $div in collection(Œwaldo¹)//div[@xml:id=trace($ext_variable)] >>> >>> >>>> >>>> I get nothing. And yet I¹ve been able to return the variable itself >>>>from the >>>> module and check its type, and use it in a let assignment. So I can >>>>see >>>>that >>>> the module is receiving the value I send, it just isn¹t matching for >>>>some >>>> reason. >>>> >>>> Bryan Cholfin >>>> >>>> Associate Editor for Digital Projects and Metadata >>>> Harvard University Press >>>> 617.496.9116 >>>> 79 Garden Street | Cambridge, MA 02138-1400 >>>> www.hup.harvard.edu >>>> >>>> >>>> From: Etanchaud Fabrice <Fabrice.Etanchaud at horanet.com> >>>> Date: Tuesday, November 17, 2015 at 4:08 AM >>>> To: "Cholfin, Bryan" <bryan_cholfin at harvard.edu>, >>>> "basex-talk at mailman.uni-konstanz.de" >>>><basex-talk at mailman.uni-konstanz.de> >>>> Subject: RE: [basex-talk] sending variables to xquery module via >>>>client >>>>api >>>> (python) >>>> >>>> Hi Bryan, >>>> >>>> >>>> >>>> Could http://docs.basex.org/wiki/Options#BINDINGSgive you a solution ? >>>> >>>> >>>> >>>> Best regards, >>>> >>>> Fabrice >>>> >>>> >>>> >>>> De : basex-talk-bounces at mailman.uni-konstanz.de >>>> [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de >>>>Cholfin, >>>> Bryan >>>> Envoyé : lundi 16 novembre 2015 23:08 >>>> À : basex-talk at mailman.uni-konstanz.de >>>> Objet : [basex-talk] sending variables to xquery module via client api >>>> (python) >>>> >>>> >>>> >>>> Hi‹ >>>> >>>> >>>> >>>> Hoping someone can help me with this. I¹m trying to write a python >>>>script >>>> that calls an xquery module in the database. It seems to be pretty >>>>easy >>>>to >>>> use a line such as: >>>> >>>> >>>> >>>> session.execute(³run gettext.xqm²) >>>> >>>> >>>> >>>> and get back the response I want. What I want to do is pass a bound >>>>variable >>>> to the module. The client api has a provision to bind a variable to a >>>>query >>>> object, but I¹m not making a query object. I¹m simply executing the >>>>stored >>>> query. I don¹t find anything in the documentation to suggest that a >>>> variable can be added to the run command this way. >>>> >>>> >>>> >>>> Bryan Cholfin >>>> >>>> Associate Editor for Digital Projects and Metadata >>>> Harvard University Press >>>> 617.496.9116 >>>> 79 Garden Street | Cambridge, MA 02138-1400 >>>> www.hup.harvard.edu >>
CG
Christian Grün17 Nov 2015 20:29 #
Quoted text · Cholfin, Bryan · 2 lines
> No—trace doesn’t seem to send anything to stderr. (I even forced a couple > of errors just to make sure stderr was going where I thought it was).
This would indicate that the predicate is never evaluated.
How does your full query look like? Do you get output when running the query on command-line?..
basex -b ext_variable=xyz query.xq
Quoted text · Cholfin, Bryan · 155 lines
> > > Bryan Cholfin > Associate Editor for Digital Projects and Metadata > Harvard University Press > 617.496.9116 > 79 Garden Street | Cambridge, MA 02138-1400 > www.hup.harvard.edu <http://www.hup.harvard.edu/> > > > > > On 11/17/15, 1:59 PM, "Christian Grün" <christian.gruen at gmail.com> wrote: > >>> I get this: >>> [...] >> >>This looks like the output that’s stored in the database logs, while >>trace output is written to STDERR (not STDOUT, as I wrote in my last >>response, sorry). Do you see anything there? >> >> >> >> >>> 13:50:53.282 127.0.0.1:39813 admin REQUEST SET BINDINGS >>> journal_id='hc2' 1.02 ms >>> 13:50:53.282 127.0.0.1:39813 admin OK BINDINGS: >>>journal_id='hc2' 0.11 ms >>> 13:50:53.284 127.0.0.1:39813 admin REQUEST RUN >>> /home/bryan/basex/webapp/waldo/waldotext.xqm 1.86 ms >>> 13:50:53.287 127.0.0.1:39813 admin OK Query "waldotext.xqm" >>>executed in >>> 3.2 ms. 3.63 ms >>> 13:50:53.288 127.0.0.1:39813 admin REQUEST EXIT 0.16 ms >>> 13:50:53.288 127.0.0.1:39813 admin OK 0.09 ms >>> >>> >>> When I run the module from the gui and set the variable manually, it >>>works >>> as I expect. >>> >>> >>> Bryan Cholfin >>> Associate Editor for Digital Projects and Metadata >>> Harvard University Press >>> 617.496.9116 >>> 79 Garden Street | Cambridge, MA 02138-1400 >>> www.hup.harvard.edu <http://www.hup.harvard.edu/> >>> >>> >>> >>> >>> On 11/17/15, 1:19 PM, "Christian Grün" <christian.gruen at gmail.com> >>>wrote: >>> >>>>> declare variable $ext_variable as xs:string external; >>>>> for $div in collection(Œwaldo¹)//div[@xml:id=$ext_variable] >>>> >>>>What is output on server STDOUT if you trace the variable?.. >>>> >>>> declare variable $ext_variable as xs:string external; >>>> for $div in collection(Œwaldo¹)//div[@xml:id=trace($ext_variable)] >>>> >>>> >>>>> >>>>> I get nothing. And yet I¹ve been able to return the variable itself >>>>>from the >>>>> module and check its type, and use it in a let assignment. So I can >>>>>see >>>>>that >>>>> the module is receiving the value I send, it just isn¹t matching for >>>>>some >>>>> reason. >>>>> >>>>> Bryan Cholfin >>>>> >>>>> Associate Editor for Digital Projects and Metadata >>>>> Harvard University Press >>>>> 617.496.9116 >>>>> 79 Garden Street | Cambridge, MA 02138-1400 >>>>> www.hup.harvard.edu >>>>> >>>>> >>>>> From: Etanchaud Fabrice <Fabrice.Etanchaud at horanet.com> >>>>> Date: Tuesday, November 17, 2015 at 4:08 AM >>>>> To: "Cholfin, Bryan" <bryan_cholfin at harvard.edu>, >>>>> "basex-talk at mailman.uni-konstanz.de" >>>>><basex-talk at mailman.uni-konstanz.de> >>>>> Subject: RE: [basex-talk] sending variables to xquery module via >>>>>client >>>>>api >>>>> (python) >>>>> >>>>> Hi Bryan, >>>>> >>>>> >>>>> >>>>> Could http://docs.basex.org/wiki/Options#BINDINGSgive you a solution ? >>>>> >>>>> >>>>> >>>>> Best regards, >>>>> >>>>> Fabrice >>>>> >>>>> >>>>> >>>>> De : basex-talk-bounces at mailman.uni-konstanz.de >>>>> [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de >>>>>Cholfin, >>>>> Bryan >>>>> Envoyé : lundi 16 novembre 2015 23:08 >>>>> À : basex-talk at mailman.uni-konstanz.de >>>>> Objet : [basex-talk] sending variables to xquery module via client api >>>>> (python) >>>>> >>>>> >>>>> >>>>> Hi‹ >>>>> >>>>> >>>>> >>>>> Hoping someone can help me with this. I¹m trying to write a python >>>>>script >>>>> that calls an xquery module in the database. It seems to be pretty >>>>>easy >>>>>to >>>>> use a line such as: >>>>> >>>>> >>>>> >>>>> session.execute(³run gettext.xqm²) >>>>> >>>>> >>>>> >>>>> and get back the response I want. What I want to do is pass a bound >>>>>variable >>>>> to the module. The client api has a provision to bind a variable to a >>>>>query >>>>> object, but I¹m not making a query object. I¹m simply executing the >>>>>stored >>>>> query. I don¹t find anything in the documentation to suggest that a >>>>> variable can be added to the run command this way. >>>>> >>>>> >>>>> >>>>> Bryan Cholfin >>>>> >>>>> Associate Editor for Digital Projects and Metadata >>>>> Harvard University Press >>>>> 617.496.9116 >>>>> 79 Garden Street | Cambridge, MA 02138-1400 >>>>> www.hup.harvard.edu >>> >
CB
Cholfin, Bryan17 Nov 2015 21:03 #
Yes, that worked—but I think I solved the problem (I wouldn’t have seen it except for trying this, though). And of course it is trivial:
I had originally:
session.execute(“SET
BINDINGS journal_id=‘hc2’”)
because I was following the example in the wiki. Changing that to:
session.execute(“SET BINDINGS journal_id=hc2”)
worked. Of course, assigning a variable and composing the command string by concatenation also works, so I shot myself in the foot by thinking I could just use a fixed string to test.
So thanks for the advice—it helped.
Bryan Cholfin
Associate Editor for Digital Projects and Metadata
Harvard University Press
617.496.9116
79 Garden Street | Cambridge, MA 02138-1400
www.hup.harvard.edu <http://www.hup.harvard.edu/>Quoted text · Christian Grün · 175 lines
On 11/17/15, 2:29 PM, "Christian Grün" <christian.gruen at gmail.com> wrote: >> No—trace doesn’t seem to send anything to stderr. (I even forced a >>couple >> of errors just to make sure stderr was going where I thought it was). > >This would indicate that the predicate is never evaluated. > >How does your full query look like? Do you get output when running the >query on command-line?.. > > basex -b ext_variable=xyz query.xq > > > > > >> >> >> Bryan Cholfin >> Associate Editor for Digital Projects and Metadata >> Harvard University Press >> 617.496.9116 >> 79 Garden Street | Cambridge, MA 02138-1400 >> www.hup.harvard.edu <http://www.hup.harvard.edu/> >> >> >> >> >> On 11/17/15, 1:59 PM, "Christian Grün" <christian.gruen at gmail.com> >>wrote: >> >>>> I get this: >>>> [...] >>> >>>This looks like the output that’s stored in the database logs, while >>>trace output is written to STDERR (not STDOUT, as I wrote in my last >>>response, sorry). Do you see anything there? >>> >>> >>> >>> >>>> 13:50:53.282 127.0.0.1:39813 admin REQUEST SET BINDINGS >>>> journal_id='hc2' 1.02 ms >>>> 13:50:53.282 127.0.0.1:39813 admin OK BINDINGS: >>>>journal_id='hc2' 0.11 ms >>>> 13:50:53.284 127.0.0.1:39813 admin REQUEST RUN >>>> /home/bryan/basex/webapp/waldo/waldotext.xqm 1.86 ms >>>> 13:50:53.287 127.0.0.1:39813 admin OK Query "waldotext.xqm" >>>>executed in >>>> 3.2 ms. 3.63 ms >>>> 13:50:53.288 127.0.0.1:39813 admin REQUEST EXIT 0.16 ms >>>> 13:50:53.288 127.0.0.1:39813 admin OK 0.09 ms >>>> >>>> >>>> When I run the module from the gui and set the variable manually, it >>>>works >>>> as I expect. >>>> >>>> >>>> Bryan Cholfin >>>> Associate Editor for Digital Projects and Metadata >>>> Harvard University Press >>>> 617.496.9116 >>>> 79 Garden Street | Cambridge, MA 02138-1400 >>>> www.hup.harvard.edu <http://www.hup.harvard.edu/> >>>> >>>> >>>> >>>> >>>> On 11/17/15, 1:19 PM, "Christian Grün" <christian.gruen at gmail.com> >>>>wrote: >>>> >>>>>> declare variable $ext_variable as xs:string external; >>>>>> for $div in collection(Œwaldo¹)//div[@xml:id=$ext_variable] >>>>> >>>>>What is output on server STDOUT if you trace the variable?.. >>>>> >>>>> declare variable $ext_variable as xs:string external; >>>>> for $div in collection(Œwaldo¹)//div[@xml:id=trace($ext_variable)] >>>>> >>>>> >>>>>> >>>>>> I get nothing. And yet I¹ve been able to return the variable itself >>>>>>from the >>>>>> module and check its type, and use it in a let assignment. So I can >>>>>>see >>>>>>that >>>>>> the module is receiving the value I send, it just isn¹t matching for >>>>>>some >>>>>> reason. >>>>>> >>>>>> Bryan Cholfin >>>>>> >>>>>> Associate Editor for Digital Projects and Metadata >>>>>> Harvard University Press >>>>>> 617.496.9116 >>>>>> 79 Garden Street | Cambridge, MA 02138-1400 >>>>>> www.hup.harvard.edu >>>>>> >>>>>> >>>>>> From: Etanchaud Fabrice <Fabrice.Etanchaud at horanet.com> >>>>>> Date: Tuesday, November 17, 2015 at 4:08 AM >>>>>> To: "Cholfin, Bryan" <bryan_cholfin at harvard.edu>, >>>>>> "basex-talk at mailman.uni-konstanz.de" >>>>>><basex-talk at mailman.uni-konstanz.de> >>>>>> Subject: RE: [basex-talk] sending variables to xquery module via >>>>>>client >>>>>>api >>>>>> (python) >>>>>> >>>>>> Hi Bryan, >>>>>> >>>>>> >>>>>> >>>>>> Could http://docs.basex.org/wiki/Options#BINDINGSgive you a >>>>>>solution ? >>>>>> >>>>>> >>>>>> >>>>>> Best regards, >>>>>> >>>>>> Fabrice >>>>>> >>>>>> >>>>>> >>>>>> De : basex-talk-bounces at mailman.uni-konstanz.de >>>>>> [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de >>>>>>Cholfin, >>>>>> Bryan >>>>>> Envoyé : lundi 16 novembre 2015 23:08 >>>>>> À : basex-talk at mailman.uni-konstanz.de >>>>>> Objet : [basex-talk] sending variables to xquery module via client >>>>>>api >>>>>> (python) >>>>>> >>>>>> >>>>>> >>>>>> Hi‹ >>>>>> >>>>>> >>>>>> >>>>>> Hoping someone can help me with this. I¹m trying to write a python >>>>>>script >>>>>> that calls an xquery module in the database. It seems to be pretty >>>>>>easy >>>>>>to >>>>>> use a line such as: >>>>>> >>>>>> >>>>>> >>>>>> session.execute(³run gettext.xqm²) >>>>>> >>>>>> >>>>>> >>>>>> and get back the response I want. What I want to do is pass a bound >>>>>>variable >>>>>> to the module. The client api has a provision to bind a variable to >>>>>>a >>>>>>query >>>>>> object, but I¹m not making a query object. I¹m simply executing the >>>>>>stored >>>>>> query. I don¹t find anything in the documentation to suggest that a >>>>>> variable can be added to the run command this way. >>>>>> >>>>>> >>>>>> >>>>>> Bryan Cholfin >>>>>> >>>>>> Associate Editor for Digital Projects and Metadata >>>>>> Harvard University Press >>>>>> 617.496.9116 >>>>>> 79 Garden Street | Cambridge, MA 02138-1400 >>>>>> www.hup.harvard.edu >>>> >>
Written for BaseX 8.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery