Simple query
Thursday, 9 March 2017 · 20 messages · last reply 11 Mar 2017
AW
Aaron Weber9 Mar 2017 01:30 #
Newbie alert.
I'm trying to get my feet wet with BaseX, and in doing so, am trying to understand XQuery and how to apply it to a database full of documents (not just a single document that is typically queried).
I am using Java and can post my code, but with a LocalSession, and a query, the following produces 0 results.
For $doc in collection() return $doc
I realize there's no "where", and in the sql world that would match all. Maybe not in XQuery?
Obviously just a test query, but I need to start somewhere. :-)
Thanks for any help!
--
AJ
MS
Michael Seiferle9 Mar 2017 09:02 #
Hi Aaron,
welcome to the list!
For BaseX to „open“ a collection you need to address it by URI; in your case no URI is present, so BaseX loads the „default collection“ which is set to the currently opened database (I guess you have none open :—)):
So usually you want to address your collection by name:
Quoted text · Aaron Weber · 3 lines
> for $foo in collection(‚myFoos‘) > … > return $foo
Where each $foo resembles a document inside your collection. In BaseX a collection usually resembles a database, so your first step would be:
- Create a database that either is a single document or contains multiple documents
So in SQL lingo I’d say you are basically missing your FROM ‚…‘ :-)
A good read might be: http://docs.basex.org/wiki/Databases <http://docs.basex.org/wiki/Databases> it shows the various ways of creating, returning and querying documents / collections :-)
Best
Michael
Quoted text · Aaron Weber · 17 lines
> Am 09.03.2017 um 00:30 schrieb Aaron Weber <aweber at comcast.net>: > > Newbie alert. > > I'm trying to get my feet wet with BaseX, and in doing so, am trying to understand XQuery and how to apply it to a database full of documents (not just a single document that is typically queried). > > I am using Java and can post my code, but with a LocalSession, and a query, the following produces 0 results. > > For $doc in collection() return $doc > > I realize there's no "where", and in the sql world that would match all. Maybe not in XQuery? > > Obviously just a test query, but I need to start somewhere. :-) > > Thanks for any help! > -- > AJ
--
Michael Seiferle, BaseX GmbH, http://www.basexgmbh.de
|-- Firmensitz: Blarerstrasse 56, 78462 Konstanz
|-- Registergericht Freiburg, HRB: 708285, Geschäftsführer:
| Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Fon: +49 7531 916 82 77
FE
Hello Aaron,
You would learn faster by using the BaseXGUI application,
You will benefit from syntax highlighting, real time execution, and hits on function signatures.
Best regards,
Fabrice
Quoted text · Aaron Weber · 13 lines
De : basex-talk-bounces at mailman.uni-konstanz.de [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de Aaron Weber Envoyé : jeudi 9 mars 2017 00:31 À : basex-talk at mailman.uni-konstanz.de Objet : [basex-talk] Simple query Newbie alert. I'm trying to get my feet wet with BaseX, and in doing so, am trying to understand XQuery and how to apply it to a database full of documents (not just a single document that is typically queried). I am using Java and can post my code, but with a LocalSession, and a query, the following produces 0 results. For $doc in collection() return $doc I realize there's no "where", and in the sql world that would match all. Maybe not in XQuery? Obviously just a test query, but I need to start somewhere. :-) Thanks for any help! -- AJ
AW
Sorry for the delayed response...
I was aware of the empty collection and default (but maybe not clear on it)...
This query works:
String myXQueryString ="for $doc in collection() where matches(document-uri($doc), '" + DocID +
"') return $doc";return (new XQuery(myXQueryString).execute(context));
Note that it too uses an empty collection clause, but always returns a document. So why do I need to specify a collection in this case? (It also confirms that I do have some documents stored in the database to actually query.)
-AJ
Quoted text · Michael Seiferle · 64 lines
On 3/9/2017 3:02 AM, Michael Seiferle wrote: > Hi Aaron, > > welcome to the list! > > For BaseX to „open“ a collection you need to address it by URI; in > your case no URI is present, so BaseX loads the „default collection“ > which is set to the currently opened database (I guess you have none > open :—)): > > > So usually you want to address your collection by name: >> for $foo in collection(‚myFoos‘) >> … >> return $foo > > Where each $foo resembles a document inside your collection. > In BaseX a collection usually resembles a database, so your first step > would be: > > - Create a database that either is a single document or contains > multiple documents > > So in SQL lingo I’d say you are basically missing your FROM ‚…‘ :-) > > A good read might be: http://docs.basex.org/wiki/Databases it shows > the various ways of creating, returning and querying documents / > collections :-) > > > > Best > Michael >> Am 09.03.2017 um 00:30 schrieb Aaron Weber <aweber at comcast.net >> <mailto:aweber at comcast.net>>: >> >> Newbie alert. >> >> I'm trying to get my feet wet with BaseX, and in doing so, am trying >> to understand XQuery and how to apply it to a database full of >> documents (not just a single document that is typically queried). >> >> I am using Java and can post my code, but with a LocalSession, and a >> query, the following produces 0 results. >> >> For $doc in collection() return $doc >> >> I realize there's no "where", and in the sql world that would match >> all. Maybe not in XQuery? >> >> Obviously just a test query, but I need to start somewhere. :-) >> >> Thanks for any help! >> -- >> AJ > > > -- > Michael Seiferle, BaseX GmbH, http://www.basexgmbh.de > |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz > |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: > | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle > `-- Fon: +49 7531 916 82 77 >
AW
Quoted text · Fabrice ETANCHAUD · 9 lines
On 3/9/2017 3:46 AM, Fabrice ETANCHAUD wrote: > > Hello Aaron, > > You would learn faster by using the BaseXGUI application, > > You will benefit from syntax highlighting, real time execution, and > hits on function signatures. >
I am trying the GUI now. It is an excellent tool!
However, issuing the same exact XQuery in the GUI returns 3 documents (which is what I would have originally expected).
Maybe it is an issue with how I setup my query in java? Here is my code:
try (LocalSession session = new LocalSession(this.context)) {
//test
try (Query q = session.query("for $doc in collection()
return $doc")) {
while (q.more()) {
LOG.debug("RESULT: " + q.next());
}
}
}
catch (Exception e) {
LOG.error("Could not execute query " + statement, e);
}Quoted text · Fabrice ETANCHAUD · 31 lines
> 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* > Aaron Weber > *Envoyé :* jeudi 9 mars 2017 00:31 > *À :* basex-talk at mailman.uni-konstanz.de > *Objet :* [basex-talk] Simple query > > Newbie alert. > > I'm trying to get my feet wet with BaseX, and in doing so, am trying > to understand XQuery and how to apply it to a database full of > documents (not just a single document that is typically queried). > > I am using Java and can post my code, but with a LocalSession, and a > query, the following produces 0 results. > > For $doc in collection() return $doc > > I realize there's no "where", and in the sql world that would match > all. Maybe not in XQuery? > > Obviously just a test query, but I need to start somewhere. :-) > > Thanks for any help! > -- > AJ >
KS
Kendall Shaw10 Mar 2017 20:24 #
Michael Seiferle gave the answer already, I think. What would collection() be referring to? How would BaseX know what to return? Probably there is no database specified. Presumably, in the GUI you have opened a database.
Kendall
Quoted text · AJ Weber · 37 lines
From: <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ Weber <aweber at comcast.net> Date: Friday, March 10, 2017 at 6:44 AM To: Fabrice ETANCHAUD <fetanchaud at groupefbo.com>, "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> Subject: Re: [basex-talk] Simple query On 3/9/2017 3:46 AM, Fabrice ETANCHAUD wrote: Hello Aaron, You would learn faster by using the BaseXGUI application, You will benefit from syntax highlighting, real time execution, and hits on function signatures. I am trying the GUI now. It is an excellent tool! However, issuing the same exact XQuery in the GUI returns 3 documents (which is what I would have originally expected). Maybe it is an issue with how I setup my query in java? Here is my code: try (LocalSession session = new LocalSession(this.context)) { //test try (Query q = session.query("for $doc in collection() return $doc")) { while (q.more()) { LOG.debug("RESULT: " + q.next()); } } } catch (Exception e) { LOG.error("Could not execute query " + statement, e); } 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 Aaron Weber Envoyé : jeudi 9 mars 2017 00:31 À : basex-talk at mailman.uni-konstanz.de<mailto:basex-talk at mailman.uni-konstanz.de> Objet : [basex-talk] Simple query Newbie alert. I'm trying to get my feet wet with BaseX, and in doing so, am trying to understand XQuery and how to apply it to a database full of documents (not just a single document that is typically queried). I am using Java and can post my code, but with a LocalSession, and a query, the following produces 0 results. For $doc in collection() return $doc I realize there's no "where", and in the sql world that would match all. Maybe not in XQuery? Obviously just a test query, but I need to start somewhere. :-) Thanks for any help! -- AJ
AW
AJ Weber10 Mar 2017 21:42 #
Quoted text · Kendall Shaw · 7 lines
On 3/10/2017 2:24 PM, Kendall Shaw wrote: > > Michael Seiferle gave the answer already, I think. What would > collection() be referring to? How would BaseX know what to return? > Probably there is no database specified. Presumably, in the GUI you > have opened a database. >
Yes, I did not include my code to open the database. There is a database open and this does not throw an exception, it just returns no results.
In my constructor of this class there is the following code: new Check(this.MyID).execute(context);
(MyID is a String identifying the database I want to work with exclusively with this context passed.)
As I mentioned in a separate post, my query where matches(uri...) works fine...every time. That query also does not have a specific collection in the query.
Quoted text · Kendall Shaw · 75 lines
> Kendall > > *From: *<basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ > Weber <aweber at comcast.net> > *Date: *Friday, March 10, 2017 at 6:44 AM > *To: *Fabrice ETANCHAUD <fetanchaud at groupefbo.com>, > "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> > *Subject: *Re: [basex-talk] Simple query > > On 3/9/2017 3:46 AM, Fabrice ETANCHAUD wrote: > > Hello Aaron, > > You would learn faster by using the BaseXGUI application, > > You will benefit from syntax highlighting, real time execution, > and hits on function signatures. > > I am trying the GUI now. It is an excellent tool! > > However, issuing the same exact XQuery in the GUI returns 3 documents > (which is what I would have originally expected). > > Maybe it is an issue with how I setup my query in java? Here is my code: > > try (LocalSession session = new LocalSession(this.context)) { > //test > > try (Query q = session.query("for $doc in collection() > return $doc")) { > while (q.more()) { > LOG.debug("RESULT: " + q.next()); > } > } > } > catch (Exception e) { > LOG.error("Could not execute query " + statement, e); > } > > > 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* Aaron Weber > *Envoyé :* jeudi 9 mars 2017 00:31 > *À :* basex-talk at mailman.uni-konstanz.de > <mailto:basex-talk at mailman.uni-konstanz.de> > *Objet :* [basex-talk] Simple query > > Newbie alert. > > I'm trying to get my feet wet with BaseX, and in doing so, am > trying to understand XQuery and how to apply it to a database full > of documents (not just a single document that is typically queried). > > I am using Java and can post my code, but with a LocalSession, and > a query, the following produces 0 results. > > For $doc in collection() return $doc > > I realize there's no "where", and in the sql world that would > match all. Maybe not in XQuery? > > Obviously just a test query, but I need to start somewhere. :-) > > Thanks for any help! > -- > AJ > > >
KS
Kendall Shaw10 Mar 2017 22:18 #
This worked for me, where “test-local” contains a document:
Context context = new Context();
LocalSession s = new LocalSession(context);
s.execute(new Check("test-local"));
try (Query q = s.query("for $doc in collection() return $doc")) {
while (q.more()) {
System.out.println(q.next());
}
}But, why your code isn’t working could be useful to know. It seems like there are some details left out.
Kendall
Quoted text · AJ Weber · 49 lines
From: <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ Weber <aweber at comcast.net> Date: Friday, March 10, 2017 at 11:40 AM To: "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> Subject: Re: [basex-talk] Simple query On 3/10/2017 2:24 PM, Kendall Shaw wrote: Michael Seiferle gave the answer already, I think. What would collection() be referring to? How would BaseX know what to return? Probably there is no database specified. Presumably, in the GUI you have opened a database. Yes, I did not include my code to open the database. There is a database open and this does not throw an exception, it just returns no results. In my constructor of this class there is the following code: new Check(this.MyID).execute(context); (MyID is a String identifying the database I want to work with exclusively with this context passed.) As I mentioned in a separate post, my query where matches(uri...) works fine...every time. That query also does not have a specific collection in the query. Kendall From: <basex-talk-bounces at mailman.uni-konstanz.de><mailto:basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ Weber <aweber at comcast.net><mailto:aweber at comcast.net> Date: Friday, March 10, 2017 at 6:44 AM To: Fabrice ETANCHAUD <fetanchaud at groupefbo.com><mailto:fetanchaud at groupefbo.com>, "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] Simple query On 3/9/2017 3:46 AM, Fabrice ETANCHAUD wrote: Hello Aaron, You would learn faster by using the BaseXGUI application, You will benefit from syntax highlighting, real time execution, and hits on function signatures. I am trying the GUI now. It is an excellent tool! However, issuing the same exact XQuery in the GUI returns 3 documents (which is what I would have originally expected). Maybe it is an issue with how I setup my query in java? Here is my code: try (LocalSession session = new LocalSession(this.context)) { //test try (Query q = session.query("for $doc in collection() return $doc")) { while (q.more()) { LOG.debug("RESULT: " + q.next()); } } } catch (Exception e) { LOG.error("Could not execute query " + statement, e); } 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 Aaron Weber Envoyé : jeudi 9 mars 2017 00:31 À : basex-talk at mailman.uni-konstanz.de<mailto:basex-talk at mailman.uni-konstanz.de> Objet : [basex-talk] Simple query Newbie alert. I'm trying to get my feet wet with BaseX, and in doing so, am trying to understand XQuery and how to apply it to a database full of documents (not just a single document that is typically queried). I am using Java and can post my code, but with a LocalSession, and a query, the following produces 0 results. For $doc in collection() return $doc I realize there's no "where", and in the sql world that would match all. Maybe not in XQuery? Obviously just a test query, but I need to start somewhere. :-) Thanks for any help! -- AJ
KS
Looking at the basex source code, LocalSession.close also does context.closeDB(). So, I think you only need LocalSession.close or the try block does it for you in your example.
Kendall
Quoted text · AJ Weber · 74 lines
From: <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ Weber <aweber at comcast.net> Date: Friday, March 10, 2017 at 1:47 PM To: "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> Subject: Re: [basex-talk] Simple query OK, changing this so that the code flows like yours works much, much better. I now return all 3 documents I expect are in the database. FOLLOW-UP Question: How do I close the database properly with these classes? I had been doing a context.closeDB() when shutting-down. Do I just do a localSession.close() now? Or do I need to do both? Thanks again!!! On 3/10/2017 4:27 PM, AJ Weber wrote: Well, one difference I spot is that I am opening (via the snippet I sent before) the database BEFORE creating a LocalSession and I am using the new Check(...).execute(context); The "context" is kept in the object's class-level. Your code creates the context, associates the new LocalSession with the context, and THEN opens the existing database. (That's more akin to how a JDBC session would go...but I did not see any java examples with this, I followed the examples on the java page and only found LocalSession via a google search.) There doesn't appear to be any details in the javadoc or anything I can find regarding how to use LocalSession, so I could be off base from that pov. -AJ On 3/10/2017 4:18 PM, Kendall Shaw wrote: This worked for me, where “test-local” contains a document: Context context = new Context(); LocalSession s = new LocalSession(context); s.execute(new Check("test-local")); try (Query q = s.query("for $doc in collection() return $doc")) { while (q.more()) { System.out.println(q.next()); } } But, why your code isn’t working could be useful to know. It seems like there are some details left out. Kendall From: <basex-talk-bounces at mailman.uni-konstanz.de><mailto:basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ Weber <aweber at comcast.net><mailto:aweber at comcast.net> Date: Friday, March 10, 2017 at 11:40 AM To: "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] Simple query On 3/10/2017 2:24 PM, Kendall Shaw wrote: Michael Seiferle gave the answer already, I think. What would collection() be referring to? How would BaseX know what to return? Probably there is no database specified. Presumably, in the GUI you have opened a database. Yes, I did not include my code to open the database. There is a database open and this does not throw an exception, it just returns no results. In my constructor of this class there is the following code: new Check(this.MyID).execute(context); (MyID is a String identifying the database I want to work with exclusively with this context passed.) As I mentioned in a separate post, my query where matches(uri...) works fine...every time. That query also does not have a specific collection in the query. Kendall From: <basex-talk-bounces at mailman.uni-konstanz.de><mailto:basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ Weber <aweber at comcast.net><mailto:aweber at comcast.net> Date: Friday, March 10, 2017 at 6:44 AM To: Fabrice ETANCHAUD <fetanchaud at groupefbo.com><mailto:fetanchaud at groupefbo.com>, "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] Simple query On 3/9/2017 3:46 AM, Fabrice ETANCHAUD wrote: Hello Aaron, You would learn faster by using the BaseXGUI application, You will benefit from syntax highlighting, real time execution, and hits on function signatures. I am trying the GUI now. It is an excellent tool! However, issuing the same exact XQuery in the GUI returns 3 documents (which is what I would have originally expected). Maybe it is an issue with how I setup my query in java? Here is my code: try (LocalSession session = new LocalSession(this.context)) { //test try (Query q = session.query("for $doc in collection() return $doc")) { while (q.more()) { LOG.debug("RESULT: " + q.next()); } } } catch (Exception e) { LOG.error("Could not execute query " + statement, e); } 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 Aaron Weber Envoyé : jeudi 9 mars 2017 00:31 À : basex-talk at mailman.uni-konstanz.de<mailto:basex-talk at mailman.uni-konstanz.de> Objet : [basex-talk] Simple query Newbie alert. I'm trying to get my feet wet with BaseX, and in doing so, am trying to understand XQuery and how to apply it to a database full of documents (not just a single document that is typically queried). I am using Java and can post my code, but with a LocalSession, and a query, the following produces 0 results. For $doc in collection() return $doc I realize there's no "where", and in the sql world that would match all. Maybe not in XQuery? Obviously just a test query, but I need to start somewhere. :-) Thanks for any help! -- AJ
AW
Well, one difference I spot is that I am opening (via the snippet I sent before) the database BEFORE creating a LocalSession and I am using the new Check(...).execute(context);
The "context" is kept in the object's class-level.
Your code creates the context, associates the new LocalSession with the context, and THEN opens the existing database. (That's more akin to how a JDBC session would go...but I did not see any java examples with this, I followed the examples on the java page and only found LocalSession via a google search.)
There doesn't appear to be any details in the javadoc or anything I can find regarding how to use LocalSession, so I could be off base from that pov.
-AJ
Quoted text · Kendall Shaw · 140 lines
On 3/10/2017 4:18 PM, Kendall Shaw wrote: > > This worked for me, where “test-local” contains a document: > > Context context = new Context(); > > LocalSession s = new LocalSession(context); > > s.execute(new Check("test-local")); > > try (Query q = s.query("for $doc in collection() return $doc")) { > > while (q.more()) { > > System.out.println(q.next()_);_ > > } > > } > > But, why your code isn’t working could be useful to know. It seems > like there are some details left out. > > Kendall > > *From: *<basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ > Weber <aweber at comcast.net> > *Date: *Friday, March 10, 2017 at 11:40 AM > *To: *"basex-talk at mailman.uni-konstanz.de" > <basex-talk at mailman.uni-konstanz.de> > *Subject: *Re: [basex-talk] Simple query > > On 3/10/2017 2:24 PM, Kendall Shaw wrote: > > Michael Seiferle gave the answer already, I think. What would > collection() be referring to? How would BaseX know what to return? > Probably there is no database specified. Presumably, in the GUI > you have opened a database. > > Yes, I did not include my code to open the database. There is a > database open and this does not throw an exception, it just returns no > results. > > In my constructor of this class there is the following code: > new Check(this.MyID).execute(context); > > (MyID is a String identifying the database I want to work with > exclusively with this context passed.) > > As I mentioned in a separate post, my query where matches(uri...) > works fine...every time. That query also does not have a specific > collection in the query. > > > Kendall > > *From: *<basex-talk-bounces at mailman.uni-konstanz.de> > <mailto:basex-talk-bounces at mailman.uni-konstanz.de> on behalf of > AJ Weber <aweber at comcast.net> <mailto:aweber at comcast.net> > *Date: *Friday, March 10, 2017 at 6:44 AM > *To: *Fabrice ETANCHAUD <fetanchaud at groupefbo.com> > <mailto:fetanchaud at groupefbo.com>, > "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] Simple query > > On 3/9/2017 3:46 AM, Fabrice ETANCHAUD wrote: > > Hello Aaron, > > You would learn faster by using the BaseXGUI application, > > You will benefit from syntax highlighting, real time > execution, and hits on function signatures. > > I am trying the GUI now. It is an excellent tool! > > However, issuing the same exact XQuery in the GUI returns 3 > documents (which is what I would have originally expected). > > Maybe it is an issue with how I setup my query in java? Here is my > code: > > try (LocalSession session = new LocalSession(this.context)) { > //test > > try (Query q = session.query("for $doc in collection() > return $doc")) { > while (q.more()) { > LOG.debug("RESULT: " + q.next()); > } > } > } > catch (Exception e) { > LOG.error("Could not execute query " + statement, e); > } > > > > 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* Aaron Weber > *Envoyé :* jeudi 9 mars 2017 00:31 > *À :* basex-talk at mailman.uni-konstanz.de > <mailto:basex-talk at mailman.uni-konstanz.de> > *Objet :* [basex-talk] Simple query > > Newbie alert. > > I'm trying to get my feet wet with BaseX, and in doing so, am > trying to understand XQuery and how to apply it to a database > full of documents (not just a single document that is > typically queried). > > I am using Java and can post my code, but with a LocalSession, > and a query, the following produces 0 results. > > For $doc in collection() return $doc > > I realize there's no "where", and in the sql world that would > match all. Maybe not in XQuery? > > Obviously just a test query, but I need to start somewhere. :-) > > Thanks for any help! > -- > AJ > > > > > >
AW
AJ Weber10 Mar 2017 23:49 #
OK, changing this so that the code flows like yours works much, much better. I now return all 3 documents I expect are in the database.
FOLLOW-UP Question: How do I close the database properly with these classes? I had been doing a context.closeDB() when shutting-down. Do I just do a localSession.close() now? Or do I need to do both?
Thanks again!!!
Quoted text · AJ Weber · 162 lines
On 3/10/2017 4:27 PM, AJ Weber wrote: > > Well, one difference I spot is that I am opening (via the snippet I > sent before) the database BEFORE creating a LocalSession and I am > using the new Check(...).execute(context); > > The "context" is kept in the object's class-level. > > Your code creates the context, associates the new LocalSession with > the context, and THEN opens the existing database. (That's more akin > to how a JDBC session would go...but I did not see any java examples > with this, I followed the examples on the java page and only found > LocalSession via a google search.) > > There doesn't appear to be any details in the javadoc or anything I > can find regarding how to use LocalSession, so I could be off base > from that pov. > > -AJ > > > On 3/10/2017 4:18 PM, Kendall Shaw wrote: >> >> This worked for me, where “test-local” contains a document: >> >> Context context = new Context(); >> >> LocalSession s = new LocalSession(context); >> >> s.execute(new Check("test-local")); >> >> try (Query q = s.query("for $doc in collection() return $doc")) { >> >> while (q.more()) { >> >> System.out.println(q.next()_);_ >> >> } >> >> } >> >> But, why your code isn’t working could be useful to know. It seems >> like there are some details left out. >> >> Kendall >> >> *From: *<basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ >> Weber <aweber at comcast.net> >> *Date: *Friday, March 10, 2017 at 11:40 AM >> *To: *"basex-talk at mailman.uni-konstanz.de" >> <basex-talk at mailman.uni-konstanz.de> >> *Subject: *Re: [basex-talk] Simple query >> >> On 3/10/2017 2:24 PM, Kendall Shaw wrote: >> >> Michael Seiferle gave the answer already, I think. What would >> collection() be referring to? How would BaseX know what to >> return? Probably there is no database specified. Presumably, in >> the GUI you have opened a database. >> >> Yes, I did not include my code to open the database. There is a >> database open and this does not throw an exception, it just returns >> no results. >> >> In my constructor of this class there is the following code: >> new Check(this.MyID).execute(context); >> >> (MyID is a String identifying the database I want to work with >> exclusively with this context passed.) >> >> As I mentioned in a separate post, my query where matches(uri...) >> works fine...every time. That query also does not have a specific >> collection in the query. >> >> >> Kendall >> >> *From: *<basex-talk-bounces at mailman.uni-konstanz.de> >> <mailto:basex-talk-bounces at mailman.uni-konstanz.de> on behalf of >> AJ Weber <aweber at comcast.net> <mailto:aweber at comcast.net> >> *Date: *Friday, March 10, 2017 at 6:44 AM >> *To: *Fabrice ETANCHAUD <fetanchaud at groupefbo.com> >> <mailto:fetanchaud at groupefbo.com>, >> "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] Simple query >> >> On 3/9/2017 3:46 AM, Fabrice ETANCHAUD wrote: >> >> Hello Aaron, >> >> You would learn faster by using the BaseXGUI application, >> >> You will benefit from syntax highlighting, real time >> execution, and hits on function signatures. >> >> I am trying the GUI now. It is an excellent tool! >> >> However, issuing the same exact XQuery in the GUI returns 3 >> documents (which is what I would have originally expected). >> >> Maybe it is an issue with how I setup my query in java? Here is >> my code: >> >> try (LocalSession session = new LocalSession(this.context)) { >> //test >> >> try (Query q = session.query("for $doc in >> collection() return $doc")) { >> while (q.more()) { >> LOG.debug("RESULT: " + q.next()); >> } >> } >> } >> catch (Exception e) { >> LOG.error("Could not execute query " + statement, e); >> } >> >> >> >> 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* Aaron Weber >> *Envoyé :* jeudi 9 mars 2017 00:31 >> *À :* basex-talk at mailman.uni-konstanz.de >> <mailto:basex-talk at mailman.uni-konstanz.de> >> *Objet :* [basex-talk] Simple query >> >> Newbie alert. >> >> I'm trying to get my feet wet with BaseX, and in doing so, am >> trying to understand XQuery and how to apply it to a database >> full of documents (not just a single document that is >> typically queried). >> >> I am using Java and can post my code, but with a >> LocalSession, and a query, the following produces 0 results. >> >> For $doc in collection() return $doc >> >> I realize there's no "where", and in the sql world that would >> match all. Maybe not in XQuery? >> >> Obviously just a test query, but I need to start somewhere. :-) >> >> Thanks for any help! >> -- >> AJ >> >> >> >> >> >> >
CG
Christian Grün11 Mar 2017 17:07 #
Dear Aaron (and thanks Kendall),
A little addendum: If you use Java’s try-with-resources statement…
try (LocalSession session = new LocalSession(this.context))
…there will be no need to manually close your connection.
Best,
Christian
Quoted text · AJ Weber · 191 lines
On Fri, Mar 10, 2017 at 10:47 PM, AJ Weber <aweber at comcast.net> wrote: > OK, changing this so that the code flows like yours works much, much better. > I now return all 3 documents I expect are in the database. > > FOLLOW-UP Question: How do I close the database properly with these > classes? I had been doing a context.closeDB() when shutting-down. Do I > just do a localSession.close() now? Or do I need to do both? > > Thanks again!!! > > > > On 3/10/2017 4:27 PM, AJ Weber wrote: > > Well, one difference I spot is that I am opening (via the snippet I sent > before) the database BEFORE creating a LocalSession and I am using the new > Check(...).execute(context); > > The "context" is kept in the object's class-level. > > Your code creates the context, associates the new LocalSession with the > context, and THEN opens the existing database. (That's more akin to how a > JDBC session would go...but I did not see any java examples with this, I > followed the examples on the java page and only found LocalSession via a > google search.) > > There doesn't appear to be any details in the javadoc or anything I can find > regarding how to use LocalSession, so I could be off base from that pov. > > -AJ > > > On 3/10/2017 4:18 PM, Kendall Shaw wrote: > > This worked for me, where “test-local” contains a document: > > > > Context context = new Context(); > > LocalSession s = new LocalSession(context); > > s.execute(new Check("test-local")); > > try (Query q = s.query("for $doc in collection() return $doc")) { > > while (q.more()) { > > System.out.println(q.next()); > > } > > } > > > > But, why your code isn’t working could be useful to know. It seems like > there are some details left out. > > > > Kendall > > > > From: <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ Weber > <aweber at comcast.net> > Date: Friday, March 10, 2017 at 11:40 AM > To: "basex-talk at mailman.uni-konstanz.de" > <basex-talk at mailman.uni-konstanz.de> > Subject: Re: [basex-talk] Simple query > > > > > > On 3/10/2017 2:24 PM, Kendall Shaw wrote: > > Michael Seiferle gave the answer already, I think. What would collection() > be referring to? How would BaseX know what to return? Probably there is no > database specified. Presumably, in the GUI you have opened a database. > > Yes, I did not include my code to open the database. There is a database > open and this does not throw an exception, it just returns no results. > > In my constructor of this class there is the following code: > new Check(this.MyID).execute(context); > > (MyID is a String identifying the database I want to work with exclusively > with this context passed.) > > As I mentioned in a separate post, my query where matches(uri...) works > fine...every time. That query also does not have a specific collection in > the query. > > > > > Kendall > > > > > > From: <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ Weber > <aweber at comcast.net> > Date: Friday, March 10, 2017 at 6:44 AM > To: Fabrice ETANCHAUD <fetanchaud at groupefbo.com>, > "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> > Subject: Re: [basex-talk] Simple query > > > > On 3/9/2017 3:46 AM, Fabrice ETANCHAUD wrote: > > Hello Aaron, > > > > You would learn faster by using the BaseXGUI application, > > You will benefit from syntax highlighting, real time execution, and hits on > function signatures. > > I am trying the GUI now. It is an excellent tool! > > However, issuing the same exact XQuery in the GUI returns 3 documents (which > is what I would have originally expected). > > Maybe it is an issue with how I setup my query in java? Here is my code: > > try (LocalSession session = new LocalSession(this.context)) { > //test > > try (Query q = session.query("for $doc in collection() return > $doc")) { > while (q.more()) { > LOG.debug("RESULT: " + q.next()); > } > } > } > catch (Exception e) { > LOG.error("Could not execute query " + statement, e); > } > > > > > > 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 Aaron > Weber > Envoyé : jeudi 9 mars 2017 00:31 > À : basex-talk at mailman.uni-konstanz.de > Objet : [basex-talk] Simple query > > > > Newbie alert. > > I'm trying to get my feet wet with BaseX, and in doing so, am trying to > understand XQuery and how to apply it to a database full of documents (not > just a single document that is typically queried). > > I am using Java and can post my code, but with a LocalSession, and a query, > the following produces 0 results. > > For $doc in collection() return $doc > > I realize there's no "where", and in the sql world that would match all. > Maybe not in XQuery? > > Obviously just a test query, but I need to start somewhere. :-) > > Thanks for any help! > -- > AJ > > > > > > > >
CG
Quoted text · Aaron Weber · 4 lines
> I was going to open the local session and keep it open for the lifetime of > the webapp like I would do with a JDBC session object. That would not allow > me to use the autoclose. Is it possible or recommended to keep the one > session object like that?
Absolutely. BaseX sessions are pretty light-weight, but if you want to repeatedly access a database/collection (as you did), and avoid reopening it every time, it can make sense to keep sessions open.
Quoted text · Aaron Weber · 227 lines
> On March 11, 2017 11:07:31 AM EST, "Christian Grün" > <christian.gruen at gmail.com> wrote: >> >> Dear Aaron (and thanks Kendall), >> >> A little addendum: If you use Java’s try-with-resources statement… >> >> try (LocalSession session = new LocalSession(this.context)) >> >> …there will be no need to manually close your connection. >> >> Best, >> Christian >> >> >> >> On Fri, Mar 10, 2017 at 10:47 PM, AJ Weber <aweber at comcast.net> wrote: >>> >>> OK, changing this so that the code flows like yours works much, much >>> better. >>> I now return all 3 documents I expect are in the database. >>> >>> FOLLOW-UP Question: How do I close the database properly with these >>> classes? I had been doing a context.closeDB() when shutting-down. Do I >>> just do a localSession.close() now? Or do I need to do both? >>> >>> Thanks again!!! >>> >>> >>> >>> On 3/10/2017 4:27 PM, AJ Weber wrote: >>> >>> Well, one difference I spot is that I am opening (via the snippet I sent >>> before) the database BEFORE creating a LocalSession and I am using the >>> new >>> Check(...).execute(context); >>> >>> The "context" is kept in the object's class-level. >>> >>> Your code creates the context, associates the new LocalSession with the >>> context, and THEN opens the existing database. (That's more akin to how >>> a >>> JDBC session would go...but I did not see any java examples with this, I >>> followed the examples on the java page and only found LocalSession via a >>> google search.) >>> >>> There doesn't appear to be any details in the javadoc or anything I can >>> find >>> regarding how to use LocalSession, so I could be off base from that pov. >>> >>> -AJ >>> >>> >>> On 3/10/2017 4:18 PM, Kendall Shaw wrote: >>> >>> This worked for me, where “test-local” contains a document: >>> >>> >>> >>> Context context = new Context(); >>> >>> LocalSession s = new LocalSession(context); >>> >>> s.execute(new Check("test-local")); >>> >>> try (Query q = s.query("for $doc in collection() return $doc")) >>> { >>> >>> while (q.more()) { >>> >>> System.out.println(q.next()); >>> >>> } >>> >>> } >>> >>> >>> >>> But, why your code isn’t working could be useful to know. It seems like >>> there are some details left out. >>> >>> >>> >>> Kendall >>> >>> >>> >>> From: <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ Weber >>> <aweber at comcast.net> >>> Date: Friday, March 10, 2017 at 11:40 AM >>> To: "basex-talk at mailman.uni-konstanz.de" >>> <basex-talk at mailman.uni-konstanz.de> >>> Subject: Re: [basex-talk] Simple query >>> >>> >>> >>> >>> >>> On 3/10/2017 2:24 PM, Kendall Shaw wrote: >>> >>> Michael Seiferle gave the answer already, I think. What would >>> collection() >>> be referring to? How would BaseX know what to return? Probably there is >>> no >>> database specified. Presumably, in the GUI you have opened a database. >>> >>> Yes, I did not include my code to open the database. There is a >>> database >>> open and this does not throw an exception, it just returns no results. >>> >>> In my constructor of this class there is the following code: >>> new Check(this.MyID).execute(context); >>> >>> (MyID is a String identifying the database I want to work with >>> exclusively >>> with this context passed.) >>> >>> As I mentioned in a separate post, my query where matches(uri...) works >>> fine...every time. That query also does not have a specific collection >>> in >>> the query. >>> >>> >>> >>> >>> Kendall >>> >>> >>> >>> >>> >>> From: <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ Weber >>> <aweber at comcast.net> >>> Date: Friday, March 10, 2017 at 6:44 AM >>> To: Fabrice ETANCHAUD <fetanchaud at groupefbo.com>, >>> "basex-talk at mailman.uni-konstanz.de" >>> <basex-talk at mailman.uni-konstanz.de> >>> Subject: Re: [basex-talk] Simple query >>> >>> >>> >>> On 3/9/2017 3:46 AM, Fabrice ETANCHAUD wrote: >>> >>> Hello Aaron, >>> >>> >>> >>> You would learn faster by using the BaseXGUI application, >>> >>> You will benefit from syntax highlighting, real time execution, and hits >>> on >>> function signatures. >>> >>> I am trying the GUI now. It is an excellent tool! >>> >>> However, issuing the same exact XQuery in the GUI returns 3 documents >>> (which >>> is what I would have originally expected). >>> >>> Maybe it is an issue with how I setup my query in java? Here is my >>> code: >>> >>> try (LocalSession session = new LocalSession(this.context)) { >>> //test >>> >>> try (Query q = session.query("for $doc in collection() >>> return >>> $doc")) { >>> while (q.more()) { >>> LOG.debug("RESULT: " + q.next()); >>> } >>> } >>> } >>> catch (Exception e) { >>> LOG.error("Could not execute query " + statement, e); >>> } >>> >>> >>> >>> >>> >>> 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 Aaron >>> Weber >>> Envoyé : jeudi 9 mars 2017 00:31 >>> À : basex-talk at mailman.uni-konstanz.de >>> Objet : [basex-talk] Simple query >>> >>> >>> >>> Newbie alert. >>> >>> I'm trying to get my feet wet with BaseX, and in doing so, am trying to >>> understand XQuery and how to apply it to a database full of documents >>> (not >>> just a single document that is typically queried). >>> >>> I am using Java and can post my code, but with a LocalSession, and a >>> query, >>> the following produces 0 results. >>> >>> For $doc in collection() return $doc >>> >>> I realize there's no "where", and in the sql world that would match all. >>> Maybe not in XQuery? >>> >>> Obviously just a test query, but I need to start somewhere. :-) >>> >>> Thanks for any help! >>> -- >>> AJ >> >> >> >> >> >> >> >> >> >
AW
Understand that, thank you for the follow up.
I was going to open the local session and keep it open for the lifetime of the webapp like I would do with a JDBC session object. That would not allow me to use the autoclose. Is it possible or recommended to keep the one session object like that?
Thanks again.
--
Aaron
Quoted text · Christian Grün · 237 lines
On March 11, 2017 11:07:31 AM EST, "Christian Grün" <christian.gruen at gmail.com> wrote: >Dear Aaron (and thanks Kendall), > >A little addendum: If you use Java’s try-with-resources statement… > > try (LocalSession session = new LocalSession(this.context)) > >…there will be no need to manually close your connection. > >Best, >Christian > > > >On Fri, Mar 10, 2017 at 10:47 PM, AJ Weber <aweber at comcast.net> wrote: >> OK, changing this so that the code flows like yours works much, much >better. >> I now return all 3 documents I expect are in the database. >> >> FOLLOW-UP Question: How do I close the database properly with these >> classes? I had been doing a context.closeDB() when shutting-down. >Do I >> just do a localSession.close() now? Or do I need to do both? >> >> Thanks again!!! >> >> >> >> On 3/10/2017 4:27 PM, AJ Weber wrote: >> >> Well, one difference I spot is that I am opening (via the snippet I >sent >> before) the database BEFORE creating a LocalSession and I am using >the new >> Check(...).execute(context); >> >> The "context" is kept in the object's class-level. >> >> Your code creates the context, associates the new LocalSession with >the >> context, and THEN opens the existing database. (That's more akin to >how a >> JDBC session would go...but I did not see any java examples with >this, I >> followed the examples on the java page and only found LocalSession >via a >> google search.) >> >> There doesn't appear to be any details in the javadoc or anything I >can find >> regarding how to use LocalSession, so I could be off base from that >pov. >> >> -AJ >> >> >> On 3/10/2017 4:18 PM, Kendall Shaw wrote: >> >> This worked for me, where “test-local” contains a document: >> >> >> >> Context context = new Context(); >> >> LocalSession s = new LocalSession(context); >> >> s.execute(new Check("test-local")); >> >> try (Query q = s.query("for $doc in collection() return >$doc")) { >> >> while (q.more()) { >> >> System.out.println(q.next()); >> >> } >> >> } >> >> >> >> But, why your code isn’t working could be useful to know. It seems >like >> there are some details left out. >> >> >> >> Kendall >> >> >> >> From: <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ >Weber >> <aweber at comcast.net> >> Date: Friday, March 10, 2017 at 11:40 AM >> To: "basex-talk at mailman.uni-konstanz.de" >> <basex-talk at mailman.uni-konstanz.de> >> Subject: Re: [basex-talk] Simple query >> >> >> >> >> >> On 3/10/2017 2:24 PM, Kendall Shaw wrote: >> >> Michael Seiferle gave the answer already, I think. What would >collection() >> be referring to? How would BaseX know what to return? Probably there >is no >> database specified. Presumably, in the GUI you have opened a >database. >> >> Yes, I did not include my code to open the database. There is a >database >> open and this does not throw an exception, it just returns no >results. >> >> In my constructor of this class there is the following code: >> new Check(this.MyID).execute(context); >> >> (MyID is a String identifying the database I want to work with >exclusively >> with this context passed.) >> >> As I mentioned in a separate post, my query where matches(uri...) >works >> fine...every time. That query also does not have a specific >collection in >> the query. >> >> >> >> >> Kendall >> >> >> >> >> >> From: <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ >Weber >> <aweber at comcast.net> >> Date: Friday, March 10, 2017 at 6:44 AM >> To: Fabrice ETANCHAUD <fetanchaud at groupefbo.com>, >> "basex-talk at mailman.uni-konstanz.de" ><basex-talk at mailman.uni-konstanz.de> >> Subject: Re: [basex-talk] Simple query >> >> >> >> On 3/9/2017 3:46 AM, Fabrice ETANCHAUD wrote: >> >> Hello Aaron, >> >> >> >> You would learn faster by using the BaseXGUI application, >> >> You will benefit from syntax highlighting, real time execution, and >hits on >> function signatures. >> >> I am trying the GUI now. It is an excellent tool! >> >> However, issuing the same exact XQuery in the GUI returns 3 documents >(which >> is what I would have originally expected). >> >> Maybe it is an issue with how I setup my query in java? Here is my >code: >> >> try (LocalSession session = new LocalSession(this.context)) { >> //test >> >> try (Query q = session.query("for $doc in collection() >return >> $doc")) { >> while (q.more()) { >> LOG.debug("RESULT: " + q.next()); >> } >> } >> } >> catch (Exception e) { >> LOG.error("Could not execute query " + statement, e); >> } >> >> >> >> >> >> 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 >Aaron >> Weber >> Envoyé : jeudi 9 mars 2017 00:31 >> À : basex-talk at mailman.uni-konstanz.de >> Objet : [basex-talk] Simple query >> >> >> >> Newbie alert. >> >> I'm trying to get my feet wet with BaseX, and in doing so, am trying >to >> understand XQuery and how to apply it to a database full of documents >(not >> just a single document that is typically queried). >> >> I am using Java and can post my code, but with a LocalSession, and a >query, >> the following produces 0 results. >> >> For $doc in collection() return $doc >> >> I realize there's no "where", and in the sql world that would match >all. >> Maybe not in XQuery? >> >> Obviously just a test query, but I need to start somewhere. :-) >> >> Thanks for any help! >> -- >> AJ >> >> >> >> >> >> >> >>
AW
Great. Thanks again!
--
Aaron
Quoted text · Christian Grün · 272 lines
On March 11, 2017 11:25:08 AM EST, "Christian Grün" <christian.gruen at gmail.com> wrote: >> I was going to open the local session and keep it open for the >lifetime of >> the webapp like I would do with a JDBC session object. That would not >allow >> me to use the autoclose. Is it possible or recommended to keep the >one >> session object like that? > >Absolutely. BaseX sessions are pretty light-weight, but if you want to >repeatedly access a database/collection (as you did), and avoid >reopening it every time, it can make sense to keep sessions open. > > > >> On March 11, 2017 11:07:31 AM EST, "Christian Grün" >> <christian.gruen at gmail.com> wrote: >>> >>> Dear Aaron (and thanks Kendall), >>> >>> A little addendum: If you use Java’s try-with-resources statement… >>> >>> try (LocalSession session = new LocalSession(this.context)) >>> >>> …there will be no need to manually close your connection. >>> >>> Best, >>> Christian >>> >>> >>> >>> On Fri, Mar 10, 2017 at 10:47 PM, AJ Weber <aweber at comcast.net> >wrote: >>>> >>>> OK, changing this so that the code flows like yours works much, >much >>>> better. >>>> I now return all 3 documents I expect are in the database. >>>> >>>> FOLLOW-UP Question: How do I close the database properly with >these >>>> classes? I had been doing a context.closeDB() when shutting-down. > Do I >>>> just do a localSession.close() now? Or do I need to do both? >>>> >>>> Thanks again!!! >>>> >>>> >>>> >>>> On 3/10/2017 4:27 PM, AJ Weber wrote: >>>> >>>> Well, one difference I spot is that I am opening (via the snippet >I sent >>>> before) the database BEFORE creating a LocalSession and I am using >the >>>> new >>>> Check(...).execute(context); >>>> >>>> The "context" is kept in the object's class-level. >>>> >>>> Your code creates the context, associates the new LocalSession >with the >>>> context, and THEN opens the existing database. (That's more akin >to how >>>> a >>>> JDBC session would go...but I did not see any java examples with >this, I >>>> followed the examples on the java page and only found LocalSession >via a >>>> google search.) >>>> >>>> There doesn't appear to be any details in the javadoc or anything >I can >>>> find >>>> regarding how to use LocalSession, so I could be off base from >that pov. >>>> >>>> -AJ >>>> >>>> >>>> On 3/10/2017 4:18 PM, Kendall Shaw wrote: >>>> >>>> This worked for me, where “test-local” contains a document: >>>> >>>> >>>> >>>> Context context = new Context(); >>>> >>>> LocalSession s = new LocalSession(context); >>>> >>>> s.execute(new Check("test-local")); >>>> >>>> try (Query q = s.query("for $doc in collection() return >$doc")) >>>> { >>>> >>>> while (q.more()) { >>>> >>>> System.out.println(q.next()); >>>> >>>> } >>>> >>>> } >>>> >>>> >>>> >>>> But, why your code isn’t working could be useful to know. It seems >like >>>> there are some details left out. >>>> >>>> >>>> >>>> Kendall >>>> >>>> >>>> >>>> From: <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ >Weber >>>> <aweber at comcast.net> >>>> Date: Friday, March 10, 2017 at 11:40 AM >>>> To: "basex-talk at mailman.uni-konstanz.de" >>>> <basex-talk at mailman.uni-konstanz.de> >>>> Subject: Re: [basex-talk] Simple query >>>> >>>> >>>> >>>> >>>> >>>> On 3/10/2017 2:24 PM, Kendall Shaw wrote: >>>> >>>> Michael Seiferle gave the answer already, I think. What would >>>> collection() >>>> be referring to? How would BaseX know what to return? Probably >there is >>>> no >>>> database specified. Presumably, in the GUI you have opened a >database. >>>> >>>> Yes, I did not include my code to open the database. There is a >>>> database >>>> open and this does not throw an exception, it just returns no >results. >>>> >>>> In my constructor of this class there is the following code: >>>> new Check(this.MyID).execute(context); >>>> >>>> (MyID is a String identifying the database I want to work with >>>> exclusively >>>> with this context passed.) >>>> >>>> As I mentioned in a separate post, my query where matches(uri...) >works >>>> fine...every time. That query also does not have a specific >collection >>>> in >>>> the query. >>>> >>>> >>>> >>>> >>>> Kendall >>>> >>>> >>>> >>>> >>>> >>>> From: <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of AJ >Weber >>>> <aweber at comcast.net> >>>> Date: Friday, March 10, 2017 at 6:44 AM >>>> To: Fabrice ETANCHAUD <fetanchaud at groupefbo.com>, >>>> "basex-talk at mailman.uni-konstanz.de" >>>> <basex-talk at mailman.uni-konstanz.de> >>>> Subject: Re: [basex-talk] Simple query >>>> >>>> >>>> >>>> On 3/9/2017 3:46 AM, Fabrice ETANCHAUD wrote: >>>> >>>> Hello Aaron, >>>> >>>> >>>> >>>> You would learn faster by using the BaseXGUI application, >>>> >>>> You will benefit from syntax highlighting, real time execution, >and hits >>>> on >>>> function signatures. >>>> >>>> I am trying the GUI now. It is an excellent tool! >>>> >>>> However, issuing the same exact XQuery in the GUI returns 3 >documents >>>> (which >>>> is what I would have originally expected). >>>> >>>> Maybe it is an issue with how I setup my query in java? Here is >my >>>> code: >>>> >>>> try (LocalSession session = new >LocalSession(this.context)) { >>>> //test >>>> >>>> try (Query q = session.query("for $doc in collection() >>>> return >>>> $doc")) { >>>> while (q.more()) { >>>> LOG.debug("RESULT: " + q.next()); >>>> } >>>> } >>>> } >>>> catch (Exception e) { >>>> LOG.error("Could not execute query " + statement, e); >>>> } >>>> >>>> >>>> >>>> >>>> >>>> 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 >Aaron >>>> Weber >>>> Envoyé : jeudi 9 mars 2017 00:31 >>>> À : basex-talk at mailman.uni-konstanz.de >>>> Objet : [basex-talk] Simple query >>>> >>>> >>>> >>>> Newbie alert. >>>> >>>> I'm trying to get my feet wet with BaseX, and in doing so, am >trying to >>>> understand XQuery and how to apply it to a database full of >documents >>>> (not >>>> just a single document that is typically queried). >>>> >>>> I am using Java and can post my code, but with a LocalSession, and >a >>>> query, >>>> the following produces 0 results. >>>> >>>> For $doc in collection() return $doc >>>> >>>> I realize there's no "where", and in the sql world that would >match all. >>>> Maybe not in XQuery? >>>> >>>> Obviously just a test query, but I need to start somewhere. :-) >>>> >>>> Thanks for any help! >>>> -- >>>> AJ >>> >>> >>> >>> >>> >>> >>> >>> >>> >>
MB
mark bordelon11 Mar 2017 21:16 #
I am trying to retreieve the raw xml from a document and think I should use the RETRIEVE command, right? What is the ID that I pass as the argument? Here is what I have tried with the error:
Quoted text · Aaron Weber · 1 line
> list
Name Resources Size Input Path
----------------------------------------
greek 2 2942906
latin 184 9942769
semantic 785 257685
3 database(s).
Quoted text · Aaron Weber · 1 line
> list greek
Input Path Type Content-Type Size
------------------------------------------------------------
PROSE~aristotle~Rhetoric1 xml application/xml 99387
PROSE~CONVERSATION~GreekPrimer xml application/xml 20260
Quoted text · Aaron Weber · 1 line
> open greek
Database 'greek' was opened in 2.9 ms.
Quoted text · Aaron Weber · 1 line
> retrieve PROSE~aristotle~Rhetoric1
Resource "PROSE~aristotle~Rhetoric1" not found.
CG
Christian Grün11 Mar 2017 21:21 #
Hi Mark,
Each resource is stored as either an XML document or a binary file (raw data) [1]. You can only retrieve resources as raw data of they have been stored as binaries.
Hope this helps,
Christian
[1] http://docs.basex.org/wiki/Binary_Data
Quoted text · mark bordelon · 1 line
Am 11.03.2017 21:16 schrieb "mark bordelon" <markcbordelon at yahoo.com>:
I am trying to retreieve the raw xml from a document and think I should use the RETRIEVE command, right? What is the ID that I pass as the argument? Here is what I have tried with the error:
Quoted text · mark bordelon · 1 line
> *list*
Name Resources Size Input Path
----------------------------------------
greek 2 2942906
latin 184 9942769
semantic 785 257685
3 database(s).
Quoted text · mark bordelon · 1 line
> *list greek*
Input Path Type Content-Type Size
------------------------------------------------------------ PROSE~aristotle~Rhetoric1 xml application/xml 99387 PROSE~CONVERSATION~GreekPrimer xml application/xml 20260
Quoted text · mark bordelon · 1 line
> *open greek*
Database 'greek' was opened in 2.9 ms.
Quoted text · mark bordelon · 1 line
> *retrieve PROSE~aristotle~Rhetoric1*
*Resource "PROSE~aristotle~Rhetoric1" not found.*
MB
mark bordelon11 Mar 2017 21:24 #
Christian, thank you.Can you give me an example of the syntax (e.g. command + param) of the RETRIEVE command in my case?
From: Christian Grün <christian.gruen at gmail.com>
To: mark bordelon <markcbordelon at yahoo.com>
Cc: BaseX <basex-talk at mailman.uni-konstanz.de>
Sent: Saturday, March 11, 2017 12:21 PM
Subject: Re: [basex-talk] RETRIEVE
Hi Mark,
Each resource is stored as either an XML document or a binary file (raw data) [1]. You can only retrieve resources as raw data of they have been stored as binaries. Hope this helps,Christian
[1] http://docs.basex.org/wiki/Binary_Data
Quoted text · Christian Grün · 1 line
Am 11.03.2017 21:16 schrieb "mark bordelon" <markcbordelon at yahoo.com>:
I am trying to retreieve the raw xml from a document and think I should use the RETRIEVE command, right? What is the ID that I pass as the argument?Here is what I have tried with the error:
Quoted text · Christian Grün · 3 lines
> list Name Resources Size Input Path ------------------------------ ----------greek 2 2942906 latin 184 9942769 semantic 785 257685 3 database(s).> list greekInput Path Type Content-Type Size ------------------------------ ------------------------------PROSE~aristotle~Rhetoric1 xml application/xml 99387 PROSE~CONVERSATION~ GreekPrimer xml application/xml 20260 > open greekDatabase 'greek' was opened in 2.9 ms.> retrieve PROSE~aristotle~Rhetoric1Resource "PROSE~aristotle~Rhetoric1" not found.
CG
Christian Grün11 Mar 2017 21:25 #
What are your intentions? Are you really interested in a raw representation of your input?
Quoted text · mark bordelon · 56 lines
Am 11.03.2017 21:24 schrieb "mark bordelon" <markcbordelon at yahoo.com>: > Christian, thank you. > Can you give me an example of the syntax (e.g. command + param) of the > RETRIEVE command in my case? > > > ------------------------------ > *From:* Christian Grün <christian.gruen at gmail.com> > *To:* mark bordelon <markcbordelon at yahoo.com> > *Cc:* BaseX <basex-talk at mailman.uni-konstanz.de> > *Sent:* Saturday, March 11, 2017 12:21 PM > *Subject:* Re: [basex-talk] RETRIEVE > > Hi Mark, > > Each resource is stored as either an XML document or a binary file (raw > data) [1]. You can only retrieve resources as raw data of they have been > stored as binaries. > > Hope this helps, > Christian > > [1] http://docs.basex.org/wiki/Binary_Data > > > > > Am 11.03.2017 21:16 schrieb "mark bordelon" <markcbordelon at yahoo.com>: > > I am trying to retreieve the raw xml from a document and think I should > use the RETRIEVE command, right? What is the ID that I pass as the argument? > Here is what I have tried with the error: > > > *list* > Name Resources Size Input Path > ------------------------------ ---------- > greek 2 2942906 > latin 184 9942769 > semantic 785 257685 > > 3 database(s). > > *list greek* > Input Path Type Content-Type Size > ------------------------------ ------------------------------ > PROSE~aristotle~Rhetoric1 xml application/xml 99387 > PROSE~CONVERSATION~ GreekPrimer xml application/xml 20260 > > > *open greek* > Database 'greek' was opened in 2.9 ms. > > *retrieve PROSE~aristotle~Rhetoric1* > *Resource "PROSE~aristotle~Rhetoric1" not found.* > > > > >
CG
Christian Grün11 Mar 2017 22:18 #
For returning specific XML documents of a database, you need to use the XQUERY command:
XQUERY db:open('greek', 'PROSE~aristotle~Rhetoric1')
All documents of the currently opened database can simply be addressed and returned via the context item (.):
XQUERY .
Hope this helps,
Christian
Am 11.03.2017 10:08 nachm. schrieb "mark bordelon" <markcbordelon at yahoo.com
Quoted text · Christian Grün · 97 lines
>: > In actuality, as you have surmised, no. > I wish to get the xml text of document. > So, for what I am attempting below ... > > *> list * > *Name Resources Size Input Path * > *------------------------------ ----------* > *greek 2 2942906 * > *latin 184 9942769 * > *semantic 785 257685 * > > *3 database(s).* > *> list greek* > *Input Path Type Content-Type Size * > *------------------------------ ------------------------------* > *PROSE~aristotle~Rhetoric1 xml application/xml 99387 * > *PROSE~CONVERSATION~ GreekPrimer xml application/xml 20260 * > > *> open greek* > *Database 'greek' was opened in 2.9 ms.* > *> retrieve PROSE~aristotle~Rhetoric1* > > .. my intention is to have the xml content: *<text><sent><clause> ...... > </text>* > > ------------------------------ > *From:* Christian Grün <christian.gruen at gmail.com> > *To:* mark bordelon <markcbordelon at yahoo.com> > *Cc:* BaseX <basex-talk at mailman.uni-konstanz.de> > *Sent:* Saturday, March 11, 2017 12:25 PM > *Subject:* Re: [basex-talk] RETRIEVE > > What are your intentions? Are you really interested in a raw > representation of your input? > > Am 11.03.2017 21:24 schrieb "mark bordelon" <markcbordelon at yahoo.com>: > > Christian, thank you. > Can you give me an example of the syntax (e.g. command + param) of the > RETRIEVE command in my case? > > > ------------------------------ > *From:* Christian Grün <christian.gruen at gmail.com> > *To:* mark bordelon <markcbordelon at yahoo.com> > *Cc:* BaseX <basex-talk at mailman.uni- konstanz.de > <basex-talk at mailman.uni-konstanz.de>> > *Sent:* Saturday, March 11, 2017 12:21 PM > *Subject:* Re: [basex-talk] RETRIEVE > > Hi Mark, > > Each resource is stored as either an XML document or a binary file (raw > data) [1]. You can only retrieve resources as raw data of they have been > stored as binaries. > > Hope this helps, > Christian > > [1] http://docs.basex.org/ wiki/Binary_Data > <http://docs.basex.org/wiki/Binary_Data> > > > > > Am 11.03.2017 21:16 schrieb "mark bordelon" <markcbordelon at yahoo.com>: > > I am trying to retreieve the raw xml from a document and think I should > use the RETRIEVE command, right? What is the ID that I pass as the argument? > Here is what I have tried with the error: > > > *list* > Name Resources Size Input Path > ------------------------------ ---------- > greek 2 2942906 > latin 184 9942769 > semantic 785 257685 > > 3 database(s). > > *list greek* > Input Path Type Content-Type Size > ------------------------------ ------------------------------ > PROSE~aristotle~Rhetoric1 xml application/xml 99387 > PROSE~CONVERSATION~ GreekPrimer xml application/xml 20260 > > > *open greek* > Database 'greek' was opened in 2.9 ms. > > *retrieve PROSE~aristotle~Rhetoric1* > *Resource "PROSE~aristotle~Rhetoric1" not found.* > > > > > > >
Written for BaseX 8.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery