Index: src/libchcore/ISerializerRowData.h =================================================================== diff -u -ra3d1e4c03280ece94af75d9aef32a65266cf8050 -r3933d378c75e0b245a6ccb91099eaeb2c5728209 --- src/libchcore/ISerializerRowData.h (.../ISerializerRowData.h) (revision a3d1e4c03280ece94af75d9aef32a65266cf8050) +++ src/libchcore/ISerializerRowData.h (.../ISerializerRowData.h) (revision 3933d378c75e0b245a6ccb91099eaeb2c5728209) @@ -33,18 +33,31 @@ public: virtual ~ISerializerRowData(); - virtual ISerializerRowData& SetValue(const TString& strColName, bool bValue) = 0; - virtual ISerializerRowData& SetValue(const TString& strColName, short iValue) = 0; - virtual ISerializerRowData& SetValue(const TString& strColName, unsigned short uiValue) = 0; - virtual ISerializerRowData& SetValue(const TString& strColName, int iValue) = 0; - virtual ISerializerRowData& SetValue(const TString& strColName, unsigned int uiValue) = 0; - virtual ISerializerRowData& SetValue(const TString& strColName, long lValue) = 0; - virtual ISerializerRowData& SetValue(const TString& strColName, unsigned long ulValue) = 0; - virtual ISerializerRowData& SetValue(const TString& strColName, long long llValue) = 0; - virtual ISerializerRowData& SetValue(const TString& strColName, unsigned long long llValue) = 0; - virtual ISerializerRowData& SetValue(const TString& strColName, double dValue) = 0; - virtual ISerializerRowData& SetValue(const TString& strColName, const TString& strValue) = 0; - virtual ISerializerRowData& SetValue(const TString& strColName, const TSmartPath& pathValue) = 0; + virtual ISerializerRowData& SetValue(size_t stColIndex, bool bValue) = 0; + virtual ISerializerRowData& SetValue(size_t stColIndex, short iValue) = 0; + virtual ISerializerRowData& SetValue(size_t stColIndex, unsigned short uiValue) = 0; + virtual ISerializerRowData& SetValue(size_t stColIndex, int iValue) = 0; + virtual ISerializerRowData& SetValue(size_t stColIndex, unsigned int uiValue) = 0; + virtual ISerializerRowData& SetValue(size_t stColIndex, long lValue) = 0; + virtual ISerializerRowData& SetValue(size_t stColIndex, unsigned long ulValue) = 0; + virtual ISerializerRowData& SetValue(size_t stColIndex, long long llValue) = 0; + virtual ISerializerRowData& SetValue(size_t stColIndex, unsigned long long llValue) = 0; + virtual ISerializerRowData& SetValue(size_t stColIndex, double dValue) = 0; + virtual ISerializerRowData& SetValue(size_t stColIndex, const TString& strValue) = 0; + virtual ISerializerRowData& SetValue(size_t stColIndex, const TSmartPath& pathValue) = 0; + + virtual ISerializerRowData& SetValue(const TString& strColumnName, bool bValue) = 0; + virtual ISerializerRowData& SetValue(const TString& strColumnName, short iValue) = 0; + virtual ISerializerRowData& SetValue(const TString& strColumnName, unsigned short uiValue) = 0; + virtual ISerializerRowData& SetValue(const TString& strColumnName, int iValue) = 0; + virtual ISerializerRowData& SetValue(const TString& strColumnName, unsigned int uiValue) = 0; + virtual ISerializerRowData& SetValue(const TString& strColumnName, long lValue) = 0; + virtual ISerializerRowData& SetValue(const TString& strColumnName, unsigned long ulValue) = 0; + virtual ISerializerRowData& SetValue(const TString& strColumnName, long long llValue) = 0; + virtual ISerializerRowData& SetValue(const TString& strColumnName, unsigned long long llValue) = 0; + virtual ISerializerRowData& SetValue(const TString& strColumnName, double dValue) = 0; + virtual ISerializerRowData& SetValue(const TString& strColumnName, const TString& strValue) = 0; + virtual ISerializerRowData& SetValue(const TString& strColumnName, const TSmartPath& pathValue) = 0; }; END_CHCORE_NAMESPACE Index: src/libchcore/TSQLiteSerializerRowData.cpp =================================================================== diff -u -ra3d1e4c03280ece94af75d9aef32a65266cf8050 -r3933d378c75e0b245a6ccb91099eaeb2c5728209 --- src/libchcore/TSQLiteSerializerRowData.cpp (.../TSQLiteSerializerRowData.cpp) (revision a3d1e4c03280ece94af75d9aef32a65266cf8050) +++ src/libchcore/TSQLiteSerializerRowData.cpp (.../TSQLiteSerializerRowData.cpp) (revision 3933d378c75e0b245a6ccb91099eaeb2c5728209) @@ -36,6 +36,10 @@ public: SQLiteBindValueVisitor(sqlite::TSQLiteStatement& rStatement, int& rColumn) : m_rStatement(rStatement), m_rColumn(rColumn) {} + void operator()(TSQLiteSerializerRowData::ENullType) const + { + } + void operator()(bool value) const { DBTRACE1_D(_T("- param(bool): %ld\n"), value ? 1l : 0l); @@ -111,10 +115,8 @@ int& m_rColumn; sqlite::TSQLiteStatement& m_rStatement; }; - } - /////////////////////////////////////////////////////////////////////////// TRowID::TRowID(const TSQLiteColumnsDefinition& rColumnDefinition) : m_bitset(rColumnDefinition.GetCount() + 1) // count of columns and a bit for add/modify @@ -166,93 +168,147 @@ m_rColumns(rColumnDefinition), m_bAdded(bAdded) { + m_vValues.resize(rColumnDefinition.GetCount()); } TSQLiteSerializerRowData::TSQLiteSerializerRowData(const TSQLiteSerializerRowData& rSrc) : m_stRowID(rSrc.m_stRowID), m_bAdded(rSrc.m_bAdded), m_rColumns(rSrc.m_rColumns), - m_mapValues(rSrc.m_mapValues) + m_vValues(rSrc.m_vValues) { } TSQLiteSerializerRowData::~TSQLiteSerializerRowData() { } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumn, const InternalVariant& rData) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, const InternalVariant& rData) { - size_t stColumn = m_rColumns.GetColumnIndex(strColumn); + m_vValues.at(stColIndex) = rData; + return *this; +} - std::map::iterator iterFnd = m_mapValues.find(stColumn); - if(iterFnd == m_mapValues.end()) - m_mapValues.insert(std::make_pair(stColumn, rData)); - else - (*iterFnd).second = rData; +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, bool bValue) +{ + return SetValue(stColIndex, InternalVariant(bValue)); +} - return *this; +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, short siValue) +{ + return SetValue(stColIndex, InternalVariant(siValue)); } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColName, bool bValue) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, unsigned short usiValue) { - return SetValue(strColName, InternalVariant(bValue)); + return SetValue(stColIndex, InternalVariant(usiValue)); } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColName, short siValue) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, int iValue) { - return SetValue(strColName, InternalVariant(siValue)); + return SetValue(stColIndex, InternalVariant(iValue)); } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColName, unsigned short usiValue) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, unsigned int uiValue) { - return SetValue(strColName, InternalVariant(usiValue)); + return SetValue(stColIndex, InternalVariant(uiValue)); } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColName, int iValue) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, long lValue) { - return SetValue(strColName, InternalVariant(iValue)); + return SetValue(stColIndex, InternalVariant(lValue)); } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColName, unsigned int uiValue) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, unsigned long ulValue) { - return SetValue(strColName, InternalVariant(uiValue)); + return SetValue(stColIndex, InternalVariant(ulValue)); } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColName, long lValue) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, long long llValue) { - return SetValue(strColName, InternalVariant(lValue)); + return SetValue(stColIndex, InternalVariant(llValue)); } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColName, unsigned long ulValue) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, unsigned long long ullValue) { - return SetValue(strColName, InternalVariant(ulValue)); + return SetValue(stColIndex, InternalVariant(ullValue)); } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColName, long long llValue) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, double dValue) { - return SetValue(strColName, InternalVariant(llValue)); + return SetValue(stColIndex, InternalVariant(dValue)); } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColName, unsigned long long ullValue) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, const TString& strValue) { - return SetValue(strColName, InternalVariant(ullValue)); + return SetValue(stColIndex, InternalVariant(strValue)); } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColName, double dValue) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(size_t stColIndex, const TSmartPath& pathValue) { - return SetValue(strColName, InternalVariant(dValue)); + return SetValue(stColIndex, InternalVariant(pathValue)); } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColName, const TString& strValue) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumnName, bool bValue) { - return SetValue(strColName, InternalVariant(strValue)); + return SetValue(m_rColumns.GetColumnIndex(strColumnName), bValue); } -ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColName, const TSmartPath& pathValue) +ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumnName, short iValue) { - return SetValue(strColName, InternalVariant(pathValue)); + return SetValue(m_rColumns.GetColumnIndex(strColumnName), iValue); } +ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumnName, unsigned short uiValue) +{ + return SetValue(m_rColumns.GetColumnIndex(strColumnName), uiValue); +} + +ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumnName, int iValue) +{ + return SetValue(m_rColumns.GetColumnIndex(strColumnName), iValue); +} + +ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumnName, unsigned int uiValue) +{ + return SetValue(m_rColumns.GetColumnIndex(strColumnName), uiValue); +} + +ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumnName, long lValue) +{ + return SetValue(m_rColumns.GetColumnIndex(strColumnName), lValue); +} + +ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumnName, unsigned long ulValue) +{ + return SetValue(m_rColumns.GetColumnIndex(strColumnName), ulValue); +} + +ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumnName, long long llValue) +{ + return SetValue(m_rColumns.GetColumnIndex(strColumnName), llValue); +} + +ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumnName, unsigned long long llValue) +{ + return SetValue(m_rColumns.GetColumnIndex(strColumnName), llValue); +} + +ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumnName, double dValue) +{ + return SetValue(m_rColumns.GetColumnIndex(strColumnName), dValue); +} + +ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumnName, const TString& strValue) +{ + return SetValue(m_rColumns.GetColumnIndex(strColumnName), strValue); +} + +ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TString& strColumnName, const TSmartPath& pathValue) +{ + return SetValue(m_rColumns.GetColumnIndex(strColumnName), pathValue); +} + void TSQLiteSerializerRowData::BindParamsAndExec(sqlite::TSQLiteStatement& tStatement) { using namespace sqlite; @@ -262,19 +318,19 @@ // exec query int iColumn = 1; tStatement.BindValue(iColumn++, m_stRowID); - for(MapVariants::iterator iterVariant = m_mapValues.begin(); iterVariant != m_mapValues.end(); ++iterVariant) + for(VecVariants::iterator iterVariant = m_vValues.begin(); iterVariant != m_vValues.end(); ++iterVariant) { - boost::apply_visitor(SQLiteBindValueVisitor(tStatement, iColumn), iterVariant->second); + boost::apply_visitor(SQLiteBindValueVisitor(tStatement, iColumn), *iterVariant); } tStatement.Step(); } - else if(!m_mapValues.empty()) + else if(!m_vValues.empty()) { int iColumn = 1; - for(MapVariants::iterator iterVariant = m_mapValues.begin(); iterVariant != m_mapValues.end(); ++iterVariant) + for(VecVariants::iterator iterVariant = m_vValues.begin(); iterVariant != m_vValues.end(); ++iterVariant) { - boost::apply_visitor(SQLiteBindValueVisitor(tStatement, iColumn), iterVariant->second); + boost::apply_visitor(SQLiteBindValueVisitor(tStatement, iColumn), *iterVariant); } tStatement.BindValue(iColumn++, m_stRowID); @@ -295,10 +351,13 @@ TString strQuery = boost::str(boost::wformat(L"INSERT INTO %1%(id,") % strContainerName).c_str(); TString strParams; - for(MapVariants::const_iterator iterVariant = m_mapValues.begin(); iterVariant != m_mapValues.end(); ++iterVariant) + for(size_t stIndex = 0; stIndex < m_vValues.size(); ++stIndex) { - strQuery += boost::str(boost::wformat(_T("%1%,")) % m_rColumns.GetColumnName(iterVariant->first)).c_str(); - strParams += _T("?,"); + if(m_vValues[stIndex].which() != 0) // not for eNull values (0th element of variant) + { + strQuery += boost::str(boost::wformat(_T("%1%,")) % m_rColumns.GetColumnName(stIndex)).c_str(); + strParams += _T("?,"); + } } strQuery.TrimRightSelf(_T(",")); @@ -310,14 +369,17 @@ return strQuery; } - else if(!m_mapValues.empty()) + else if(!m_vValues.empty()) { // prepare update query TString strQuery = boost::str(boost::wformat(L"UPDATE %1% SET ") % strContainerName).c_str(); - for(MapVariants::const_iterator iterVariant = m_mapValues.begin(); iterVariant != m_mapValues.end(); ++iterVariant) + for(size_t stIndex = 0; stIndex < m_vValues.size(); ++stIndex) { - strQuery += boost::str(boost::wformat(_T("%1%=?,")) % m_rColumns.GetColumnName(iterVariant->first)).c_str(); + if(m_vValues[stIndex].which() != 0) // not for eNull values (0th element of variant) + { + strQuery += boost::str(boost::wformat(_T("%1%=?,")) % m_rColumns.GetColumnName(stIndex)).c_str(); + } } strQuery.TrimRightSelf(_T(",")); @@ -333,9 +395,12 @@ { TRowID rowID(m_rColumns); rowID.SetAddedBit(m_bAdded); - for(MapVariants::const_iterator iterVariant = m_mapValues.begin(); iterVariant != m_mapValues.end(); ++iterVariant) + for(size_t stIndex = 0; stIndex < m_vValues.size(); ++stIndex) { - rowID.SetColumnBit(iterVariant->first, true); + if(m_vValues[stIndex].which() != 0) + { + rowID.SetColumnBit(stIndex, true); + } } return rowID; Index: src/libchcore/TSQLiteSerializerRowData.h =================================================================== diff -u -ra3d1e4c03280ece94af75d9aef32a65266cf8050 -r3933d378c75e0b245a6ccb91099eaeb2c5728209 --- src/libchcore/TSQLiteSerializerRowData.h (.../TSQLiteSerializerRowData.h) (revision a3d1e4c03280ece94af75d9aef32a65266cf8050) +++ src/libchcore/TSQLiteSerializerRowData.h (.../TSQLiteSerializerRowData.h) (revision 3933d378c75e0b245a6ccb91099eaeb2c5728209) @@ -25,6 +25,7 @@ #include "ISerializerContainer.h" #include "TSQLiteDatabase.h" #include "TSQLiteStatement.h" +#include #include #include @@ -56,7 +57,13 @@ class LIBCHCORE_API TSQLiteSerializerRowData : public ISerializerRowData { private: + enum ENullType + { + eNull + }; + typedef boost::variant< + ENullType, bool, short, unsigned short, @@ -79,19 +86,32 @@ TSQLiteSerializerRowData(const TSQLiteSerializerRowData& rSrc); virtual ~TSQLiteSerializerRowData(); - virtual ISerializerRowData& SetValue(const TString& strColName, bool bValue); - virtual ISerializerRowData& SetValue(const TString& strColName, short iValue); - virtual ISerializerRowData& SetValue(const TString& strColName, unsigned short uiValue); - virtual ISerializerRowData& SetValue(const TString& strColName, int iValue); - virtual ISerializerRowData& SetValue(const TString& strColName, unsigned int uiValue); - virtual ISerializerRowData& SetValue(const TString& strColName, long lValue); - virtual ISerializerRowData& SetValue(const TString& strColName, unsigned long ulValue); - virtual ISerializerRowData& SetValue(const TString& strColName, long long llValue); - virtual ISerializerRowData& SetValue(const TString& strColName, unsigned long long llValue); - virtual ISerializerRowData& SetValue(const TString& strColName, double dValue); - virtual ISerializerRowData& SetValue(const TString& strColName, const TString& strValue); - virtual ISerializerRowData& SetValue(const TString& strColName, const TSmartPath& pathValue); + virtual ISerializerRowData& SetValue(size_t stColIndex, bool bValue); + virtual ISerializerRowData& SetValue(size_t stColIndex, short iValue); + virtual ISerializerRowData& SetValue(size_t stColIndex, unsigned short uiValue); + virtual ISerializerRowData& SetValue(size_t stColIndex, int iValue); + virtual ISerializerRowData& SetValue(size_t stColIndex, unsigned int uiValue); + virtual ISerializerRowData& SetValue(size_t stColIndex, long lValue); + virtual ISerializerRowData& SetValue(size_t stColIndex, unsigned long ulValue); + virtual ISerializerRowData& SetValue(size_t stColIndex, long long llValue); + virtual ISerializerRowData& SetValue(size_t stColIndex, unsigned long long llValue); + virtual ISerializerRowData& SetValue(size_t stColIndex, double dValue); + virtual ISerializerRowData& SetValue(size_t stColIndex, const TString& strValue); + virtual ISerializerRowData& SetValue(size_t stColIndex, const TSmartPath& pathValue); + virtual ISerializerRowData& SetValue(const TString& strColumnName, bool bValue); + virtual ISerializerRowData& SetValue(const TString& strColumnName, short iValue); + virtual ISerializerRowData& SetValue(const TString& strColumnName, unsigned short uiValue); + virtual ISerializerRowData& SetValue(const TString& strColumnName, int iValue); + virtual ISerializerRowData& SetValue(const TString& strColumnName, unsigned int uiValue); + virtual ISerializerRowData& SetValue(const TString& strColumnName, long lValue); + virtual ISerializerRowData& SetValue(const TString& strColumnName, unsigned long ulValue); + virtual ISerializerRowData& SetValue(const TString& strColumnName, long long llValue); + virtual ISerializerRowData& SetValue(const TString& strColumnName, unsigned long long llValue); + virtual ISerializerRowData& SetValue(const TString& strColumnName, double dValue); + virtual ISerializerRowData& SetValue(const TString& strColumnName, const TString& strValue); + virtual ISerializerRowData& SetValue(const TString& strColumnName, const TSmartPath& pathValue); + TString GetQuery(const TString& strContainerName) const; TRowID GetChangeIdentification() const; @@ -100,7 +120,7 @@ void MarkAsAdded(); private: - ISerializerRowData& SetValue(const TString& strColumn, const InternalVariant& rData); + ISerializerRowData& SetValue(size_t stColIndex, const InternalVariant& rData); private: size_t m_stRowID; @@ -109,8 +129,8 @@ #pragma warning(disable: 4251) TSQLiteColumnsDefinition& m_rColumns; - typedef std::map MapVariants; // column id -> variant data - MapVariants m_mapValues; + typedef std::vector VecVariants; // column id -> variant data + VecVariants m_vValues; #pragma warning(pop) }; Index: src/libchcore/TSubTaskArray.cpp =================================================================== diff -u -ra3d1e4c03280ece94af75d9aef32a65266cf8050 -r3933d378c75e0b245a6ccb91099eaeb2c5728209 --- src/libchcore/TSubTaskArray.cpp (.../TSubTaskArray.cpp) (revision a3d1e4c03280ece94af75d9aef32a65266cf8050) +++ src/libchcore/TSubTaskArray.cpp (.../TSubTaskArray.cpp) (revision 3933d378c75e0b245a6ccb91099eaeb2c5728209) @@ -191,7 +191,6 @@ /////////////////////////////////////////////////////////////////////// { ISerializerContainerPtr spContainer = spSerializer->GetContainer(_T("subtasks")); - InitSubtasksColumns(spContainer); // base data