version 0.3.31
[fms.git] / src / threadbuilder.cpp
index 79102b9..7df5a54 100644 (file)
@@ -3,6 +3,7 @@
 \r
 #include "../include/dbsetup.h"\r
 #include "../include/stringfunctions.h"\r
+#include "../include/option.h"\r
 \r
 const bool ThreadBuilder::Build(const long messageid, const long boardid, const bool bydate)\r
 {\r
@@ -10,21 +11,44 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const
        int threadid=-1;\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
+       option.Get("LogLevel",ll);\r
 \r
        mt.Load(messageid,boardid,bydate);\r
        m_threadmessages=mt.GetNodes();\r
 \r
-       m_db->Execute("BEGIN;");\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
@@ -36,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
@@ -52,6 +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
+                       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
@@ -63,10 +125,30 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const
                st2.Bind(2,threadid);\r
                st2.Step();\r
 \r
+               if(ll=="8")\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
+               if(ll=="8")\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
 \r
                count=0;\r
@@ -78,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
@@ -91,10 +196,25 @@ 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
-       m_db->Execute("COMMIT;");\r
+       st.Finalize();\r
+\r
+       //m_db->Execute("COMMIT;");\r
+\r
+       if(ll=="8")\r
+       {\r
+               m_log->trace(logmessage);\r
+       }\r
 \r
        return true;\r
 \r