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