Re: [bdbxml] problem with dbxml distinct-values

George Feinberg <[email protected]> Fri, 26 Aug 2005 10:49:18 -0400
Newsgroups gmane.comp.db.dbxml.general
Message-ID <[email protected]>
Luigi,

Sorry it's taken a while to get back to you.

You have not provided the initial query, but
I have to assume that you are executing a query that returns
10 values in an XmlResults object, and each of those values is
a "block" element, similar to the one referenced.

Given that, it's important to understand that the "/" operator
of XPath still refers to the root of the document, and not to
the root of the current context (the "block") element.

Given that, your arguments to distinct-values() should
be relative paths, rather than absolute.  So, instead of
distinct-values(/storage/block/<path>)
use simply
distinct-values(<path>) or distinct-values(./<path>)

What is happening is that your queries are always going to the
root of the document, ignoring the current context, and always
getting the first block as a result.

Regards,

George

> I am not able to make this code crop work, mistakes are not but the  
> result is not the wished one
>
> Example block xml:
>
> <block>
>     <id_block>2147483641</id
> _block>
>     <name_block>2147483641</name_block>
>     <size>2147483641</size>
>     <last_offset>2147483641</last_offset>
>     <last_byte_write>2147483641</last_byte_write>
>     <delete>
>         <offset_init>2147483641</offset_init>
>         <offset_fin>2147483641</offset_fin>
>     </delete>
>     <delete>
>         <offset_init>2147483655</offset_init>
>         <offset_fin>2147483667</offset_fin>
>     </delete>
> </block>
>
> code which is not working:
>
> resultsBlock  contains the 10 blocks and he is a XMLRESULT
> ...
> XmlValue valueBlock = resultsBlock.next();
>
> while (valueBlock != null) {
>
>     String nameQ = "distinct-values(/storage/block/id_block)";
>     long name = 0;
>
>     String sizeQ = "distinct-values(/storage/block/size)";
>     long size = 0;
>
>     String lastOffsetQ = "distinct-values(/storage/block/ 
> last_offset)";
>     long lastOffset = 0;
>
>     String nameBlockFileQ = "distinct-values(/storage/block/ 
> name_block)";
>     String nameBlockFile = "";
>
>     String lastByteWriteQ = "distinct-values(/storage/block/ 
> last_byte_write)";
>     long lastByteWrite = 0;
>
>     String deleteQ = "distinct-values(/storage/block/delete)";
>
>     XmlQueryContext documentContext = mgr.createQueryContext();
>     documentContext.setReturnType(XmlQueryContext.DeadValues);
>
>     ArrayList listDelete = new ArrayList();
>     Block block;
>
>     XmlQueryExpression nameExpr = mgr.prepare(nameQ, documentContext);
>     XmlResults nameResults = nameExpr.execute(valueBlock,  
> documentContext);
>     name = Long.parseLong(nameResults.next().asString());
>
>     XmlQueryExpression sizeExpr = mgr.prepare(sizeQ, documentContext);
>     XmlResults sizeResults = sizeExpr.execute(valueBlock,  
> documentContext);
>     size = Long.parseLong(sizeResults.next().asString());
>
>     XmlQueryExpression lastOffsetExpr = mgr.prepare(lastOffsetQ,  
> documentContext);
>     XmlResults lastOffsetResults = lastOffsetExpr.execute 
> (valueBlock, documentContext);
>     lastOffset = Long.parseLong(lastOffsetResults.next().asString());
>
>     XmlQueryExpression nameBlockFileExpr = mgr.prepare 
> (nameBlockFileQ, documentContext);
>     XmlResults nameBlockFileResults = nameBlockFileExpr.execute 
> (valueBlock, documentContext);
>     nameBlockFile = nameBlockFileResults.next().asString();
>
>     XmlQueryExpression lastByteWriteExpr = mgr.prepare 
> (lastByteWriteQ, documentContext);
>     XmlResults lastByteWriteResults = lastByteWriteExpr.execute 
> (valueBlock, documentContext);
>     lastByteWrite = Long.parseLong(lastByteWriteResults.next 
> ().asString());
>
>     XmlQueryExpression deleteExpr = mgr.prepare(deleteQ,  
> documentContext);
>     XmlResults deleteResults = deleteExpr.execute(valueBlock,  
> documentContext);
>
>     block = new Block(lastByteWrite, lastOffset, listDelete, name,  
> nameBlockFile, size);
>     listaBlocchi.add(block);
>
>     // Ricavo il singolo blocco
>     valueBlock = resultsBlock.next();
>
> }
>
>
> wished result: an ArrayList containing the ten blocks
>
> obtained result: an ArrayList containing 10 blocks with the values  
> of the first block
>
> could you show me where I make a mistake?



------------------------------------------
To remove yourself from this list, send an
email to [email protected]