querying database
Tuesday, 19 July 2016 · 8 messages · last reply 20 Jul 2016
MK
Mohamed kharrat19 Jul 2016 18:33 #
Hi,i have created a database in BaseX GUI but i did not understand how to use it inside FLWR query.So since i would like to create one FLWR query to query all my files in the database not only one file with doc()i have tried collection() is that right? (i have putted all my xml files inside path/ directory)This is my query: let $d:=collection ("path/")
let $r:=doc("myfile1.xml")
for $d in$d// item/@qcode="tx"where $d//subj[text() contains text { 'Hal', 'Fade' } any] and$r/subj ="Berlin
"return
<results>$d/tit</results>it shows me error: [XPTY0019] descendant::subj: node expected, xs:boolean found: false(). what is that error about?----Thank youBest regards
MG
Maximilian Gärber19 Jul 2016 18:44 #
Hi,
you do not need to use doc() or collection() if your documents are stored in a database.
The documents are just nodes as well, so doing something like:
let $db := db:open('some-db')
for $d in $db//item/@qcode="tx"
return $dwould return the items from all nodes (all files)
BTW: I guess you want: $db// item[@qcode="tx"]
Regards,
Max
2016-07-19 18:33 GMT+02:00 Mohamed kharrat <med_khr at yahoo.fr>:
Quoted text · Mohamed kharrat · 25 lines
> Hi, > i have created a database in BaseX GUI but i did not understand how to use > it inside FLWR query. > So since i would like to create one FLWR query to query all my files in the > database not only one file with doc() > i have tried collection() is that right? (i have putted all my xml files > inside path/ directory) > This is my query: > > let $d:= collection ("path/") > let $r:= doc("myfile1.xml") > for $d in $d// item/@qcode="tx" > where $d//subj[text() contains text { 'Hal', 'Fade' } any] and $r/subj > ="Berlin" > return > <results>$d/tit</results> > > > it shows me error: [XPTY0019] descendant::subj: node expected, xs:boolean > found: false(). > > what is that error about? > ---- > Thank you > Best regards
MK
Mohamed kharrat19 Jul 2016 19:16 #
Thank you, it works :)What about the error? error: [XPTY0019] descendant::subj: node expected, xs:boolean found: false().Any idea please?
De : Maximilian Gärber <mgaerber at arcor.de>
À : Mohamed kharrat <med_khr at yahoo.fr>
Cc : BaseX Talk <basex-talk at mailman.uni-konstanz.de>
Envoyé le : Mardi 19 juillet 2016 17h44
Objet : Re: [basex-talk] querying database
Hi,
you do not need to use doc() or collection() if your documents are stored in a database.
The documents are just nodes as well, so doing something like:
let $db := db:open('some-db')
for $d in $db//item/@qcode="tx"
return $dwould return the items from all nodes (all files)
BTW: I guess you want: $db// item[@qcode="tx"]
Regards,
Max
2016-07-19 18:33 GMT+02:00 Mohamed kharrat <med_khr at yahoo.fr>:
Quoted text · Maximilian Gärber · 25 lines
> Hi, > i have created a database in BaseX GUI but i did not understand how to use > it inside FLWR query. > So since i would like to create one FLWR query to query all my files in the > database not only one file with doc() > i have tried collection() is that right? (i have putted all my xml files > inside path/ directory) > This is my query: > > let $d:= collection ("path/") > let $r:= doc("myfile1.xml") > for $d in $d// item/@qcode="tx" > where $d//subj[text() contains text { 'Hal', 'Fade' } any] and $r/subj > ="Berlin" > return > <results>$d/tit</results> > > > it shows me error: [XPTY0019] descendant::subj: node expected, xs:boolean > found: false(). > > what is that error about? > ---- > Thank you > Best regards
CG
Christian Grün19 Jul 2016 19:22 #
$d// item/@qcode="tx"…returns a boolean value (true or false). Hence,
for $d in $d// item/@qcode="tx"is the same as
for $d in true()or
for $d in false()As a result,
$d//subjwill give you an error (node expected, boolean found).
Quoted text · Mohamed kharrat · 61 lines
On Tue, Jul 19, 2016 at 7:16 PM, Mohamed kharrat <med_khr at yahoo.fr> wrote: > Thank you, it works :) > What about the error? error: [XPTY0019] descendant::subj: node expected, > xs:boolean found: false(). > Any idea please? > > > ________________________________ > De : Maximilian Gärber <mgaerber at arcor.de> > À : Mohamed kharrat <med_khr at yahoo.fr> > Cc : BaseX Talk <basex-talk at mailman.uni-konstanz.de> > Envoyé le : Mardi 19 juillet 2016 17h44 > Objet : Re: [basex-talk] querying database > > Hi, > > you do not need to use doc() or collection() if your documents are > stored in a database. > > The documents are just nodes as well, so doing something like: > > let $db := db:open('some-db') > for $d in $db//item/@qcode="tx" > return $d > > would return the items from all nodes (all files) > > BTW: I guess you want: $db// item[@qcode="tx"] > > Regards, > Max > > 2016-07-19 18:33 GMT+02:00 Mohamed kharrat <med_khr at yahoo.fr>: >> Hi, >> i have created a database in BaseX GUI but i did not understand how to use >> it inside FLWR query. >> So since i would like to create one FLWR query to query all my files in >> the >> database not only one file with doc() >> i have tried collection() is that right? (i have putted all my xml files >> inside path/ directory) >> This is my query: >> >> let $d:= collection ("path/") >> let $r:= doc("myfile1.xml") >> for $d in $d// item/@qcode="tx" >> where $d//subj[text() contains text { 'Hal', 'Fade' } any] and $r/subj >> ="Berlin" >> return >> <results>$d/tit</results> >> >> >> it shows me error: [XPTY0019] descendant::subj: node expected, xs:boolean >> found: false(). >> >> what is that error about? >> ---- >> Thank you >> Best regards > >
M
med_khr19 Jul 2016 19:35 #
ok i understand now. In fact i am looking for results which have this condition of qcode=tx . I do not want to know if it's true or false.
Quoted text · Christian Grün · 1 line
On Tue, Jul 19, 2016 at 6:23 PM +0100, "Christian Grün" <christian.gruen at gmail.com> wrote:
$d// item/@qcode="tx"…returns a boolean value (true or false). Hence,
for $d in $d// item/@qcode="tx"is the same as
for $d in true()or
for $d in false()As a result,
$d//subjwill give you an error (node expected, boolean found).
Quoted text · Mohamed kharrat · 61 lines
On Tue, Jul 19, 2016 at 7:16 PM, Mohamed kharrat wrote: > Thank you, it works :) > What about the error? error: [XPTY0019] descendant::subj: node expected, > xs:boolean found: false(). > Any idea please? > > > ________________________________ > De : Maximilian Gärber > À : Mohamed kharrat > Cc : BaseX Talk > Envoyé le : Mardi 19 juillet 2016 17h44 > Objet : Re: [basex-talk] querying database > > Hi, > > you do not need to use doc() or collection() if your documents are > stored in a database. > > The documents are just nodes as well, so doing something like: > > let $db := db:open('some-db') > for $d in $db//item/@qcode="tx" > return $d > > would return the items from all nodes (all files) > > BTW: I guess you want: $db// item[@qcode="tx"] > > Regards, > Max > > 2016-07-19 18:33 GMT+02:00 Mohamed kharrat : >> Hi, >> i have created a database in BaseX GUI but i did not understand how to use >> it inside FLWR query. >> So since i would like to create one FLWR query to query all my files in >> the >> database not only one file with doc() >> i have tried collection() is that right? (i have putted all my xml files >> inside path/ directory) >> This is my query: >> >> let $d:= collection ("path/") >> let $r:= doc("myfile1.xml") >> for $d in $d// item/@qcode="tx" >> where $d//subj[text() contains text { 'Hal', 'Fade' } any] and $r/subj >> ="Berlin" >> return >> $d/tit >> >> >> it shows me error: [XPTY0019] descendant::subj: node expected, xs:boolean >> found: false(). >> >> what is that error about? >> ---- >> Thank you >> Best regards > >
CG
Christian Grün19 Jul 2016 19:38 #
Quoted text · med_khr · 2 lines
> ok i understand now. In fact i am looking for results which have this > condition of qcode=tx . I do not want to know if it's true or false.
Perfect, so use the predicate, as suggested by Max
$d// item[@qcode="tx"]For more details, please spend some time on an XPath/XQuery primer, such as http://www.w3schools.com/xsl/xpath_intro.asp.
MK
Thank you it works.Just a last question please.i need to write a query which means: return titles of all docs in database where the item/qcode ="tx"and where one of the subject name contains any one of those string: "FH" or "HG" let $db := db:open('mybase')for $x in $db//item[@qcode="tx"]where $db//subject/name[text() contains text{ "FH","HG"}any]return<results>{$db//title}</results> I think this query is wrong
De : Maximilian Gärber <mgaerber at arcor.de>
À : Mohamed kharrat <med_khr at yahoo.fr>
Cc : BaseX Talk <basex-talk at mailman.uni-konstanz.de>
Envoyé le : Mardi 19 juillet 2016 17h44
Objet : Re: [basex-talk] querying database
Hi,
you do not need to use doc() or collection() if your documents are stored in a database.
The documents are just nodes as well, so doing something like:
let $db := db:open('some-db')
for $d in $db//item/@qcode="tx"
return $dwould return the items from all nodes (all files)
BTW: I guess you want: $db// item[@qcode="tx"]
Regards,
Max
2016-07-19 18:33 GMT+02:00 Mohamed kharrat <med_khr at yahoo.fr>:
Quoted text · Maximilian Gärber · 25 lines
> Hi, > i have created a database in BaseX GUI but i did not understand how to use > it inside FLWR query. > So since i would like to create one FLWR query to query all my files in the > database not only one file with doc() > i have tried collection() is that right? (i have putted all my xml files > inside path/ directory) > This is my query: > > let $d:= collection ("path/") > let $r:= doc("myfile1.xml") > for $d in $d// item/@qcode="tx" > where $d//subj[text() contains text { 'Hal', 'Fade' } any] and $r/subj > ="Berlin" > return > <results>$d/tit</results> > > > it shows me error: [XPTY0019] descendant::subj: node expected, xs:boolean > found: false(). > > what is that error about? > ---- > Thank you > Best regards
CG
Christian Grün20 Jul 2016 08:40 #
Quoted text · Mohamed kharrat · 1 line
> I think this query is wrong
Yes it is. Please try to understand what you are doing in this query, otherwise you won't be very successful in the middle term.
Written for BaseX 8.5. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery