George Feinberg
2006-04-17 14:13:17 UTC
Temo,
to open the container. If you use the DBXML_TRANSACTIONAL
flag, you should not also pass a transaction. That, and if you
*do* pass a transaction to open or create a container, it must
be committed immediately after, and not used for anything else.
See below...
$con = $mgr->openContainer("test.dbxml",DBXML_TRANSACTIONAL);
$txn = $mgr->createTransaction();
Regards,
George
To remove yourself from this list, send an
email to xml-unsubscribe-***@public.gmane.org
I'm working on a PHP manager to handle articles on line. I have been
using XmlModify in some scripts but when I create an environment to
modify a document within a transaction the XmlModify doesn't apply
the changes.
My cuestion is about how to handle a XmlModify into transactions in
PHP.
I'm think that I am doing something wrong. I trying to isolate the
transaction in a sigle scrips reading and using many of the basic
examples.
The problem is at least partly related to use of the transactionusing XmlModify in some scripts but when I create an environment to
modify a document within a transaction the XmlModify doesn't apply
the changes.
My cuestion is about how to handle a XmlModify into transactions in
PHP.
I'm think that I am doing something wrong. I trying to isolate the
transaction in a sigle scrips reading and using many of the basic
examples.
to open the container. If you use the DBXML_TRANSACTIONAL
flag, you should not also pass a transaction. That, and if you
*do* pass a transaction to open or create a container, it must
be committed immediately after, and not used for anything else.
See below...
<?php
$env = new Db4Env();
$env->open();
$mgr = new XmlManager($env);
$txn = $mgr->createTransaction();
Don't do above, move it down...$env = new Db4Env();
$env->open();
$mgr = new XmlManager($env);
$txn = $mgr->createTransaction();
$con = $mgr->openContainer($txn,"test.dbxml",DBXML_TRANSACTIONAL);
Change this to :$con = $mgr->openContainer("test.dbxml",DBXML_TRANSACTIONAL);
$qc = $mgr->createQueryContext();
$uc = $mgr->createUpdateContext();
$mod = $mgr->createModify();
Now start your transaction for the modify:$uc = $mgr->createUpdateContext();
$mod = $mgr->createModify();
$txn = $mgr->createTransaction();
$select = $mgr->prepare($txn,"/book",$qc);
$mod->addAppendStep($select,XmlModify_Element,"section","some
text");
$retdoc=$mgr->query($txn,"doc('test.dbxml/book1')/book");
$mod->execute($txn,$retdoc,$qc,$uc);
$txn->commit();
unset($con);
$env->close();
?>
See if that helps,$mod->addAppendStep($select,XmlModify_Element,"section","some
text");
$retdoc=$mgr->query($txn,"doc('test.dbxml/book1')/book");
$mod->execute($txn,$retdoc,$qc,$uc);
$txn->commit();
unset($con);
$env->close();
?>
Regards,
George
In other side, the following script XmlModify works nicely without
<?php
$mgr = new XmlManager();
$con = $mgr->openContainer("test.dbxml");
$qc = $mgr->createQueryContext();
$uc = $mgr->createUpdateContext();
$mod = $mgr->createModify();
$select = $mgr->prepare("/book",$qc);
$mod->addAppendStep($select,XmlModify_Element,"section","some
text");
$retdoc=$mgr->query("doc('test.dbxml/book1')/book");
$mod->execute($retdoc,$qc,$uc);
unset($doc);
unset($con);
?>
The container and the document was created with the following
<?php
$book_name = 'book1';
$book_content = '<book><title>This the title of the document.</
title></book>';
$mgr = new XmlManager();
$con = $mgr->createContainer("test.dbxml");
$con->putDocument($book_name, $book_content);
$doc = $con->getDocument($book_name);
$s = $doc->getContentAsString();
print $doc->getName(). " = $s\n";
unset($doc);
unset($con);
?>
Thanks for any help you can offer!
Regards,
Temo
------------------------------------------<?php
$mgr = new XmlManager();
$con = $mgr->openContainer("test.dbxml");
$qc = $mgr->createQueryContext();
$uc = $mgr->createUpdateContext();
$mod = $mgr->createModify();
$select = $mgr->prepare("/book",$qc);
$mod->addAppendStep($select,XmlModify_Element,"section","some
text");
$retdoc=$mgr->query("doc('test.dbxml/book1')/book");
$mod->execute($retdoc,$qc,$uc);
unset($doc);
unset($con);
?>
The container and the document was created with the following
<?php
$book_name = 'book1';
$book_content = '<book><title>This the title of the document.</
title></book>';
$mgr = new XmlManager();
$con = $mgr->createContainer("test.dbxml");
$con->putDocument($book_name, $book_content);
$doc = $con->getDocument($book_name);
$s = $doc->getContentAsString();
print $doc->getName(). " = $s\n";
unset($doc);
unset($con);
?>
Thanks for any help you can offer!
Regards,
Temo
To remove yourself from this list, send an
email to xml-unsubscribe-***@public.gmane.org