34 #include <boost/filesystem.hpp>
35 #include <boost/algorithm/string/replace.hpp>
93 #define QUERYTIMESTAMPDB(QUER,RES) \
96 GimmickMessage(2,"SQL query: '"<<QUER<<"'"<<std::endl); \
97 RES = mDB->execQuery(QUER.c_str()); \
99 catch (CppSQLite3Exception& e) \
101 GimmickError("SQLite query '"<<QUER<<"' : " \
102 << e.errorCode() << ":" \
103 << e.errorMessage() ); \
105 //=====================================================================
106 #define UPDATETIMESTAMPDB(UP) \
109 GimmickMessage(2,"SQL update: '"<<UP<<"'"<<std::endl); \
110 mDB->execDML(UP.c_str()); \
112 catch (CppSQLite3Exception& e) \
114 GimmickError("SQLite update '"<<UP<<"' Error : " \
115 << e.errorCode() << ":" \
116 << e.errorMessage() ); \
125 <<
"' ... "<<std::endl);
145 <<
"' ... OK"<<std::endl);
154 <<
"' ... "<<std::endl);
159 <<
"file already exists");
181 command =
"CREATE TABLE ";
183 command +=
"\n(\nID INTEGER PRIMARY KEY";
184 command +=
",\nPARENT_ID int not null";
185 command +=
",\nPATH text";
186 command +=
",\nLastModified datetext";
187 command +=
",\nLastRead datetext";
188 command +=
",\nTopLevelNodeId text";
189 command +=
",\nReferencedDB text";
190 command +=
",\nconstraint FK_PARENT foreign key (PARENT_ID) references ";
192 command +=
"(ID) on delete restrict on update restrict";
208 pos = str.find(
'\\');
211 str.replace(pos, 1,
"/");
214 while ((
int)pos!=-1);
219 const std::string& path,
220 const time_t lastModif,
221 const time_t lastRead,
222 const std::string& refdb)
225 std::string par=parent.c_str();
226 std::string pat=path.c_str();
232 if(parent.compare(
"")==0)
234 if(pathId.compare(
"")==0)
236 AddFile(pat,lastModif,lastRead,refdb);
246 std::string parentId=
IsIndexed(par,refdb);
248 if(parentId.compare(
"")==0)
250 AddFile(par,lastModif,lastRead,refdb);
255 if(pathId.compare(
"")==0)
257 AddFile(parentId,pat,lastModif,lastRead,refdb);
275 std::stringstream out;
276 out<<
"INSERT INTO FILES (PARENT_ID,PATH,LastModified,LastRead,ReferencedDB) VALUES(0,'"<<path<<
"',";
277 out<<lastModif<<
","<<lastRead<<
",'"<<refdb<<
"');";
285 const std::string& path,
286 const time_t lastModif,
287 const time_t lastRead,
288 const std::string& refdb)
290 std::stringstream out;
291 out<<
"INSERT INTO FILES (PARENT_ID,PATH,LastModified,LastRead,ReferencedDB) VALUES("<<parentId<<
",'"<<path<<
"',";
292 out<<lastModif<<
","<<lastRead<<
",'"<<refdb<<
"');";
299 std::string pat=path.c_str();
301 std::stringstream out;
302 std::stringstream result;
303 out<<
"SELECT ID FROM FILES WHERE PATH='"<<pat<<
"' AND REFERENCEDDB='"<<refdb<<
"';";
311 for (
int fld = 0; fld < q.
numFields(); fld++)
323 const std::string& attValue,
324 const std::string& searchParam,
325 const std::string& searchValue)
327 std::string av=attValue.c_str();
328 std::string sv=searchValue.c_str();
332 std::string sql =
"UPDATE FILES SET ";
351 std::vector<tree::Node*>::iterator it;
352 for(it=children.begin();it!=children.end();++it)
372 std::stringstream result;
373 std::string sel=
"SELECT PARENT_ID FROM FILES WHERE "+searchAtt+
"='"+searchVal+
"' AND REFERENCEDDB='"+refdb+
"';";
380 for (
int fld = 0; fld < q.
numFields(); fld++)
386 DBRemove(searchAtt,searchVal,refdb);
389 sel=
"SELECT ID FROM FILES WHERE PARENT_ID='"+result.str()+
"'";
399 if(!result.str().compare(
"0"))
414 std::string query =
"DELETE FROM FILES WHERE "+searchAtt+
"='"+ searchVal +
"' AND REFERENCEDDB='"+refdb+
"';";
421 std::string sel=
"SELECT LastModified FROM FILES WHERE ID='"+pathId+
"' AND REFERENCEDDB='"+refdb+
"';";
428 for (
int fld = 0; fld < q.
numFields(); fld++)
436 std::stringstream lm;
438 double modif=atof((lm.str()).c_str());
449 const std::string i_attribute,
450 const std::string i_operand,
451 const std::string i_val)
453 std::stringstream query;
454 query<<
"DELETE FROM "<<i_table<<
" WHERE "<<i_attribute<<
" "<<i_operand<<
" '"<<i_val<<
"'";