30 #include <boost/filesystem.hpp>
31 #include <boost/algorithm/string.hpp>
43 #define QUERYSYNCDB(QUER,RES) \
46 RES = mDB->execQuery(QUER.c_str()); \
48 catch (CppSQLite3Exception& e) \
50 GimmickError("SQLite query '"<<QUER<<"' Error : " \
51 << e.errorCode() << ":" \
52 << e.errorMessage() ); \
55 #define UPDATESYNCDB(UP) \
58 mDB->execDML(UP.c_str()); \
60 catch (CppSQLite3Exception& e) \
62 GimmickError("SQLite update '"<<UP<<"' Error : " \
63 << e.errorCode() << ":" \
64 << e.errorMessage() ); \
70 pathDB = path +
"maintenance_database.db3";
84 if (!boost::filesystem::exists(
pathDB))
113 command =
"CREATE TABLE ";
114 command +=
"ADD_OPS";
115 command +=
"\n(\nADD_KEY INTEGER PRIMARY KEY";
116 command +=
",\nPATH text";
117 command +=
",\nRECURSIVE boolean";
118 command +=
",\nFILES_ADDED int";
119 command +=
",\nREFERENCEDDB text";
123 command =
"CREATE TABLE ";
124 command +=
"IGNORED_FILES";
125 command +=
"\n(\nID INTEGER PRIMARY KEY";
126 command +=
",\nADD_KEY integer";
127 command +=
",\nPATH text";
128 command +=
",\nREMOVE boolean";
129 command +=
",\nTIME datetext";
140 pos = str.find(
'\\');
143 str.replace(pos, 1,
"/");
165 std::string query =
"SELECT * FROM ADD_OPS WHERE REFERENCEDDB = '"+refdb+
"';";
184 std::string query =
"DELETE FROM " + i_table +
" WHERE ADD_KEY = '" + i_key +
"'";
197 const std::string i_attribute,
198 const std::string i_operand,
199 const std::string i_val)
201 std::stringstream query;
202 query<<
"DELETE FROM "<<i_table<<
" WHERE "<<i_attribute<<
" "<<i_operand<<
" '"<<i_val<<
"'";
215 std::vector<AddList>::iterator it_add =
mAddList.begin();
216 for(;it_add <
mAddList.end(); ++it_add)
218 if(it_add->nbFiles ==
"0")
237 void Synchronizer::InsertAddOp(
const std::string& path,
const std::string& recursive,
const std::string& nChildren,
const std::string& refdb)
240 std::string pat=path.c_str();
242 insert=
"INSERT INTO ADD_OPS (PATH,RECURSIVE,FILES_ADDED,REFERENCEDDB) VALUES('";
244 insert+=recursive+
"',";
245 insert+=nChildren+
",'";
259 void Synchronizer::InsertIgnoreFile(
const std::string& addKey,
const std::string& path,
const std::string&
remove,
const std::string& time,
const std::string& refdb )
261 std::string pat=path.c_str();
263 std::string
id=
GetAttribute(
"ID",
"IGNORED_FILES",
"PATH",pat,refdb);
264 if(
id.compare(
"")==0)
267 insert=
"INSERT INTO IGNORED_FILES (ADD_KEY,PATH,REMOVE,TIME) VALUES('";
268 insert+=addKey+
"','";
277 std::string ak=
GetAttribute(
"ADD_KEY",
"IGNORED_FILES",
"ID",
id,refdb);
279 std::string parentDB=
GetAttribute(
"*",
"ADD_OPS",
"ADD_KEY",ak,refdb);
281 if(parentDB.compare(
"")==0)
284 insert=
"INSERT INTO IGNORED_FILES (ADD_KEY,PATH,REMOVE,TIME) VALUES('";
285 insert+=addKey+
"','";
294 SetAttribute(
"ADD_KEY",
"IGNORED_FILES",addKey,
"ID",
id,refdb);
296 SetAttribute(
"REMOVE",
"IGNORED_FILES",
remove,
"ID",
id,refdb);
298 SetAttribute(
"TIME",
"IGNORED_FILES",time,
"ID",
id,refdb);
311 std::vector<std::string> i_names;
312 std::string query =
"SELECT * FROM IGNORED_FILES WHERE ADD_KEY = ";
319 if(temp.
remove.compare(
"0")==0)
325 std::vector<RemoveList>::iterator it;
329 i_names.push_back((*it).path);
343 const std::string& table,
344 const std::string& searchParam,
345 const std::string& searchValue,
346 const std::string& refdb)
348 std::stringstream query;
350 std::string sVal=
convert(searchValue.c_str());
352 query<<
"SELECT "<<attribute<<
" FROM "<<table<<
" WHERE "<<searchParam<<
" = '"<<sVal;
353 if(table.compare(
"ADD_OPS")==0)
355 query<<
"' AND REFERENCEDDB = '"<<refdb<<
"';";
381 const std::string& table,
382 const std::string& value,
383 const std::string& searchParam,
384 const std::string& searchValue,
385 const std::string& refdb)
387 std::string val=value.c_str();
388 std::string sVal=
convert(searchValue.c_str());
391 std::string sql =
"UPDATE ";
401 if(table.compare(
"ADD_OPS")==0)
403 sql +=
"' AND REFERENCEDDB = '";
420 std::vector<std::string> i_names;
421 std::vector<std::string> keys;
423 std::string query =
"SELECT ADD_KEY, REFERENCEDDB FROM ADD_OPS";
436 query =
"SELECT PATH, REMOVE FROM IGNORED_FILES WHERE";
439 for (
int i=0; i < keys.size(); i++)
441 query +=
" ADD_KEY = " + keys[i];
444 query = query.substr(0,query.size() - 4);
448 query +=
" ADD_KEY = -1";
455 mList[file] = ignore ==
"0"?
true :
false;
463 std::string name(filename);
464 boost::algorithm::replace_all( name,
"\\" ,
"/");
465 std::map <std::string, bool>::iterator it_list =
mList.begin();
466 for(;it_list !=
mList.end(); it_list++)
468 if(it_list->first == name)
478 std::string temp = i_word;
479 boost::algorithm::replace_all(temp,
"'",
"''");