Changeset 175

Show
Ignore:
Timestamp:
07/31/08 12:08:33 (4 months ago)
Author:
zork
Message:

XMLOStream forgets where to add class members as elements after store - it always add it to first child

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dba/dba/xmlostream.cpp

    r174 r175  
    134134    xmlNodeSetContent(node,encoded_data); 
    135135    xmlFree(encoded_data); 
     136    debug("adding node '%s' to '%s'", pName, (const char*)pNode->name); 
    136137    xmlAddChild(pNode,node); 
    137138  } else { 
     
    155156    xmlNodePtr last = xmlGetLastChild(mParentNode); 
    156157    if (last == NULL) 
    157       xmlAddChild(mParentNode, node); 
     158      mLastAddedNode = xmlAddChild(mParentNode, node); 
    158159    else 
    159       xmlAddPrevSibling(last,node); 
    160   } else { 
     160      mLastAddedNode = xmlAddPrevSibling(last,node); 
     161 } else { 
    161162    node->nsDef = xmlCopyNamespaceList(mParentNode->nsDef); 
    162163    xmlFree(xmlDocSetRootElement(mDocument,node)); 
     
    181182  //set new parent node for storing subobjects 
    182183  if (mParentNode != NULL) { 
    183     debug("going down to first child of mParent '%s'", (const char*)mParentNode->name); 
    184     mParentNode = mParentNode->children
     184    debug("going down to last added child '%s' of mParent '%s'", (const char*)mLastAddedNode->name, (const char*)mParentNode->name); 
     185    mParentNode = mLastAddedNode
    185186  } else { 
    186187    mParentNode = xmlDocGetRootElement(mDocument); 
  • trunk/dba/dba/xmlostream.h

    r166 r175  
    4545    xmlDocPtr mDocument; 
    4646    xmlNodePtr mParentNode; 
     47    xmlNodePtr mLastAddedNode; 
    4748    bool mReplaceParentNode; 
    4849    bool mUseElements; 
  • trunk/dba/test/main.cpp

    r174 r175  
    151151  //runner.addTest(new CppUnit::TestCaller<SQLite3SQLArchiveTestCase>("debug_test",&SQLite3SQLArchiveTestCase::transactions_rollback)); 
    152152  runner.addTest(dba_tests::XMLTestCase::suite()); 
    153   //runner.addTest(new CppUnit::TestCaller<dba_tests::XMLTestCase>("debug_test",&dba_tests::XMLTestCase::storeBug1)); 
     153  //runner.addTest(new CppUnit::TestCaller<dba_tests::XMLTestCase>("debug_test",&dba_tests::XMLTestCase::storeBug2)); 
    154154  //runner.addTest(new CppUnit::TestCaller<dba_tests::XMLTestCase>("debug_test",&dba_tests::XMLTestCase::store_two)); 
    155155  //runner.addTest(new CppUnit::TestCaller<OdbcPluginTestCase>("debug_test",&OdbcPluginTestCase::dbConnection)); 
  • trunk/dba/test/xmltestcase.cpp

    r174 r175  
    832832}; 
    833833 
    834 struct Address : public dba::Storeable { 
     834struct storeBug1Address : public dba::Storeable { 
    835835  DECLARE_STORE_TABLE(); 
    836836  std::string mData; 
    837837}; 
    838838 
    839 BEGIN_STORE_TABLE(Address,dba::Storeable,"address") 
     839BEGIN_STORE_TABLE(storeBug1Address,dba::Storeable,"address") 
    840840  BIND_STR(mData,dba::String,"data") 
    841841END_STORE_TABLE() 
    842842 
    843 struct Patient : public dba::Storeable { 
     843struct storeBug1Patient : public dba::Storeable { 
    844844  DECLARE_STORE_TABLE(); 
    845   Address mAddress; 
    846 }; 
    847  
    848 BEGIN_STORE_TABLE(Patient,dba::Storeable,"patient") 
     845  storeBug1Address mAddress; 
     846}; 
     847 
     848BEGIN_STORE_TABLE(storeBug1Patient,dba::Storeable,"patient") 
    849849  BIND_COL(mAddress,dba::Single,NULL) 
    850850END_STORE_TABLE() 
    851851 
    852852 
    853 struct Report : public dba::Storeable { 
     853struct storeBug1Report : public dba::Storeable { 
    854854  DECLARE_STORE_TABLE(); 
    855855}; 
    856856 
    857 BEGIN_STORE_TABLE(Report,dba::Storeable,"report") 
     857BEGIN_STORE_TABLE(storeBug1Report,dba::Storeable,"report") 
    858858END_STORE_TABLE() 
    859859 
    860 struct Request : public dba::Storeable { 
     860struct storeBug1Request : public dba::Storeable { 
    861861  DECLARE_STORE_TABLE(); 
    862   Patient mPatient; 
    863   Report mReport; 
    864 }; 
    865  
    866 BEGIN_STORE_TABLE(Request,dba::Storeable,"request") 
     862  storeBug1Patient mPatient; 
     863  storeBug1Report mReport; 
     864}; 
     865 
     866BEGIN_STORE_TABLE(storeBug1Request,dba::Storeable,"request") 
    867867  BIND_COL(mReport,dba::Single,NULL) 
    868868  BIND_COL(mPatient,dba::Single,NULL) 
     
    886886    unlink("storebug1.xml"); 
    887887    ar.open("storebug1.xml"); 
    888     Request obj1; 
     888    storeBug1Request obj1; 
    889889    dba::XMLOStream stream(ar.getOStream()); 
    890890    stream.enableDebug(); 
     
    895895}; 
    896896 
     897struct storeBug2Address : public dba::Storeable { 
     898  storeBug2Address(const std::string& pData) : mData(pData) {}; 
     899  std::string mData; 
     900  DECLARE_STORE_TABLE(); 
     901}; 
     902 
     903BEGIN_STORE_TABLE(storeBug2Address,dba::Storeable,"address") 
     904  BIND_STR(mData,dba::String,"addressdata") 
     905END_STORE_TABLE() 
     906 
     907struct storeBug2Patient : public dba::Storeable { 
     908  storeBug2Patient() : mAddress("patient address") {}; 
     909  storeBug2Address mAddress; 
     910  DECLARE_STORE_TABLE(); 
     911}; 
     912 
     913BEGIN_STORE_TABLE(storeBug2Patient,dba::Storeable,"patient") 
     914  BIND_COL(mAddress,dba::Single,NULL) 
     915END_STORE_TABLE() 
     916 
     917struct storeBug2Request : public dba::Storeable { 
     918  storeBug2Request() : mData("request data"), mAddress("request address") {}; 
     919  storeBug2Patient mPatient; 
     920  storeBug2Address mAddress; 
     921  std::string mData; 
     922  DECLARE_STORE_TABLE(); 
     923}; 
     924 
     925BEGIN_STORE_TABLE(storeBug2Request,dba::Storeable,"request") 
     926  BIND_STB(mAddress) 
     927  BIND_COL(mPatient,dba::Single,NULL) 
     928  BIND_STR(mData,dba::String,"requestdata") 
     929END_STORE_TABLE() 
     930 
     931void 
     932XMLTestCase::storeBug2() { 
     933  const char* result =  
     934"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
     935"<request>\n" 
     936"  <addressdata>request address</addressdata>\n" 
     937"  <patient>\n" 
     938"    <address>\n" 
     939"      <addressdata>patient address</addressdata>\n" 
     940"    </address>\n" 
     941"  </patient>\n" 
     942"  <requestdata>request data</requestdata>\n" 
     943"</request>\n" 
     944; 
     945  { 
     946    dba::XMLArchive ar; 
     947    ar.setRootNodeName(NULL); 
     948    ar.useElements(); 
     949    unlink("storebug2.xml"); 
     950    ar.open("storebug2.xml"); 
     951    storeBug2Request obj1; 
     952    dba::XMLOStream stream(ar.getOStream()); 
     953    stream.enableDebug(); 
     954    stream.open(); 
     955    stream.put(&obj1); 
     956  } 
     957  CPPUNIT_ASSERT(compareXML("storebug2.xml",result)); 
     958}; 
     959 
    897960} //namespace 
    898961 
  • trunk/dba/test/xmltestcase.h

    r174 r175  
    5353      CPPUNIT_TEST(loadFromElements); 
    5454      CPPUNIT_TEST(storeToElements); 
    55       CPPUNIT_TEST(storeBug1); 
     55      CPPUNIT_TEST(storeBug2); 
    5656    CPPUNIT_TEST_SUITE_END(); 
    5757  public: 
     
    9191    void storeToElements(); 
    9292    void storeBug1(); 
     93    void storeBug2(); 
    9394  private: 
    9495    bool compareXML(const char* pFilename, const char* pData);