Binding a sequence to an external variable?

Monday, 17 December 2012 · 3 messages · last reply 18 Dec 2012
JK
Johannes Krampf17 Dec 2012 13:23 #
Hello, I would like to bind a sequence of xs:string to an external variable. I've tried various ways and after trying to read the source and the spec I fear that it might not be possible. First of all the code: Inside the xquery:
declare variable $mysequence as xs:string* external;
On the Java side:
ClientQuery clientQuery = clientSession.query(query);
clientQuery.bind(parameter, values.get(parameter));
I tried to give the type "xs:string*" as a third parameter to clientQuery.bind, but I got the error message "org.basex.core.BaseXException: [XPST0003] Unknown type 'xs:string*'", so this is not the way to do it. I furthermore tried to pass a string array as a parameter, but the variable got the value of the output of the toString method. When I tried with a list of Strings, I got again the output of the toString method. What I want is something like the following:
let $mysequence := ("Hello", "world")
but using sequence values transmitted from the java application using an external variable. Is there any way to achieve this? The goal is to test for membership in the sequence, i.e. allowing the parametrize the query using a variable number of possible values. Thanks for your assistance, Johannes
CG
Christian Grün18 Dec 2012 01:19 #
Hi Johannes, sorry for the late feedback. – As you already indicated, our bindings don’t support sequence types. One of the reasons is that our client API is designed to be implementable in different languages. You could think about joining all your strings and bind them as a single strings, and then split the string via fn:tokenize(). Of course, this requires that the used string separator (which can be any Unicode character) does not occur in the input strings. You could also have a look at XQJ [1], which provides the XQExpression.bindSequence() function [2]. Hope this helps, Christian [1] http://xqj.net/basex/ [2] http://www.cfoster.net/articles/xqj-tutorial/xml-schema.xml
Quoted text · Johannes Krampf · 48 lines
On Mon, Dec 17, 2012 at 1:23 PM, Johannes Krampf <johannes.krampf at hevs.ch> wrote: > Hello, > > I would like to bind a sequence of xs:string to an external variable. I've > tried various ways and after trying to read the source and the spec I fear > that it might not be possible. > > First of all the code: > > Inside the xquery: > > declare variable $mysequence as xs:string* external; > > On the Java side: > > ClientQuery clientQuery = clientSession.query(query); > clientQuery.bind(parameter, values.get(parameter)); > > I tried to give the type "xs:string*" as a third parameter to > clientQuery.bind, but I got the error message > "org.basex.core.BaseXException: [XPST0003] Unknown type 'xs:string*'", so > this is not the way to do it. > > I furthermore tried to pass a string array as a parameter, but the variable > got the value of the output of the toString method. When I tried with a list > of Strings, I got again the output of the toString method. > > What I want is something like the following: > > let $mysequence := ("Hello", "world") > > but using sequence values transmitted from the java application using an > external variable. Is there any way to achieve this? > > The goal is to test for membership in the sequence, i.e. allowing the > parametrize the query using a variable number of possible values. > > Thanks for your assistance, > > Johannes > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
JK
Johannes Krampf18 Dec 2012 11:37 #
Hi Christian, thanks a lot for your (in my opinion very fast) answer! I went the XQJ route and assigning sequences to variables works flawlessly. For future reference a code sketch of what is needed:
XQPreparedExpression xqPreparedExpression =
xqConnection.prepareExpression(myQuery);
XQSequence xqSequence = xqConnection.createSequence(myIterable.iterator());
xqPreparedExpression.bindSequence(new QName(myParameter), xqSequence);
Keep up the good work on BaseX! - Johannes
Quoted text · Christian Grün · 70 lines
On 12/18/2012 01:19 AM, Christian Grün wrote: > Hi Johannes, > > sorry for the late feedback. – As you already indicated, our bindings > don’t support sequence types. One of the reasons is that our client > API is designed to be implementable in different languages. > > You could think about joining all your strings and bind them as a > single strings, and then split the string via fn:tokenize(). Of > course, this requires that the used string separator (which can be any > Unicode character) does not occur in the input strings. > > You could also have a look at XQJ [1], which provides the > XQExpression.bindSequence() function [2]. > > Hope this helps, > Christian > > [1] http://xqj.net/basex/ > [2] http://www.cfoster.net/articles/xqj-tutorial/xml-schema.xml > ___________________________ > > On Mon, Dec 17, 2012 at 1:23 PM, Johannes Krampf > <johannes.krampf at hevs.ch> wrote: >> Hello, >> >> I would like to bind a sequence of xs:string to an external variable. I've >> tried various ways and after trying to read the source and the spec I fear >> that it might not be possible. >> >> First of all the code: >> >> Inside the xquery: >> >> declare variable $mysequence as xs:string* external; >> >> On the Java side: >> >> ClientQuery clientQuery = clientSession.query(query); >> clientQuery.bind(parameter, values.get(parameter)); >> >> I tried to give the type "xs:string*" as a third parameter to >> clientQuery.bind, but I got the error message >> "org.basex.core.BaseXException: [XPST0003] Unknown type 'xs:string*'", so >> this is not the way to do it. >> >> I furthermore tried to pass a string array as a parameter, but the variable >> got the value of the output of the toString method. When I tried with a list >> of Strings, I got again the output of the toString method. >> >> What I want is something like the following: >> >> let $mysequence := ("Hello", "world") >> >> but using sequence values transmitted from the java application using an >> external variable. Is there any way to achieve this? >> >> The goal is to test for membership in the sequence, i.e. allowing the >> parametrize the query using a variable number of possible values. >> >> Thanks for your assistance, >> >> Johannes >> >> >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>

⚡Generated with XQuery