X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FcreaImageIOSQLiteTreeHandler.cpp;h=562aa6d2a4c3b3ebf048e9cf2651246903bc1b85;hb=e512772003e71d7505c469967730c9e6b562e9a0;hp=627db08f7465afd4321302687a5d527d3affee6d;hpb=3a22e19184c369b130d4caa992a8e98e50c7a0ee;p=creaImageIO.git diff --git a/src/creaImageIOSQLiteTreeHandler.cpp b/src/creaImageIOSQLiteTreeHandler.cpp index 627db08..562aa6d 100644 --- a/src/creaImageIOSQLiteTreeHandler.cpp +++ b/src/creaImageIOSQLiteTreeHandler.cpp @@ -1,7 +1,34 @@ +/* +# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Santé) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ +*/ + + #include #include #include -#include #include "CppSQLite3.h" @@ -44,7 +71,8 @@ namespace creaImageIO //===================================================================== bool SQLiteTreeHandler::Open(bool writable) { - // std::cout << "***> SQLiteTreeHandler::Open('"<execDML("PRAGMA synchronous=ON "); if (parent==0) parent = GetTree().GetTree(); return DBLoadChildren(parent,maxlevel); } @@ -239,6 +268,7 @@ namespace creaImageIO try { mDB->open(GetFileName().c_str()); + mDB->execDML("pragma synchronous=off;"); } catch (CppSQLite3Exception& e) { @@ -283,7 +313,7 @@ namespace creaImageIO << e.errorMessage() <execDML("pragma synchronous=off;"); // CREATING TABLES @@ -321,6 +351,7 @@ namespace creaImageIO command += "\n)"; UPDATEDB(command); + GetTree().CopyAttributeDescriptorList(l); // Add Attribute 'ID' to Description GetTree().GetDescriptor().Add @@ -500,6 +531,7 @@ namespace creaImageIO return false; } + GetTree().CopyAttributeDescriptorList(level); } @@ -659,7 +691,7 @@ GimmickDebugMessage(1, "query : '" <lastRowId(); + //long lastrow = mDB->lastRowId(); std::stringstream ri; ri << mDB->lastRowId(); n->SetAttribute("ID",ri.str()); @@ -767,7 +799,7 @@ GimmickDebugMessage(1, "query : '" <GetAttribute("ID"); sql +="'"; @@ -804,21 +836,10 @@ GimmickDebugMessage(1, "query : '" <GetLevel()).GetName(); - + query += GetTree().GetLevelDescriptor(node->GetLevel()).GetName(); query += " WHERE ID='"+ node->GetAttribute("ID") + "';"; - - UPDATEDB(query); - GimmickDebugMessage(2, - " Deleting '" - <GetLabel()<<"' with ID '" - <GetAttribute("ID") - <<"' in level "<< GetTree().GetLevelDescriptor(node->GetLevel()).GetName() - <GetNumberOfChildren()!=0) { Node::ChildrenListType::iterator i; @@ -954,36 +975,135 @@ GimmickDebugMessage(1, "query : '" < &i_results) { int level=GetTree().GetNumberOfLevels()-1; - std::string sp=searchParam.c_str(); - std::string sv=searchValue.c_str(); + + std::string search = i_filename; + std::string param = "FullFileName"; + std::string name; + std::string id; + std::set pid; + std::vector attr; + std::vector::iterator it_attr; + std::vector values; + std::vector::iterator it_val; + + + + while(level>1) { - std::stringstream out; - std::stringstream results; - out<<"SELECT PARENT_ID FROM "< values; + GetUpLevelNodeId(level, param,search,id); + GetAttributes(name, param,search,attr, values); + for(it_attr = attr.begin(), it_val = values.begin(); it_attr != attr.end(); it_attr++, it_val++) + { + i_results[(*it_attr).GetKey()] = (*it_val).c_str(); + } + search = id; + param = "ID"; + level --; + } + } + + +//===================================================================== +// get selected attributes from database for a given file + void SQLiteTreeHandler::GetAttributes(std::string name, std::string i_id, std::string i_value, tree::LevelDescriptor::AttributeDescriptorListType i_attr, std::vector &i_results) + { + //SELECT t1.ArtistName,CDs.Title FROM Artists t1, CDs WHERE t1.ArtistID=CDs.ArtistID + std::stringstream out; + std::stringstream results; + out<<"SELECT "; + tree::LevelDescriptor::AttributeDescriptorListType::iterator it = i_attr.begin(); + std::string query =""; + for(; it != i_attr.end(); it++) + { + query += (*it).GetKey(); + query +=" ,"; + } + query = query.substr(0, query.size()-1); + out << query; + out << "FROM "<1) + { + GetUpLevelNodeId(level, sp, sv, parent_id); + level--; + sp = "ID"; + sv = parent_id; + } +///* +// std::stringstream out; +// std::stringstream results; +// out<<"SELECT PARENT_ID FROM "<