X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fthreadbuilder.cpp;h=79102b92753a7b62cd22c7f5cd6c074944f852ae;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=175a34a3d44e5491e1f40379b7bed3db0bebad66;hpb=f2545574af789b63fc655decfe31a3d9f1b30504;p=fms.git diff --git a/src/threadbuilder.cpp b/src/threadbuilder.cpp index 175a34a..79102b9 100644 --- a/src/threadbuilder.cpp +++ b/src/threadbuilder.cpp @@ -1,17 +1,22 @@ #include "../include/threadbuilder.h" #include "../include/messagethread.h" +#include "../include/dbsetup.h" +#include "../include/stringfunctions.h" + const bool ThreadBuilder::Build(const long messageid, const long boardid, const bool bydate) { int count=0; int threadid=-1; - MessageThread mt; + MessageThread mt(m_db); std::vector m_threadmessages; mt.Load(messageid,boardid,bydate); m_threadmessages=mt.GetNodes(); - // find threadid of this thread if it already exists in a thread + 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); @@ -52,20 +57,20 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const if(m_threadmessages.size()>0) { - st=m_db->Prepare("UPDATE tblThread SET FirstMessageID=?, LastMessageID=? WHERE ThreadID=?;"); - st.Bind(0,m_threadmessages[0].m_messageid); - st.Bind(1,m_threadmessages[m_threadmessages.size()-1].m_messageid); - st.Bind(2,threadid); - st.Step(); + SQLite3DB::Statement st2=m_db->Prepare("UPDATE tblThread SET FirstMessageID=?, LastMessageID=? WHERE ThreadID=?;"); + st2.Bind(0,m_threadmessages[0].m_messageid); + st2.Bind(1,m_threadmessages[m_threadmessages.size()-1].m_messageid); + st2.Bind(2,threadid); + st2.Step(); - st=m_db->Prepare("DELETE FROM tblThreadPost WHERE ThreadID=?;"); - st.Bind(0,threadid); - st.Step(); + SQLite3DB::Statement st3=m_db->Prepare("DELETE FROM tblThreadPost WHERE ThreadID=?;"); + st3.Bind(0,threadid); + st3.Step(); 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=?);"); count=0; - st=m_db->Prepare("INSERT INTO tblThreadPost(ThreadID,MessageID,PostOrder) VALUES(?,?,?);"); + SQLite3DB::Statement st4=m_db->Prepare("INSERT 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); @@ -73,20 +78,24 @@ const bool ThreadBuilder::Build(const long messageid, const long boardid, const deleteotherst.Step(); deleteotherst.Reset(); - st.Bind(0,threadid); - st.Bind(1,(*i).m_messageid); - st.Bind(2,count); - st.Step(); - st.Reset(); + st4.Bind(0,threadid); + st4.Bind(1,(*i).m_messageid); + st4.Bind(2,count); + st4.Step(); + st4.Reset(); } } else { - st=m_db->Prepare("DELETE FROM tblThread WHERE ThreadID=?;"); - st.Bind(0,threadid); - st.Step(); + SQLite3DB::Statement st2=m_db->Prepare("DELETE FROM tblThread WHERE ThreadID=?;"); + st2.Bind(0,threadid); + st2.Step(); + + m_log->trace("ThreadBuilder::Build deleted thread"); } + m_db->Execute("COMMIT;"); + return true; }