X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fthreadbuilder.cpp;h=7df5a54066dbe70b09a1fde535448c5e6ebbbaed;hb=ed0732b2550c23c05fc9faf925620e87ee6dee12;hp=cf21aab6c2e9db8c4a30488e96bbfafdf83b197e;hpb=e662ea47fba8715474851ceebacba400984ee433;p=fms.git diff --git a/src/threadbuilder.cpp b/src/threadbuilder.cpp index cf21aab..7df5a54 100644 --- a/src/threadbuilder.cpp +++ b/src/threadbuilder.cpp @@ -9,35 +9,46 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const { int count=0; int threadid=-1; - MessageThread mt; + MessageThread mt(m_db); std::vector m_threadmessages; + std::string logmessage(""); // temp var to help track down exactly when corruption occurrs + std::string ll(""); + Option option(m_db); - std::string ll=""; - Option::Instance()->Get("LogLevel",ll); - - // TODO - remove after corruption issue fixed - if(ll=="8") - { - std::string dbres=TestDBIntegrity(); - std::string messageidstr=""; - std::string boardidstr=""; - StringFunctions::Convert(messageid,messageidstr); - StringFunctions::Convert(boardid,boardidstr); - m_log->trace("ThreadBuilder::Build start TestDBIntegrity("+messageidstr+","+boardidstr+") returned "+dbres); - } + option.Get("LogLevel",ll); mt.Load(messageid,boardid,bydate); m_threadmessages=mt.GetNodes(); + //m_db->Execute("BEGIN;"); + // find threadid of this mesage if it already exists in a thread SQLite3DB::Statement st=m_db->Prepare("SELECT tblThread.ThreadID FROM tblThread INNER JOIN tblThreadPost ON tblThread.ThreadID=tblThreadPost.ThreadID WHERE tblThread.BoardID=? AND tblThreadPost.MessageID=?;"); st.Bind(0,boardid); st.Bind(1,messageid); + if(ll=="8") + { + std::string temp1(""); + std::string temp2(""); + StringFunctions::Convert(boardid,temp1); + StringFunctions::Convert(messageid,temp2); + + logmessage+="initial bound boardid=" + temp1 + " messageid=" + temp2 + " | "; + } + st.Step(); if(st.RowReturned()) { st.ResultInt(0,threadid); + + if(ll=="8") + { + std::string temp1(""); + StringFunctions::Convert(threadid,temp1); + + logmessage+="result threadid=" + temp1 + " | "; + } } else { @@ -49,9 +60,36 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const st.Bind(1,(*i).m_messageid); st.Step(); + if(ll=="8") + { + std::string temp1(""); + std::string temp2(""); + StringFunctions::Convert(boardid,temp1); + StringFunctions::Convert((*i).m_messageid,temp2); + + logmessage+="find bound boardid=" + temp1 + " messageid=" + temp2 + " | "; + } + if(st.RowReturned()) { st.ResultInt(0,threadid); + if(ll=="8") + { + std::string temp1(""); + StringFunctions::Convert(threadid,temp1); + + logmessage+="find result threadid=" + temp1 + " | "; + } + } + else + { + if(ll=="8") + { + std::string temp1(""); + StringFunctions::Convert(threadid,temp1); + + logmessage+="find not found | "; + } } st.Reset(); @@ -65,16 +103,17 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const st.Bind(0,boardid); st.Step(true); threadid=st.GetLastInsertRowID(); - } - } - // TODO - remove after corruption issue fixed - if(ll=="8") - { - std::string dbres=TestDBIntegrity(); - if(dbres!="ok") - { - m_log->trace("ThreadBuilder::Build middle TestDBIntegrity returned "+dbres); + if(ll=="8") + { + std::string temp1(""); + std::string temp2(""); + StringFunctions::Convert(boardid,temp1); + StringFunctions::Convert(threadid,temp2); + + logmessage+="insert thread bind boardid=" + temp1 + " result threadid=" + temp2 + " | "; + } + } } @@ -86,28 +125,28 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const st2.Bind(2,threadid); st2.Step(); - // TODO - remove after corruption issue fixed if(ll=="8") { - std::string dbres=TestDBIntegrity(); - if(dbres!="ok") - { - m_log->trace("ThreadBuilder::Build after thread update TestDBIntegrity returned "+dbres); - } + std::string temp1(""); + std::string temp2(""); + std::string temp3(""); + StringFunctions::Convert(m_threadmessages[0].m_messageid,temp1); + StringFunctions::Convert(m_threadmessages[m_threadmessages.size()-1].m_messageid,temp2); + StringFunctions::Convert(threadid,temp3); + + logmessage+="update bind fmessageid=" + temp1 + " lmessageid=" + temp2 + " threadid=" + temp3 + " | "; } SQLite3DB::Statement st3=m_db->Prepare("DELETE FROM tblThreadPost WHERE ThreadID=?;"); st3.Bind(0,threadid); st3.Step(); - // TODO - remove after corruption issue fixed if(ll=="8") { - std::string dbres=TestDBIntegrity(); - if(dbres!="ok") - { - m_log->trace("ThreadBuilder::Build after thread post delete TestDBIntegrity returned "+dbres); - } + std::string temp1(""); + StringFunctions::Convert(threadid,temp1); + + logmessage+="delete bind threadid=" + temp1 + " | "; } SQLite3DB::Statement deleteotherst=m_db->Prepare("DELETE FROM tblThread WHERE ThreadID IN (SELECT tblThread.ThreadID FROM tblThreadPost INNER JOIN tblThread ON tblThreadPost.ThreadID=tblThread.ThreadID WHERE tblThread.BoardID=? AND tblThreadPost.MessageID=?);"); @@ -121,11 +160,34 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const deleteotherst.Step(); deleteotherst.Reset(); + if(ll=="8") + { + std::string temp1(""); + std::string temp2(""); + StringFunctions::Convert(boardid,temp1); + StringFunctions::Convert((*i).m_messageid,temp2); + + logmessage+="deleteother bind boardid=" + temp1 + " messageid=" + temp2 + " | "; + } + st4.Bind(0,threadid); st4.Bind(1,(*i).m_messageid); st4.Bind(2,count); st4.Step(); st4.Reset(); + + if(ll=="8") + { + std::string temp1(""); + std::string temp2(""); + std::string temp3(""); + StringFunctions::Convert(threadid,temp1); + StringFunctions::Convert((*i).m_messageid,temp2); + StringFunctions::Convert(count,temp3); + + logmessage+="insertthreadpost bind threadid=" + temp1 + " messageid=" + temp2 + " count=" + temp3 + " | "; + } + } } else @@ -134,14 +196,24 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const st2.Bind(0,threadid); st2.Step(); + if(ll=="8") + { + std::string temp1(""); + StringFunctions::Convert(threadid,temp1); + + logmessage+="delete thread bind threadid=" + temp1 + " | "; + } + m_log->trace("ThreadBuilder::Build deleted thread"); } - // TODO - remove after corruption issue fixed + st.Finalize(); + + //m_db->Execute("COMMIT;"); + if(ll=="8") { - std::string dbres=TestDBIntegrity(); - m_log->trace("ThreadBuilder::Build end TestDBIntegrity returned "+dbres); + m_log->trace(logmessage); } return true;