+ //=====================================================================
+ void SQLiteTreeHandler::DBRecursiveRemoveNode(int level, std::string parentId)
+ {
+ std::stringstream out;
+ std::stringstream result;
+ out<<"SELECT ID FROM "<<GetTree().GetLevelDescriptor(level).GetName()<<" WHERE PARENT_ID='"<<parentId<<"'";
+
+ CppSQLite3Query q;
+ QUERYDB(out.str(),q);
+
+ while (!q.eof())
+ {
+ for (int fld = 0; fld < q.numFields(); fld++)
+ {
+ result<<q.getStringField(fld)<<"#";
+ }
+ q.nextRow();
+ }
+ std::string res=result.str();
+ size_t ini=0;
+ size_t fin=0;
+ while(fin<res.size()-1)
+ {
+ fin=res.find('#',ini);
+ DBDelete(GetTree().GetLevelDescriptor(level).GetName(),"ID",res.substr(ini,fin-ini));
+ if(level<GetTree().GetNumberOfLevels()-1)
+ {
+ DBRecursiveRemoveNode(level+1,res.substr(ini,fin-ini));
+ }
+ ini=fin+1;
+ }
+
+
+ }
+
+ //=====================================================================
+ void SQLiteTreeHandler::DBDelete(std::string levelDescriptor, std::string key, std::string value)
+ {
+
+ std::stringstream query;
+ query<<"DELETE FROM "<<levelDescriptor<<" WHERE "<<key<<"='"<<value<<"';";
+
+ UPDATEDB(query.str());
+ GimmickDebugMessage(2," Deleting: Query: "<<query.str()<<std::endl);
+ }
+
+
+ //=====================================================================
+ void SQLiteTreeHandler::GetAttribute(std::string levelDescriptor,
+ std::string searchParam,
+ std::string searchVal,
+ std::string key,
+ std::string& result)
+ {
+ std::stringstream out;
+ std::stringstream results;
+ out<<"SELECT "<<key<<" FROM "<<levelDescriptor;
+ if(searchParam!="")
+ {
+ out<<" WHERE "<<searchParam<<"='"<<searchVal<<"'";
+ }
+
+ CppSQLite3Query q;
+ QUERYDB(out.str(),q);
+
+
+ while (!q.eof())
+ {
+ for (int fld = 0; fld < q.numFields(); fld++)
+ {
+ results<<q.getStringField(fld);
+ if(searchParam=="")
+ {
+ results<<"#";
+ }
+ }
+ q.nextRow();
+ }
+ result=results.str();
+
+ }
+ //=====================================================================
+ unsigned int SQLiteTreeHandler::GetNumberOfChildren(tree::Node* n)
+ {
+ // Query DB
+ int nb=0;
+ int level = n->GetLevel();
+
+ if(level<GetTree().GetNumberOfLevels()&& level>0)
+ {
+ std::string query = "SELECT NumberOfChildren FROM ";
+ query += GetTree().GetLevelDescriptor(level).GetName();
+ if (level>0)
+ {
+ query += " WHERE ID='" + n->UnsafeGetAttribute("ID")
+ + "'";
+ }
+ CppSQLite3Query q;
+ QUERYDB(query,q);
+
+
+ while (!q.eof())
+ {
+ for (int fld = 0; fld < q.numFields(); fld++)
+ {
+ nb=q.getIntField(fld);
+ }
+ q.nextRow();
+ }
+ }
+ /*
+ if(nb==0)
+ {
+ nb=1;
+ }
+ */
+ return nb;
+ }
+
+ //=====================================================================
+ void SQLiteTreeHandler::GetTopLevelNodeId(const std::string& searchParam, const std::string& searchValue, std::string& parent_id)
+ {
+ int level=GetTree().GetNumberOfLevels()-1;
+ std::string sp=searchParam.c_str();
+ std::string sv=searchValue.c_str();
+
+ while(level>1)
+ {
+ std::stringstream out;
+ std::stringstream results;
+ out<<"SELECT PARENT_ID FROM "<<GetTree().GetLevelDescriptor(level).GetName();
+ out<<" WHERE "<<sp<<"='"<<sv<<"'";
+ CppSQLite3Query q;
+ QUERYDB(out.str(),q);
+
+
+ while (!q.eof())
+ {
+ for (int fld = 0; fld < q.numFields(); fld++)
+ {
+ results<<q.getStringField(fld);
+ }
+ q.nextRow();
+ }
+ level=level-1;
+ sp="ID";
+ sv=results.str();
+ }
+ parent_id=sv;
+
+ }
+
+ //=====================================================================
+ void SQLiteTreeHandler::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 "<<i_table<<" WHERE "<<i_attribute<<" "<<i_operand<<" '"<<i_val<<"'";
+ UPDATEDB(query.str());
+ }
+
+ //=====================================================================
+ void SQLiteTreeHandler::BeginTransaction()
+ {
+ std::stringstream out;
+ out<<"begin transaction;";
+ UPDATEDB(out.str());
+ }
+
+ //=====================================================================
+ void SQLiteTreeHandler::EndTransaction()
+ {
+ std::stringstream out;
+ out<<"commit transaction;";
+ UPDATEDB(out.str());
+ }
+
+ /*