X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fboard.cpp;h=9d249ad50c1355d14d53e2380b77c92cc45fd3eb;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=e256dcbb608823bd63266e6964a1e6c4c43b4dc6;hpb=6b896a9e1dc143bba86795be1e9336549db9b85f;p=fms.git diff --git a/src/board.cpp b/src/board.cpp index e256dcb..9d249ad 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -1,43 +1,66 @@ #include "../include/board.h" #include "../include/stringfunctions.h" +#include + #ifdef XMEM #include #endif -Board::Board() +Board::Board(SQLite3DB::DB *db):IDatabase(db) { m_boardid=-1; m_boardname=""; m_boarddescription=""; - m_datecreated.Set(1970,1,1); + m_datecreated.assign(1970,1,1); m_lowmessageid=0; m_highmessageid=0; m_messagecount=0; + m_savereceivedmessages=true; + m_addedmethod=""; } -Board::Board(const long boardid) +Board::Board(SQLite3DB::DB *db, const long boardid):IDatabase(db) { Load(boardid); } -Board::Board(const std::string &boardname) +Board::Board(SQLite3DB::DB *db, const std::string &boardname):IDatabase(db) { Load(boardname); } +Board::Board(SQLite3DB::DB *db, const long boardid, const std::string &boardname, const std::string &boarddescription, const std::string datecreated, const long lowmessageid, const long highmessageid, const long messagecount, const bool savereceivedmessages, const std::string &addedmethod):IDatabase(db) +{ + m_boardid=boardid; + m_boardname=boardname; + m_boarddescription=boarddescription; + m_lowmessageid=lowmessageid; + m_highmessageid=highmessageid; + m_messagecount=messagecount; + m_savereceivedmessages=savereceivedmessages; + m_addedmethod=addedmethod; + + SetDateFromString(datecreated); + +} + + const bool Board::Load(const long boardid) { // clear current values m_boardid=-1; m_boardname=""; m_boarddescription=""; - m_datecreated.Set(1970,1,1); + m_datecreated.assign(1970,1,1); m_lowmessageid=0; m_highmessageid=0; m_messagecount=0; + m_addedmethod=""; - SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName, BoardDescription, DateAdded FROM tblBoard WHERE BoardID=?;"); + // Optimize query by not using vwBoardStats + //SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName, BoardDescription, DateAdded, HighMessageID, LowMessageID, MessageCount, SaveReceivedMessages, AddedMethod FROM tblBoard LEFT JOIN vwBoardStats ON tblBoard.BoardID=vwBoardStats.BoardID WHERE tblBoard.BoardID=?;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName, BoardDescription, DateAdded, IFNULL(MAX(MessageID),'0') AS HighMessageID, IFNULL(MIN(MessageID),'0') AS LowMessageID, COUNT(MessageID) AS MessageCount, SaveReceivedMessages, AddedMethod FROM tblBoard LEFT JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID WHERE tblBoard.BoardID=? AND (MessageID IS NULL OR MessageID>=0);"); st.Bind(0,boardid); st.Step(); @@ -52,54 +75,27 @@ const bool Board::Load(const long boardid) st.ResultText(1,m_boarddescription); st.ResultText(2,tempstr); - // break out date created - date should be in format yyyy-mm-dd HH:MM:SS, so we split on "-", " " (space), and ":" - StringFunctions::SplitMultiple(tempstr,"- :",dateparts); - if(dateparts.size()>0) - { - StringFunctions::Convert(dateparts[0],tempint); - m_datecreated.SetYear(tempint); - } - if(dateparts.size()>1) - { - StringFunctions::Convert(dateparts[1],tempint); - m_datecreated.SetMonth(tempint); - } - if(dateparts.size()>2) - { - StringFunctions::Convert(dateparts[2],tempint); - m_datecreated.SetDay(tempint); - } - if(dateparts.size()>3) - { - StringFunctions::Convert(dateparts[3],tempint); - m_datecreated.SetHour(tempint); - } - if(dateparts.size()>4) - { - StringFunctions::Convert(dateparts[4],tempint); - m_datecreated.SetMinute(tempint); - } - if(dateparts.size()>5) + SetDateFromString(tempstr); + + tempint=0; + st.ResultInt(3,tempint); + m_highmessageid=tempint; + tempint=0; + st.ResultInt(4,tempint); + m_lowmessageid=tempint; + tempint=0; + st.ResultInt(5,tempint); + m_messagecount=tempint; + st.ResultText(6,tempstr); + if(tempstr=="true") { - StringFunctions::Convert(dateparts[5],tempint); - m_datecreated.SetSecond(tempint); + m_savereceivedmessages=true; } - - // get max and min ids and message count in this board - SQLite3DB::Statement bounds=m_db->Prepare("SELECT HighMessageID, LowMessageID, MessageCount FROM vwBoardStats WHERE BoardID=?;"); - bounds.Bind(0,boardid); - bounds.Step(); - - if(bounds.RowReturned()) + else { - int tempint; - bounds.ResultInt(0,tempint); - m_highmessageid=tempint; - bounds.ResultInt(1,tempint); - m_lowmessageid=tempint; - bounds.ResultInt(2,tempint); - m_messagecount=tempint; + m_savereceivedmessages=false; } + st.ResultText(7,m_addedmethod); return true; } @@ -109,19 +105,74 @@ const bool Board::Load(const long boardid) } } -const bool Board::Load(const std::string &boardname) +const bool Board::Load(const std::string &boardname) // same as loading form boardid - but using name { - SQLite3DB::Statement st=m_db->Prepare("SELECT BoardID FROM tblBoard WHERE BoardName=?;"); + + // clear current values + m_boardid=-1; + m_boardname=""; + m_boarddescription=""; + m_datecreated.assign(1970,1,1); + m_lowmessageid=0; + m_highmessageid=0; + m_messagecount=0; + int tempint=-1; + m_addedmethod=""; + + // Optimize query by not using vwBoardStats + //SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName, BoardDescription, DateAdded, HighMessageID, LowMessageID, MessageCount, SaveReceivedMessages, tblBoard.BoardID, AddedMethod FROM tblBoard LEFT JOIN vwBoardStats ON tblBoard.BoardID=vwBoardStats.BoardID WHERE tblBoard.BoardName=?;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName, BoardDescription, DateAdded, IFNULL(MAX(MessageID),'0') AS HighMessageID, IFNULL(MIN(MessageID),'0') AS LowMessageID, COUNT(MessageID) AS MessageCount, SaveReceivedMessages, tblBoard.BoardID, AddedMethod FROM tblBoard LEFT JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID WHERE tblBoard.BoardName=? AND (MessageID IS NULL OR MessageID>=0);"); st.Bind(0,boardname); st.Step(); + if(st.RowReturned()) { int tempint; - st.ResultInt(0,tempint); - return Load(tempint); + std::string tempstr; + std::vector dateparts; + + st.ResultText(0,m_boardname); + st.ResultText(1,m_boarddescription); + st.ResultText(2,tempstr); + st.ResultInt(7,tempint); // boardid + m_boardid=tempint; + + SetDateFromString(tempstr); + + tempint=0; + st.ResultInt(3,tempint); + m_highmessageid=tempint; + tempint=0; + st.ResultInt(4,tempint); + m_lowmessageid=tempint; + tempint=0; + st.ResultInt(5,tempint); + m_messagecount=tempint; + st.ResultText(6,tempstr); + if(tempstr=="true") + { + m_savereceivedmessages=true; + } + else + { + m_savereceivedmessages=false; + } + st.ResultText(8,m_addedmethod); + + return true; } else { return false; } + +} + +void Board::SetDateFromString(const std::string &datestring) +{ + int tzdiff=0; + if(Poco::DateTimeParser::tryParse(datestring,m_datecreated,tzdiff)==false) + { + m_log->error("Board::SetDateFromString could not parse date "+datestring); + } }