X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fthreadbuilder.cpp;h=5e6b1ea366d160229ca3056d00e42f3ab2f48bd0;hb=109c20e6f822c6efa465af31249e5608469253b6;hp=79102b92753a7b62cd22c7f5cd6c074944f852ae;hpb=59a5414ec47a2932a7802fcd1d98c4d80166564f;p=fms.git diff --git a/src/threadbuilder.cpp b/src/threadbuilder.cpp index 79102b9..5e6b1ea 100644 --- a/src/threadbuilder.cpp +++ b/src/threadbuilder.cpp @@ -3,6 +3,7 @@ #include "../include/dbsetup.h" #include "../include/stringfunctions.h" +#include "../include/option.h" const bool ThreadBuilder::Build(const long messageid, const long boardid, const bool bydate) { @@ -10,6 +11,11 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const int threadid=-1; 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); + + option.Get("LogLevel",ll); mt.Load(messageid,boardid,bydate); m_threadmessages=mt.GetNodes(); @@ -21,10 +27,28 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const 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 { @@ -36,14 +60,42 @@ 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(); } + st.Finalize(); // thread doesn't exist - create it if(threadid==-1) @@ -52,6 +104,17 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const st.Bind(0,boardid); st.Step(true); threadid=st.GetLastInsertRowID(); + + 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 + " | "; + } + } } @@ -63,26 +126,58 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const st2.Bind(2,threadid); st2.Step(); - SQLite3DB::Statement st3=m_db->Prepare("DELETE FROM tblThreadPost WHERE ThreadID=?;"); - st3.Bind(0,threadid); - st3.Step(); + if(ll=="8") + { + 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 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=?);"); + 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.ThreadID<>? AND tblThread.BoardID=? AND tblThreadPost.MessageID=?);"); count=0; - SQLite3DB::Statement st4=m_db->Prepare("INSERT INTO tblThreadPost(ThreadID,MessageID,PostOrder) VALUES(?,?,?);"); + SQLite3DB::Statement st4=m_db->Prepare("INSERT OR REPLACE INTO tblThreadPost(ThreadID,MessageID,PostOrder) VALUES(?,?,?);"); for(std::vector::const_iterator i=m_threadmessages.begin(); i!=m_threadmessages.end(); i++, count++) { - deleteotherst.Bind(0,boardid); - deleteotherst.Bind(1,(*i).m_messageid); + deleteotherst.Bind(0,threadid); + deleteotherst.Bind(1,boardid); + deleteotherst.Bind(2,(*i).m_messageid); 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 @@ -91,11 +186,26 @@ 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"); } + st.Finalize(); + m_db->Execute("COMMIT;"); + if(ll=="8") + { + m_log->trace(logmessage); + } + return true; }