]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOSQLiteTreeHandler.cpp
Remove dependencies of WxWidget from Model and Controller class.
[creaImageIO.git] / src2 / creaImageIOSQLiteTreeHandler.cpp
index 6af107d7c27fc023b17de9f0403edf5c2140754b..3d3fe70c1639ad2357a75f628ff63462020a2e9f 100644 (file)
 
 #include <deque>
 
-#include "wx/wx.h"
-#include <wx/dir.h>
-#include <wx/filename.h>
-
-
 //#include <icons/close.xpm>
 
 #include <creaWx.h>
@@ -149,7 +144,7 @@ namespace creaImageIO
     if (parent)
       {
        int nC = parent->RemoveChildrenFromList(node);
-       if(nC>0)
+       if(nC>0 && parent->GetLevel()>0)
        {       
                std::stringstream out;
                out <<nC;
@@ -169,10 +164,6 @@ namespace creaImageIO
     //    std::cout << "DELETE OK"<<std::endl;
     return true;
    }
-
-    //========================================================================
-
-  
   
   //===================================================================== 
 
@@ -335,9 +326,9 @@ namespace creaImageIO
     command = "create table LEVELS\n";
     command += "( Name text )\n";
     UPDATEDB(command);
-    
+    int l;
     // Iterate the Levels
-    for (int l=0; l<GetTree().GetNumberOfLevels(); ++l)
+    for (l=0; l<GetTree().GetNumberOfLevels(); l++)
       {
        command = "INSERT INTO LEVELS (Name) VALUES ('";
        command += GetTree().GetLevelDescriptor(l).GetName();
@@ -874,6 +865,7 @@ namespace creaImageIO
        sql +="'";
     //    sql += " LIMIT 1";
     UPDATEDB(sql);
+       return true;
   }
 
   //===================================================================== 
@@ -896,6 +888,7 @@ namespace creaImageIO
        sql += " = '";
     sql += searchVal;
        sql += "'";
+       std::cout<<sql<<std::endl;
     UPDATEDB(sql);
   }
    //=====================================================================
@@ -975,7 +968,7 @@ namespace creaImageIO
        query<<"DELETE FROM "<<levelDescriptor<<" WHERE "<<key<<"='"<<value<<"';";
  
     UPDATEDB(query.str());
-       GimmickMessage(1," Deleting: Query: "<<query.str()<<std::endl);
+       GimmickDebugMessage(2," Deleting: Query: "<<query.str()<<std::endl);
   }
 
 
@@ -1051,6 +1044,66 @@ namespace creaImageIO
     return nb; 
   }
 
+  //===================================================================== 
+  void SQLiteTreeHandler::GetTopLevelNodeId(const std::string& searchParam, const std::string& searchValue, std::string& parent_id) 
+  {
+         int level=GetTree().GetNumberOfLevels()-1;
+         std::string sp=searchParam.c_str();
+         std::string sv=searchValue.c_str();
+
+         while(level>1)
+         {
+               std::stringstream out;
+               std::stringstream results;
+               out<<"SELECT PARENT_ID FROM "<<GetTree().GetLevelDescriptor(level).GetName();
+               out<<" WHERE "<<sp<<"='"<<sv<<"'";      
+               CppSQLite3Query q;
+               QUERYDB(out.str(),q);
+               
+               
+               while (!q.eof())
+               {
+                       for (int fld = 0; fld < q.numFields(); fld++)
+                       {
+                               results<<q.getStringField(fld);
+                       }
+                       q.nextRow();
+               }
+               level=level-1;
+               sp="ID";
+               sv=results.str();
+         }
+         parent_id=sv;
+
+  }
+
+  //=====================================================================
+  void SQLiteTreeHandler::RemoveEntries(const std::string i_table, 
+               const std::string i_attribute, 
+               const std::string i_operand, 
+               const std::string i_val)
+    {
+        std::stringstream query;
+               query<<"DELETE  FROM "<<i_table<<" WHERE "<<i_attribute<<" "<<i_operand<<" '"<<i_val<<"'";
+        UPDATEDB(query.str());
+       }
+
+       //=====================================================================
+  void SQLiteTreeHandler::BeginTransaction()
+    {
+               std::stringstream out;
+               out<<"begin transaction;";
+        UPDATEDB(out.str());
+       }
+
+       //=====================================================================
+  void SQLiteTreeHandler::EndTransaction()
+    {
+       std::stringstream out;
+               out<<"commit transaction;";
+        UPDATEDB(out.str());
+       }
+
   /*
   //=====================================================================
   bool SQLiteTreeHandler::DBInsert(Node* alien_node,