X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src2%2FcreaImageIOSynchron.cpp;h=f7e1807b0908b5a0ff82324c3fef40004d0bc89e;hb=e4a54c9026a2a0c17e3be0b5915c34688a9385ad;hp=3bd73e433107d16cfbcf2fb4be9d0375e25ab60f;hpb=48959b03ebd4e0d100f468f6c05c873f70b43516;p=creaImageIO.git diff --git a/src2/creaImageIOSynchron.cpp b/src2/creaImageIOSynchron.cpp index 3bd73e4..f7e1807 100644 --- a/src2/creaImageIOSynchron.cpp +++ b/src2/creaImageIOSynchron.cpp @@ -1,8 +1,9 @@ #include #include #include +#include +//namespace fs = boost::filesystem; -namespace fs = boost::filesystem; //===================================================================== @@ -10,41 +11,41 @@ namespace fs = boost::filesystem; namespace creaImageIO { - //===================================================================== - #define QUERYSYNCDB(QUER,RES) \ + //===================================================================== + #define QUERYSYNCDB(QUER,RES) \ try \ - { \ + { \ RES = mDB->execQuery(QUER.c_str()); \ - } \ + } \ catch (CppSQLite3Exception& e) \ { \ GimmickError("SQLite query '"<execDML(UP.c_str()); \ } \ - catch (CppSQLite3Exception& e) \ + catch (CppSQLite3Exception& e) \ { \ GimmickError("SQLite update '"<open(pathDB.c_str()); // CREATING TABLES std::string command; - command = "CREATE TABLE "; - command += "ADD_OPS"; - command += "\n(\nADD_KEY INTEGER PRIMARY KEY"; - command += ",\nPATH text"; - command += ",\nRECURSIVE boolean"; - command += ",\nFILES_ADDED int"; - command += ",\nREFERENCEDDB text"; - command += "\n)"; - UPDATESYNCDB(command); + command = "CREATE TABLE "; + command += "ADD_OPS"; + command += "\n(\nADD_KEY INTEGER PRIMARY KEY"; + command += ",\nPATH text"; + command += ",\nRECURSIVE boolean"; + command += ",\nFILES_ADDED int"; + command += ",\nREFERENCEDDB text"; + command += "\n)"; + UPDATESYNCDB(command); - command = "CREATE TABLE "; - command += "IGNORED_FILES"; - command += "\n(\nID INTEGER PRIMARY KEY"; - command += ",\nADD_KEY integer"; - command += ",\nPATH text"; - command += ",\nREMOVE boolean"; - command += ",\nTIME datetext"; - command += "\n)"; - UPDATESYNCDB(command); + command = "CREATE TABLE "; + command += "IGNORED_FILES"; + command += "\n(\nID INTEGER PRIMARY KEY"; + command += ",\nADD_KEY integer"; + command += ",\nPATH text"; + command += ",\nREMOVE boolean"; + command += ",\nTIME datetext"; + command += "\n)"; + UPDATESYNCDB(command); } //===================================================================== @@ -118,35 +119,35 @@ namespace creaImageIO } //===================================================================== - void Synchronizer::GetFileList(std::vector & list, const std::string& refdb) + void Synchronizer::GetFileList(std::vector & list, const std::string& refdb) { CleanList(refdb); - list=mAddList; + list=mAddList; } //===================================================================== - void Synchronizer::GetIgnoredFiles(const std::string& key, std::vector &ignoreList) - { + void Synchronizer::GetIgnoredFiles(const std::string& key, std::vector &ignoreList) + { ignoreList=GetIgnoreList(key); - } + } - //===================================================================== - void Synchronizer::UpdateAddList(const std::string& refdb) +//===================================================================== + void Synchronizer::UpdateAddList(const std::string& refdb) { std::string query = "SELECT * FROM ADD_OPS WHERE REFERENCEDDB = '"+refdb+"';"; CppSQLite3Query res; QUERYSYNCDB(query, res); - while (!res.eof()) + while (!res.eof()) { - AddList temp = AddList(res); + AddList temp = AddList(res); mAddList.push_back(temp); - res.nextRow(); + res.nextRow(); } - } + } ///////////////////////////////////////////////////////////////////////////////////////////////// // remove an entry of the DB - //@param i_table : table where do the remove + //@param i_table : table where to do the remove // @param i_key : the add_key reference (one entry to remove for ADD_OP table, many for IGNORED_FILES table //@result : - ///////////////////////////////////////////////////////////////////////////////////////////////// @@ -154,6 +155,24 @@ namespace creaImageIO { std::string query = "DELETE FROM " + i_table + " WHERE ADD_KEY = '" + i_key +"'"; UPDATESYNCDB(query); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // remove several entries of the DB + // @param i_table : table where to do the remove + // @param i_attribute: attribute to match + // @param i_operand : operand to use + // @param i_val : the reference + //@result : - + ///////////////////////////////////////////////////////////////////////////////////////////////// + void Synchronizer::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 "<::iterator it_add = mAddList.begin(); for(;it_add nbFiles == "0") { - RemoveEntry("ADD_OPS", it_add->key); - RemoveEntry("IGNORED_FILES", it_add->key); - + RemoveEntry("ADD_OPS", it_add->key); + RemoveEntry("IGNORED_FILES", it_add->key); + } } mAddList.clear(); UpdateAddList(refdb); } - ///////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////// // Inserts a new add operation in the database // @param path: the path of the directory that was added - // @param recursive: shows if the action was called recursively or not - // @param nChildren: the number of files affected by the operation - // @param refdb: the referenced database + // @param recursive: shows if the action was called recursively or not + // @param nChildren: the number of files affected by the operation + // @param refdb: the referenced database // @result : The operation has been added ///////////////////////////////////////////////////////////////////////////////////////////////// - void Synchronizer::InsertAddOp(const std::string& path, const std::string& recursive, const std::string& nChildren, const std::string& refdb) + void Synchronizer::InsertAddOp(const std::string& path, const std::string& recursive, const std::string& nChildren, const std::string& refdb) { std::string insert; std::string pat=path.c_str(); @@ -195,7 +214,7 @@ namespace creaImageIO insert="INSERT INTO ADD_OPS (PATH,RECURSIVE,FILES_ADDED,REFERENCEDDB) VALUES('"; insert+=pat+"','"; insert+=recursive+"',"; - insert+=nChildren+",'"; + insert+=nChildren+",'"; insert+=refdb+"');"; UPDATESYNCDB(insert); } @@ -221,10 +240,10 @@ namespace creaImageIO insert+=addKey+"','"; insert+=pat+"','"; insert+=remove+"',"; - insert+=time+");"; + insert+=time+");"; UPDATESYNCDB(insert); } - else + else { //Gets the add key std::string ak=GetAttribute("ADD_KEY","IGNORED_FILES","ID",id,refdb); @@ -238,7 +257,7 @@ namespace creaImageIO insert+=addKey+"','"; insert+=pat+"','"; insert+=remove+"',"; - insert+=time+");"; + insert+=time+");"; UPDATESYNCDB(insert); } else @@ -260,20 +279,20 @@ namespace creaImageIO ///////////////////////////////////////////////////////////////////////////////////////////////// std::vector Synchronizer::GetIgnoreList(const std::string &i_key) { - mIgnoreList.clear(); + mIgnoreList.clear(); std::vector i_names; - std::string query = "SELECT * FROM IGNORED_FILES WHERE ADD_KEY = "; - query+=i_key; + std::string query = "SELECT * FROM IGNORED_FILES WHERE ADD_KEY = "; + query+=i_key; CppSQLite3Query res; QUERYSYNCDB(query, res); - while (!res.eof()) + while (!res.eof()) { - RemoveList temp = RemoveList(res); - if(temp.remove.compare("0")==0) - { - mIgnoreList.push_back(temp); - } - res.nextRow(); + RemoveList temp = RemoveList(res); + if(temp.remove.compare("0")==0) + { + mIgnoreList.push_back(temp); + } + res.nextRow(); } std::vector::iterator it; @@ -281,10 +300,10 @@ namespace creaImageIO { i_names.push_back((*it).path); } - return i_names; + return i_names; } - ///////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////// // Gets the required attribute in the required table // @param attribute: the attribute to look for // @param table: the table to look in @@ -299,33 +318,33 @@ namespace creaImageIO const std::string& refdb) { std::stringstream query; - std::string result; - std::string sVal=searchValue.c_str(); - CleanName(sVal); - query<<"SELECT "< i_names; + std::string query = "SELECT PATH, REMOVE FROM IGNORED_FILES"; + CppSQLite3Query res; + QUERYSYNCDB(query, res); + while (!res.eof()) + { + std::string file(res.getStringField(0)); + std::string ignore(res.getStringField(1)); + mList[file] = ignore == "0"? true : false; + res.nextRow(); + } + } + + bool Synchronizer::isIndexed(const std::string filename) + { + bool valid = true; + std::string name(filename); + boost::algorithm::replace_all( name,"\\" , "/"); + std::map ::iterator it_list = mList.begin(); + for(;it_list != mList.end(); it_list++) { - sql += "' AND REFERENCEDDB = '"; - sql += refdb; + if(it_list->first == name) + { + valid = false; + break; + } } - sql += "';"; - UPDATESYNCDB(sql); - } + return valid; + } } +