2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
29 #include <creaImageIOSQLiteTreeHandler.h>
30 #include <creaImageIOSystem.h>
31 #include <creaImageIOGimmick.h>
33 #include "CppSQLite3.h"
40 #include <boost/algorithm/string.hpp>
50 //=============================================================
51 SQLiteTreeHandler::SQLiteTreeHandler(const std::string& filename)
54 mDB = new CppSQLite3DB;
56 //GimmickMessage(1,"SQLite version : " <<std::string(mDB->SQLiteVersion())<< std::endl);
58 //=============================================================
60 //=============================================================
61 SQLiteTreeHandler::~SQLiteTreeHandler()
65 //=============================================================
68 //=====================================================================
71 //=====================================================================
72 bool SQLiteTreeHandler::Open(bool writable)
75 //sqlite3_exec(mDB, "PRAGMA synchronous=OFF ", NULL, 0, &errMsg);
76 SetWritable(writable);
80 //=====================================================================
81 bool SQLiteTreeHandler::Create(bool writable)
83 // std::cout << "***> SQLiteTreeHandler::New('"<<GetFileName()<<"')"<<std::endl;
84 SetWritable(writable);
87 //=====================================================================
90 //=====================================================================
91 bool SQLiteTreeHandler::Close()
95 //=====================================================================
98 //=====================================================================
99 bool SQLiteTreeHandler::Destroy()
104 //=====================================================================
106 //=====================================================================
107 int SQLiteTreeHandler::LoadChildren(tree::Node* parent, int maxlevel)
109 //mDB->execDML("PRAGMA synchronous=ON ");
110 if (parent==0) parent = GetTree().GetTree();
111 return DBLoadChildren(parent,maxlevel);
113 //=====================================================================
118 //=====================================================================
119 void SQLiteTreeHandler::UnLoad(tree::Node* n)
122 //=====================================================================
124 //=====================================================================
125 int SQLiteTreeHandler::AddBranch( const AttributeMapType& attr )
127 tree::Node* parent = DBGetParent(attr);
128 DBGraftToParent(parent,attr);
129 return (parent->GetLevel()+1);
132 //=====================================================================
135 //=====================================================================
136 bool SQLiteTreeHandler::Remove(tree::Node* node)
138 DBRecursiveRemoveNode(node);
140 // std::cout << "DELETE"<<std::endl;
142 tree::Node* parent=node->GetParent();
145 int nC = parent->RemoveChildrenFromList(node);
146 if(nC>0 && parent->GetLevel()>0)
148 std::stringstream out;
150 SetAttribute(parent,"NumberOfChildren",out.str());
159 if(remove&&parent->GetLevel()>0)
163 // std::cout << "DELETE OK"<<std::endl;
167 //=====================================================================
169 //=====================================================================
170 /// Sets an attribute of a Node
171 bool SQLiteTreeHandler::SetAttribute(tree::Node* n,
172 const std::string& key,
173 const std::string& value)
175 if (n==0) n=GetTree().GetTree();
176 return DBSetAttribute(n,key,value);
178 //=====================================================================
179 //=====================================================================
180 /// Sets an attribute
181 void SQLiteTreeHandler::SetAttribute(const std::string& levelDescriptor,
182 const std::string& key,
183 const std::string& value,
184 const std::string& searchParam,
185 const std::string& searchVal)
187 DBSetAttribute(levelDescriptor,key,value,searchParam, searchVal);
189 //=====================================================================
191 void SQLiteTreeHandler::DeleteTuple(std::string levelDescriptor,
192 std::string key, std::string value)
194 DBDelete(levelDescriptor,key,value);
196 //=====================================================================
210 //=====================================================================
211 // SQLite DB specific methods
212 //=====================================================================
217 //=====================================================================
218 char* format_sql(const std::string& s)
220 return sqlite3_mprintf("%q",s.c_str());
222 //=====================================================================
225 //=====================================================================
226 #define QUERYDB(QUER,RES) \
229 GimmickMessage(2,"SQL query: '"<<QUER<<"'"<<std::endl); \
230 RES = mDB->execQuery(QUER.c_str()); \
232 catch (CppSQLite3Exception& e) \
234 GimmickError("SQLite query '"<<QUER<<"' : " \
235 << e.errorCode() << ":" \
236 << e.errorMessage() ); \
239 //=====================================================================
241 //=====================================================================
242 #define UPDATEDB(UP) \
245 GimmickMessage(2,"SQL update: '"<<UP<<"'"<<std::endl); \
246 mDB->execDML(UP.c_str()); \
248 catch (CppSQLite3Exception& e) \
250 GimmickError("SQLite update '"<<UP<<"' Error : " \
251 << e.errorCode() << ":" \
252 << e.errorMessage() ); \
254 //=====================================================================
257 //=====================================================================
258 bool SQLiteTreeHandler::DBOpen()
260 GimmickMessage(1,"Opening SQLite database '"<<GetFileName()
261 <<"' ... "<<std::endl);
263 if (!boost::filesystem::exists(GetFileName()))
270 mDB->open(GetFileName().c_str());
271 mDB->execDML("pragma synchronous=off;");
273 catch (CppSQLite3Exception& e)
275 GimmickError("Opening '"<<GetFileName()<<"' : "
276 << e.errorCode() << ":"
277 << e.errorMessage());
280 // IMPORT TREE DESCRIPTION (AND TEST DB VALIDITY)
281 if (!DBImportTreeDescription())
286 GimmickDebugMessage(1,"Opening SQLite database '"<<GetFileName()
287 <<"' ... OK"<<std::endl);
290 //=====================================================================
292 //=====================================================================
293 bool SQLiteTreeHandler::DBCreate()
295 GimmickMessage(1,"Creating SQLite database '"<<GetFileName()
296 <<"' ... "<<std::endl);
298 if (boost::filesystem::exists(GetFileName()))
300 GimmickError(GetFileName()<<"' : "
301 << "file already exists");
308 mDB->open(GetFileName().c_str());
310 catch (CppSQLite3Exception& e)
312 GimmickError(e.errorCode() << ":"
313 << e.errorMessage() <<std::endl);
316 mDB->execDML("pragma synchronous=off;");
321 // Create LEVELS table
322 command = "create table LEVELS\n";
323 command += "( Name text )\n";
326 // Iterate the Levels
327 for (l=0; l<GetTree().GetNumberOfLevels(); l++)
329 command = "INSERT INTO LEVELS (Name) VALUES ('";
330 command += GetTree().GetLevelDescriptor(l).GetName();
334 // Create table of level (for level>0, i.e. not Root)
337 command = "CREATE TABLE ";
338 command += GetTree().GetLevelDescriptor(l).GetName();
339 command += "\n(\nID INTEGER PRIMARY KEY";
342 command += ",\nPARENT_ID int not null";
344 SQLAppendAttributesDefinition(l,command);
347 command += ",\nconstraint FK_PARENT foreign key (PARENT_ID) references ";
348 command += GetTree().GetLevelDescriptor(l-1).GetName();
349 command += "(ID) on delete restrict on update restrict";
354 GetTree().CopyAttributeDescriptorList(l);
356 // Add Attribute 'ID' to Description
357 GetTree().GetDescriptor().Add
358 (AttributeDescriptor( "ID",
359 "Database Identifier",
361 AttributeDescriptor::PRIVATE
366 // Add Attribute 'PARENT_ID' to Description
367 GetTree().GetDescriptor().Add
368 (AttributeDescriptor( "PARENT_ID",
369 "Database Parent Identifier",
371 AttributeDescriptor::PRIVATE
377 // Create table *_ATTRIBUTES
379 command = "CREATE TABLE ";
380 command += GetTree().GetLevelDescriptor(l).GetName();
381 command += "_Attributes\n(\n";
382 command += "Key text,\n";
383 command += "Name text,\n";
384 command += "DicomGroup int,\n";
385 command += "DicomElement int,\n";
386 command += "Flags int\n";
390 // Fill the table *_ATTRIBUTES
391 LevelDescriptor::AttributeDescriptorListType::const_iterator i;
392 for (i = GetTree().GetAttributeDescriptorList(l).begin();
393 i != GetTree().GetAttributeDescriptorList(l).end();
397 std::stringstream insert;
398 insert << "INSERT INTO "
399 << GetTree().GetLevelDescriptor(l).GetName()
400 << "_Attributes (Key,Name,DicomGroup,DicomElement,Flags) "
402 << i->GetKey() << "','"
403 << i->GetName() << "',"
404 << i->GetGroup() << ","
405 << i->GetElement() << ","
406 << i->GetFlags() << ");";
407 UPDATEDB(insert.str());
412 // Initialize the root attributes
413 GetTree().InitializeAttributeMap();
414 // Insert the root in the level 0 table
415 DBInsert(GetTree().GetTree());
418 GetTree().SetChildrenLoaded(true);
419 GimmickMessage(1,"Creating SQLite database '"<<GetFileName()
420 <<"' ... OK"<<std::endl);
423 //=====================================================================
425 //=====================================================================
426 void SQLiteTreeHandler::SQLAppendAttributesDefinition(int level,
429 LevelDescriptor::AttributeDescriptorListType::const_iterator i;
430 for (i = GetTree().GetAttributeDescriptorList(level).begin();
431 i != GetTree().GetAttributeDescriptorList(level).end();
434 // if (i->second.flags==1) continue;
440 //=====================================================================
443 //=====================================================================
444 bool SQLiteTreeHandler::DBImportTreeDescription()
446 GimmickMessage(1,"Importing tree description for database ..."
449 // Test table 'LEVELS' existence
450 if ( ! mDB->tableExists("LEVELS") )
452 GimmickMessage(1,"!! ERROR : Table 'LEVELS' does not exist"
457 tree::Descriptor& desc = GetTree().GetDescriptor();
458 // clears the existing one
462 std::string query = "SELECT * FROM LEVELS";
468 std::string name = q.getStringField(0);
469 GimmickMessage(2," * Importing level '"<<name<<"'"<<std::endl);
470 desc.Add(LevelDescriptor(name));
475 for (int level = 0; level < nblevel; ++level )
477 std::string table = GetTree().GetLevelDescriptor(level).GetName();
478 table += "_Attributes";
479 // Test table 'LEVELS' existence
480 if ( ! mDB->tableExists(table.c_str()) )
482 GimmickMessage(1,"!! ERROR : Table '"<<table<<"' does not exist"
487 std::string query = "SELECT * FROM ";
492 GimmickMessage(2," * Level '"
493 <<GetTree().GetLevelDescriptor(level).GetName()
496 // Test that ID and PARENT_ID mandatory attributes exist
497 bool ID_found = false;
498 bool PARENT_ID_found = false;
499 if (level==0) ID_found = true;
500 if (level<=1) PARENT_ID_found = true;
504 std::string key(q.getStringField(0));
505 std::string name(q.getStringField(1));
506 GimmickMessage(2," - Importing attribute '"<<key<<"' '"<<name
509 (AttributeDescriptor( key, // Key
511 q.getIntField(2), // Group
512 q.getIntField(3), // Element
513 q.getIntField(4) // Flags
519 if ( key == "PARENT_ID" )
521 PARENT_ID_found = true;
526 if ( ! (ID_found || PARENT_ID_found ) )
528 GimmickMessage(1,"!! ERROR : Table '"<<table
529 <<"' does not contain mandatory attribute ID or PARENT_ID"
534 GetTree().CopyAttributeDescriptorList(level);
538 // Create the attributes table for Root (i.e. Tree)
539 LevelDescriptor::AttributeDescriptorListType::const_iterator a;
540 for (a = GetTree().GetAttributeDescriptorList(0).begin();
541 a!= GetTree().GetAttributeDescriptorList(0).end();
545 GetTree().UnsafeSetAttribute( a->GetKey(), "" );
548 // Reading Root attributes
550 query = "SELECT * FROM ";
551 query += GetTree().GetLevelDescriptor(0).GetName();
554 for (int fld = 0; fld < q.numFields(); fld++)
556 GetTree().UnsafeSetAttribute(q.fieldName(fld),
557 q.getStringField(fld));
560 GimmickMessage(1,"Importing tree description from database ... OK"
564 //=====================================================================
566 //========================================================================
568 void SQLformat(std::string i_str, std::string &o_str)
570 // quote must be doubled
571 boost::algorithm::replace_all(i_str,"'","''");
572 // Found strange strings which contained NULL char INSIDE string
573 int i,size=(int)i_str.size();
578 i_str = i_str.substr(0,i);
584 //========================================================================
586 //=====================================================================
587 void SQLiteTreeHandler::SQLAppendAttributesValues(tree::Node* n,
590 GimmickMessage(4,"SQLAppendAttributesValues"<<std::endl);
592 std::string values="";
594 tree::Node::AttributeMapType::iterator i;
595 for (i = n->GetAttributeMap().begin();
596 i != n->GetAttributeMap().end();
604 atts += "'" + i->first + "'";
605 SQLformat(i->second, out);
606 values += "'" + out + "'";
609 GimmickMessage(4,"'"<<i->first<<"' = '"<<i->second<<"'"<<std::endl);
611 atts[atts.size()-1]=' ';
612 values[values.size()-1]=' ';
614 str = "("+atts+") VALUES ("+values+")";
615 GimmickMessage(4,"Result = '"<<str<<"'"<<std::endl);
617 //=====================================================================
619 //=====================================================================
620 tree::Node* SQLiteTreeHandler::DBGetParent( const AttributeMapType& attr)
622 Node* parent = GetTree().GetTree();
627 // Load the children of the current parent
628 DBLoadChildren(parent);
629 // Iterate the children
630 tree::Node::ChildrenListType::const_iterator i;
631 for (i = parent->GetChildrenList().begin();
632 i!= parent->GetChildrenList().end();
635 if ( (*i)->Matches( attr ) )
646 //=====================================================================
648 //=====================================================================
649 int SQLiteTreeHandler::DBLoadChildren(tree::Node* node,
652 if (node->GetLevel()+1 >= node->GetTree()->GetNumberOfLevels() )
655 GimmickMessage(2,"Loading children of '"<<node->GetLabel()
659 // If children loaded we do not have to do it but we need to recurse
660 // in order to load the children's children if necessary, and so on...
661 if (node->GetChildrenLoaded())
663 // Iterate the children
665 tree::Node::ChildrenListType::iterator i;
666 for (i = node->GetChildrenList().begin();
667 i!= node->GetChildrenList().end();
670 nbloaded += DBLoadChildren(*i,numberoflevels-1);
672 node->SetChildrenLoaded(true);
678 /// If children not loaded : do it and recurse
681 int level = node->GetLevel();
682 std::string query = "SELECT * FROM ";
684 query += GetTree().GetLevelDescriptor(level+1).GetName();
687 query += " WHERE PARENT_ID='" + node->GetAttribute("ID")
690 GimmickDebugMessage(1, "query : '" <<query <<std::endl);
698 // std::cout << "DBLoadCh : creating node level "<<level+1<<std::endl;
701 Node* n = new Node(node);
702 for (int fld = 0; fld < q.numFields(); fld++)
704 n->UnsafeSetAttribute(q.fieldName(fld),q.getStringField(fld));
708 if ( numberoflevels != 1 )
711 nbloaded += DBLoadChildren(n, numberoflevels-1);
718 node->SetChildrenLoaded(true);
725 //=====================================================================
727 //======================================================================
728 void SQLiteTreeHandler::DBInsert(tree::Node* n)
730 GimmickMessage(2,"Inserting in DB '"<<n->GetLabel()
733 SQLAppendAttributesValues(n,val);
734 std::string insert("INSERT INTO ");
735 insert += GetTree().GetLevelDescriptor(n->GetLevel()).GetName();
736 insert += " " + val + ";";
740 // Store DB id of newly created node;
741 //long lastrow = mDB->lastRowId();
742 std::stringstream ri;
743 ri << mDB->lastRowId();
744 n->SetAttribute("ID",ri.str());
746 //======================================================================
748 //======================================================================
749 /// Graft the branch defined by the attributes to the parent
750 void SQLiteTreeHandler::DBGraftToParent( tree::Node* parent,
751 const AttributeMapType& attr)
753 // std::cout <<"Grafting to parent '"<<parent->GetLabel()
756 for (int level = parent->GetLevel()+1;
757 level < GetTree().GetNumberOfLevels();
761 tree::Node* child = new tree::Node(parent,attr);
762 child->SetChildrenLoaded(true);
765 int nc = GetNumberOfChildren(parent)+1;
767 // std::cout<<"Number of children "<<parent->GetNumberOfChildren()<<std::endl;
768 std::stringstream out;
770 SetAttribute(parent,"NumberOfChildren",out.str());
773 // Set PARENT_ID if necessary
774 if ( parent->GetLevel()>0 )
775 child->SetAttribute("PARENT_ID",parent->GetAttribute("ID"));
784 //======================================================================
787 //=====================================================================
788 /// Sets an attribute of a Node
789 bool SQLiteTreeHandler::DBSetAttribute(tree::Node* n,
790 const std::string& key,
791 const std::string& value)
793 GimmickMessage(3,"Setting Attribute of '"<<n->GetLabel()<<
794 "' "<<key<<"='"<<value<<"'"<<std::endl);
796 n->SetAttribute(key,value);
797 std::string sql = "UPDATE ";
798 sql += GetTree().GetLevelDescriptor(n->GetLevel()).GetName();
802 sql += convert(value);
803 sql += "' WHERE ID = '";
804 sql += n->GetAttribute("ID");
806 // sql += " LIMIT 1";
811 //=====================================================================
812 /// Sets an attribute of a Node
813 void SQLiteTreeHandler::DBSetAttribute(const std::string& levelDescriptor,
814 const std::string& key,
815 const std::string& value,
816 const std::string& searchParam,
817 const std::string& searchVal)
820 std::string sql = "UPDATE ";
821 sql += levelDescriptor;
831 std::cout<<sql<<std::endl;
834 //=====================================================================
835 void SQLiteTreeHandler::DBRecursiveRemoveNode(Node* node)
838 std::string query = "DELETE FROM ";
839 query += GetTree().GetLevelDescriptor(node->GetLevel()).GetName();
840 query += " WHERE ID='"+ node->GetAttribute("ID") + "';";
843 if(node->GetNumberOfChildren()!=0)
845 Node::ChildrenListType::iterator i;
846 for (i = node->GetChildrenList().begin();
847 i != node->GetChildrenList().end();
850 DBRecursiveRemoveNode((*i));
853 else if(node->GetLevel()<GetTree().GetNumberOfLevels()-1)
855 DBRecursiveRemoveNode(node->GetLevel()+1,node->GetAttribute("ID"));
859 //=====================================================================
860 void SQLiteTreeHandler::DBRecursiveRemoveNode(int level, std::string parentId)
862 std::stringstream out;
863 std::stringstream result;
864 out<<"SELECT ID FROM "<<GetTree().GetLevelDescriptor(level).GetName()<<" WHERE PARENT_ID='"<<parentId<<"'";
867 QUERYDB(out.str(),q);
871 for (int fld = 0; fld < q.numFields(); fld++)
873 result<<q.getStringField(fld)<<"#";
877 std::string res=result.str();
880 while(fin<res.size()-1)
882 fin=res.find('#',ini);
883 DBDelete(GetTree().GetLevelDescriptor(level).GetName(),"ID",res.substr(ini,fin-ini));
884 if(level<GetTree().GetNumberOfLevels()-1)
886 DBRecursiveRemoveNode(level+1,res.substr(ini,fin-ini));
894 //=====================================================================
895 void SQLiteTreeHandler::DBDelete(std::string levelDescriptor, std::string key, std::string value)
898 std::stringstream query;
899 query<<"DELETE FROM "<<levelDescriptor<<" WHERE "<<key<<"='"<<value<<"';";
901 UPDATEDB(query.str());
902 GimmickDebugMessage(2," Deleting: Query: "<<query.str()<<std::endl);
906 //=====================================================================
907 void SQLiteTreeHandler::GetAttribute(std::string levelDescriptor,
908 std::string searchParam,
909 std::string searchVal,
913 std::stringstream out;
914 std::stringstream results;
915 out<<"SELECT "<<key<<" FROM "<<levelDescriptor;
918 out<<" WHERE "<<searchParam<<"='"<<searchVal<<"'";
922 QUERYDB(out.str(),q);
927 for (int fld = 0; fld < q.numFields(); fld++)
929 results<<q.getStringField(fld);
937 result=results.str();
940 //=====================================================================
941 unsigned int SQLiteTreeHandler::GetNumberOfChildren(tree::Node* n)
945 int level = n->GetLevel();
947 if(level<GetTree().GetNumberOfLevels()&& level>0)
949 std::string query = "SELECT NumberOfChildren FROM ";
950 query += GetTree().GetLevelDescriptor(level).GetName();
953 query += " WHERE ID='" + n->GetAttribute("ID")
962 for (int fld = 0; fld < q.numFields(); fld++)
964 nb=q.getIntField(fld);
978 //=====================================================================
979 // get all attributes from database for a given file
980 void SQLiteTreeHandler::getAllAttributes(std::string i_filename, std::map<std::string, std::string> &i_results)
982 int level=GetTree().GetNumberOfLevels()-1;
984 std::string search = i_filename;
985 std::string param = "FullFileName";
989 std::set<std::string> pid;
990 std::vector<AttributeDescriptor> attr;
991 std::vector<AttributeDescriptor>::iterator it_attr;
992 std::vector<std::string> values;
993 std::vector<std::string>::iterator it_val;
997 attr = GetTree().GetAttributeDescriptorList(level,1);
999 name = GetTree().GetLevelDescriptor(level).GetName();
1000 std::vector<std::string> values;
1002 //EED 2018-04-13 GetUpLevelNodeId(level, param,search,id);
1005 GetUpLevelNodeId(level, param,search,id);
1007 GetAttributes(name, param,search,attr, values);
1008 for(it_attr = attr.begin(), it_val = values.begin(); it_attr != attr.end(); it_attr++, it_val++)
1010 i_results[(*it_attr).GetKey()] = (*it_val).c_str();
1019 //=====================================================================
1020 // get selected attributes from database for a given file
1021 void SQLiteTreeHandler::GetAttributes(std::string name, std::string i_id, std::string i_value, tree::LevelDescriptor::AttributeDescriptorListType i_attr, std::vector<std::string> &i_results)
1023 //SELECT t1.ArtistName,CDs.Title FROM Artists t1, CDs WHERE t1.ArtistID=CDs.ArtistID
1024 std::stringstream out;
1025 std::stringstream results;
1027 tree::LevelDescriptor::AttributeDescriptorListType::iterator it = i_attr.begin();
1028 std::string query ="";
1029 for(; it != i_attr.end(); it++)
1031 query += (*it).GetKey();
1034 query = query.substr(0, query.size()-1);
1036 out << "FROM "<<name;
1037 out<<" WHERE "<<i_id <<"='"<<i_value<<"'";
1039 QUERYDB(out.str(),q);
1042 for (int fld = 0; fld < q.numFields(); fld++)
1044 i_results.push_back(q.getStringField(fld));
1050 void SQLiteTreeHandler::GetUpLevelNodeId(int level, const std::string& searchParam, const std::string& searchValue, std::string& parent_id)
1052 std::string sp=searchParam.c_str();
1053 std::string sv=searchValue.c_str();
1054 std::stringstream out;
1055 std::stringstream results;
1056 out<<"SELECT PARENT_ID FROM "<<GetTree().GetLevelDescriptor(level).GetName();
1057 out<<" WHERE "<<sp<<"='"<<sv<<"'";
1059 QUERYDB(out.str(),q);
1062 for (int fld = 0; fld < q.numFields(); fld++)
1064 results<<q.getStringField(fld);
1068 parent_id = results.str();
1072 //=====================================================================
1073 void SQLiteTreeHandler::GetTopLevelNodeId(const std::string& searchParam, const std::string& searchValue, std::string& parent_id)
1075 int level=GetTree().GetNumberOfLevels()-1;
1076 std::string sp=searchParam.c_str();
1077 std::string sv=searchValue.c_str();
1081 GetUpLevelNodeId(level, sp, sv, parent_id);
1087 // std::stringstream out;
1088 // std::stringstream results;
1089 // out<<"SELECT PARENT_ID FROM "<<GetTree().GetLevelDescriptor(level).GetName();
1090 // out<<" WHERE "<<sp<<"='"<<sv<<"'";
1091 // CppSQLite3Query q;
1092 // QUERYDB(out.str(),q);
1097 // for (int fld = 0; fld < q.numFields(); fld++)
1099 // results<<q.getStringField(fld);
1105 // sv=results.str();
1111 //=====================================================================
1112 void SQLiteTreeHandler::RemoveEntries(const std::string i_table,
1113 const std::string i_attribute,
1114 const std::string i_operand,
1115 const std::string i_val)
1117 std::stringstream query;
1118 query<<"DELETE FROM "<<i_table<<" WHERE "<<i_attribute<<" "<<i_operand<<" '"<<i_val<<"'";
1119 UPDATEDB(query.str());
1122 //=====================================================================
1123 void SQLiteTreeHandler::BeginTransaction()
1125 std::stringstream out;
1126 out<<"begin transaction;";
1127 UPDATEDB(out.str());
1130 //=====================================================================
1131 void SQLiteTreeHandler::EndTransaction()
1133 std::stringstream out;
1134 out<<"commit transaction;";
1135 UPDATEDB(out.str());
1137 const std::string SQLiteTreeHandler::convert(const std::string &i_word)
1139 std::string temp = i_word;
1140 boost::algorithm::replace_all(temp,"'","''");
1141 return temp.c_str();
1144 } // namespace creaImageIO