Hallo,

the following xquery results in duplicate keys or missed updates, if we get two messages of the same person in one xml-document. All updates in the database are done at the end of the xquery and the reading inbetween gets the old state of the database. Is there a command to persist the actual state (like commit in sql)? If not, i need some help for my design, because i have no idea, how to get a stable processing. 


Kind regards,
Christoph


(: Verarbeitung einer Bestandslieferung (1600).
:)
declare namespace xmeld="http://www.osci.de/xmeld21";
declare namespace kmeld="http://www.krz-swd.de/kmeld";
import module namespace kmeldFkt="http://www.krz-swd.de/kmeld/Fkt" at "kmeldFkt.xq";
declare variable $file := "/home/christoph/Beruf/KRZ/Referenznachrichten/16.001.001.001a-1600.xml";

for $s in doc($file)/xmeld:kirche.bestandslieferung.1600/xmeld:sachzusammenhang,
    $k in $s/xmeld:initialGeliefertesKirchenmitglied/xmeld:kirchenmitglied
  let $n   := $s/preceding-sibling::xmeld:nachrichtenkopf,
      $key := kmeldFkt:bildeIdMitglied($n, $k),
      $m_alt :=                        (: Mitglied im Bestand :)
        collection("XMeldDB")/kmeld:XMeldDB/kmeld:personenbestand/kmeld:Mitglied[@ID eq $key]
  let $m_neu :=
    if ($m_alt)
    then
      kmeldFkt:updateMitglied($m_alt, $k, $s, $n)
    else
      kmeldFkt:createMitglied($k, $s, $n)
  return
    if($m_alt)
    then
      replace node $m_alt with $m_neu
    else
      insert node $m_neu into collection("XMeldDB")/kmeld:XMeldDB/kmeld:personenbestand