Subject:Inserting and selecting data into DB by XQuery Author:Simon Tuson Date:22 Oct 2010 12:16 AM
Hi All,
I'm not an XQuery expert so please forgive any bad terminology here.
Essentially what I an trying to do is load in an XML hierarchical index into a database. The loading is simple but I am struggling to insert the correct parent id's from the hierarchy.
Every item in the index has an id in the database (primary key), items also must have the parent id of it direct ancestor. The is best illustrated in the following where we have 3 levels of depth.
Subject:Inserting and selecting data into DB by XQuery Author:Ivan Pedruzzi Date:23 Oct 2010 01:21 AM
Simon,
Unfortunately an updating query cannot see its side effects because of the XQuery snapshot semantic.
You could try doing two queries, the first query does the insert and leave the PID empty and the second query updates the PID.
for $MYITEM in /root//item
,$record in collection("tm_m_taxdtls")//tm_m_taxdtls[key = $MYITEM/@id]
,$parent in collection("tm_m_taxdtls")/tm_m_taxdtls[key = $MYITEM/@pid]
where exists($parent)
return
ddtek:sql-update($record, "pid", $parent/id)