]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOSQLiteTreeHandler.cpp
Big correction in Database query
[creaImageIO.git] / src2 / creaImageIOSQLiteTreeHandler.cpp
index f29a8ce7ef4b7ced02410167684d1b1405cfef16..627db08f7465afd4321302687a5d527d3affee6d 100644 (file)
@@ -1,25 +1,19 @@
 #include <creaImageIOSQLiteTreeHandler.h>
 #include <creaImageIOSystem.h>
+#include <creaImageIOGimmick.h>
+#include <creaImageIOTree.h>
 
 #include "CppSQLite3.h"
 
 #include <sys/stat.h>
 
-//#include <creaImageIOSQLiteTreeHandlerStructure.h>
-
-//#include <creaImageIOUtilities.h>
-
-//#include <icons/database.xpm>
-
 #include <deque>
 
-//#include <icons/close.xpm>
-
 #include <creaWx.h>
+#include <boost/algorithm/string.hpp>
 using namespace crea;
 
-#include <boost/filesystem.hpp>
-#include <boost/algorithm/string/replace.hpp>
+
 
 namespace creaImageIO
 {
@@ -32,8 +26,7 @@ namespace creaImageIO
   {
     mDB = new CppSQLite3DB;
        mIsAdding=false;
-    GimmickMessage(1,"SQLite version : "
-                  <<std::string(mDB->SQLiteVersion())<< std::endl);
+    //GimmickMessage(1,"SQLite version : "                <<std::string(mDB->SQLiteVersion())<< std::endl);
   }
   //=============================================================
 
@@ -362,8 +355,7 @@ namespace creaImageIO
        command += "Flags int\n";           
        command += "\n)";
        UPDATEDB(command);
-       
-       
+
        // Fill the table *_ATTRIBUTES
        LevelDescriptor::AttributeDescriptorListType::const_iterator i;
        for (i  = GetTree().GetAttributeDescriptorList(l).begin();
@@ -510,7 +502,7 @@ namespace creaImageIO
          }
       }
 
-
+       
     // Create the attributes table for Root (i.e. Tree)
     LevelDescriptor::AttributeDescriptorListType::const_iterator a;
     for (a = GetTree().GetAttributeDescriptorList(0).begin();
@@ -541,22 +533,21 @@ namespace creaImageIO
 
   //========================================================================
   /// 
-  std::string& SQLformat(std::string& str)
+  void SQLformat(std::string i_str, std::string &o_str)
   {
-    // quote must be doubled
-    boost::algorithm::replace_all(str,"'","''");
-    // Found strange strings which contained NULL char INSIDE string 
-    int i,size=str.size();
-    for (i=0;i<size;++i) 
-      {
-       if (str[i]==0) 
-         {
-           str = str.substr(0,i);
-           break;
-         }
-      }
-    //    if (i<str.size())
-    return str;
+               // quote must be doubled
+               boost::algorithm::replace_all(i_str,"'","''");
+               // Found strange strings which contained NULL char INSIDE string 
+               int i,size=i_str.size();
+               for (i=0;i<size;++i) 
+               {
+                       if (i_str[i]==0) 
+                       {
+                               i_str = i_str.substr(0,i);
+                               break;
+                         }
+               }
+               o_str = i_str;
   }
   //========================================================================
   
@@ -567,6 +558,7 @@ namespace creaImageIO
     GimmickMessage(4,"SQLAppendAttributesValues"<<std::endl);
     std::string atts="";
     std::string values="";
+       std::string out ="";
     tree::Node::AttributeMapType::iterator i;
     for (i =  n->GetAttributeMap().begin();
         i != n->GetAttributeMap().end();
@@ -578,7 +570,8 @@ namespace creaImageIO
          }
 
        atts += "'" + i->first + "'";
-       values += "'" + SQLformat(i->second) + "'"; 
+       SQLformat(i->second, out);
+       values += "'" + out + "'"; 
        atts += ",";
        values += ",";
        GimmickMessage(4,"'"<<i->first<<"' = '"<<i->second<<"'"<<std::endl);
@@ -662,6 +655,7 @@ namespace creaImageIO
        query += " WHERE PARENT_ID='" + node->GetAttribute("ID") 
          + "'";
       }
+GimmickDebugMessage(1,                                 "query : '"                         <<query                                         <<std::endl);
     CppSQLite3Query q;
     QUERYDB(query,q);
 
@@ -811,7 +805,9 @@ namespace creaImageIO
        
     std::string query = "DELETE FROM ";
    
-    query += GetTree().GetLevelDescriptor(node->GetLevel()).GetName();
+
+       query += GetTree().GetLevelDescriptor(node->GetLevel()).GetName();
+       
     query += " WHERE ID='"+ node->GetAttribute("ID") + "';";
  
     UPDATEDB(query);