Commit [r514] Maximize Restore History

Renamed the sqlite data row class.

Part of the sqlite query generator (CH-82).

ixen 2014-03-24

changed /trunk/src/libchcore/libchcore.vc90.vcproj
changed /trunk/src/libchcore/TSQLiteSerializer.cpp
changed /trunk/src/libchcore/TSQLiteSerializerContainer.cpp
changed /trunk/src/libchcore/TTaskInfo.cpp
changed /trunk/src/libchcore/TSQLiteSerializerContainer.h
changed /trunk/src/libchcore/ISerializerContainer.h
changed /trunk/src/libchcore/TRowData.h
copied /trunk/src/libchcore/ISerializerRowWriter.h -> /trunk/src/libchcore/ISerializerRowData.h
copied /trunk/src/libchcore/TSQLiteSerializerRowWriter.cpp -> /trunk/src/libchcore/TSQLiteSerializerRowData.h
copied /trunk/src/libchcore/ISerializerRowWriter.cpp -> /trunk/src/libchcore/ISerializerRowData.cpp
copied /trunk/src/libchcore/TSQLiteSerializerRowWriter.h -> /trunk/src/libchcore/TSQLiteSerializerRowData.cpp
/trunk/src/libchcore/libchcore.vc90.vcproj Diff Switch to side-by-side view
Loading...
/trunk/src/libchcore/TSQLiteSerializer.cpp Diff Switch to side-by-side view
Loading...
/trunk/src/libchcore/TSQLiteSerializerContainer.cpp Diff Switch to side-by-side view
Loading...
/trunk/src/libchcore/TTaskInfo.cpp Diff Switch to side-by-side view
Loading...
/trunk/src/libchcore/TSQLiteSerializerContainer.h Diff Switch to side-by-side view
Loading...
/trunk/src/libchcore/ISerializerContainer.h Diff Switch to side-by-side view
Loading...
/trunk/src/libchcore/TRowData.h Diff Switch to side-by-side view
Loading...
/trunk/src/libchcore/ISerializerRowWriter.h to /trunk/src/libchcore/ISerializerRowData.h
--- a/trunk/src/libchcore/ISerializerRowWriter.h
+++ b/trunk/src/libchcore/ISerializerRowData.h
@@ -27,16 +27,16 @@
 class ISerializerContainer;
 typedef boost::shared_ptr<ISerializerContainer> ISerializerContainerPtr;
 
-class LIBCHCORE_API ISerializerRowWriter
+class LIBCHCORE_API ISerializerRowData
 {
 public:
-	virtual ~ISerializerRowWriter();
+	virtual ~ISerializerRowData();
 
-	virtual ISerializerRowWriter& operator%(const TRowData& rData) = 0;
-	virtual ISerializerRowWriter& SetValue(const TRowData& rData) = 0;
+	virtual ISerializerRowData& operator%(const TRowData& rData) = 0;
+	virtual ISerializerRowData& SetValue(const TRowData& rData) = 0;
 };
 
-typedef boost::shared_ptr<ISerializerRowWriter> ISerializerRowWriterPtr;
+typedef boost::shared_ptr<ISerializerRowData> ISerializerRowDataPtr;
 
 END_CHCORE_NAMESPACE
 
/trunk/src/libchcore/TSQLiteSerializerRowWriter.cpp to /trunk/src/libchcore/TSQLiteSerializerRowData.h
--- a/trunk/src/libchcore/TSQLiteSerializerRowWriter.cpp
+++ b/trunk/src/libchcore/TSQLiteSerializerRowData.h
@@ -1,5 +1,5 @@
 // ============================================================================
-//  Copyright (C) 2001-2013 by Jozef Starosczyk
+//  Copyright (C) 2001-2014 by Jozef Starosczyk
 //  ixen@copyhandler.com
 //
 //  This program is free software; you can redistribute it and/or modify
@@ -16,45 +16,43 @@
 //  Free Software Foundation, Inc.,
 //  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // ============================================================================
-#include "stdafx.h"
-#include "TSQLiteSerializerRowWriter.h"
-#include "TSQLiteSerializerContainer.h"
+#ifndef __TSQLITESERIALIZERROWWRITER_H__
+#define __TSQLITESERIALIZERROWWRITER_H__
+
+#include "libchcore.h"
+#include "ISerializerRowData.h"
+#include "TSQLiteColumnDefinition.h"
+#include "ISerializerContainer.h"
+#include "TRowData.h"
+#include "TSQLiteDatabase.h"
 
 BEGIN_CHCORE_NAMESPACE
 
-TSQLiteSerializerRowWriter::TSQLiteSerializerRowWriter(size_t stRowID, const TSQLiteColumnDefinitionPtr& spColumnDefinition, bool bAdded) :
-	m_stRowID(stRowID),
-	m_spColumns(spColumnDefinition),
-	m_bAdded(bAdded)
+class LIBCHCORE_API TSQLiteSerializerRowData : public ISerializerRowData
 {
-}
+public:
+	TSQLiteSerializerRowData(size_t stRowID, const TSQLiteColumnDefinitionPtr& spColumnDefinition, bool bAdded);
+	virtual ~TSQLiteSerializerRowData();
 
-TSQLiteSerializerRowWriter::~TSQLiteSerializerRowWriter()
-{
-}
+	virtual ISerializerRowData& operator%(const TRowData& rData);
+	virtual ISerializerRowData& SetValue(const TRowData& rData);
 
-ISerializerRowWriter& TSQLiteSerializerRowWriter::operator%(const TRowData& rData)
-{
-	size_t stColumn = m_spColumns->GetColumnIndex(rData.m_strColName);
-	std::map<size_t, TRowData::InternalVariant>::iterator iterFnd = m_mapValues.find(stColumn);
-	if(iterFnd == m_mapValues.end())
-		m_mapValues.insert(std::make_pair(stColumn, rData.m_varValue));
-	else
-		(*iterFnd).second = rData.m_varValue;
+	void Flush(const sqlite::TSQLiteDatabasePtr& spDatabase, const TString& strContainerName);
 
-	return *this;
-}
+private:
+	size_t m_stRowID;
+	bool m_bAdded;
+#pragma warning(push)
+#pragma warning(disable: 4251)
+	TSQLiteColumnDefinitionPtr m_spColumns;
 
-ISerializerRowWriter& TSQLiteSerializerRowWriter::SetValue(const TRowData& rData)
-{
-	size_t stColumn = m_spColumns->GetColumnIndex(rData.m_strColName);
-	std::map<size_t, TRowData::InternalVariant>::iterator iterFnd = m_mapValues.find(stColumn);
-	if(iterFnd == m_mapValues.end())
-		m_mapValues.insert(std::make_pair(stColumn, rData.m_varValue));
-	else
-		(*iterFnd).second = rData.m_varValue;
+	typedef std::map<size_t, TRowData::InternalVariant> MapVariants;	// column id -> variant data
+	MapVariants m_mapValues;
+#pragma warning(pop)
+};
 
-	return *this;
-}
+typedef boost::shared_ptr<TSQLiteSerializerRowData> TSQLiteSerializerRowDataPtr;
 
 END_CHCORE_NAMESPACE
+
+#endif
/trunk/src/libchcore/ISerializerRowWriter.cpp to /trunk/src/libchcore/ISerializerRowData.cpp
--- a/trunk/src/libchcore/ISerializerRowWriter.cpp
+++ b/trunk/src/libchcore/ISerializerRowData.cpp
@@ -17,11 +17,11 @@
 //  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // ============================================================================
 #include "stdafx.h"
-#include "ISerializerRowWriter.h"
+#include "ISerializerRowData.h"
 
 BEGIN_CHCORE_NAMESPACE
 
-ISerializerRowWriter::~ISerializerRowWriter()
+ISerializerRowData::~ISerializerRowData()
 {
 }
 
/trunk/src/libchcore/TSQLiteSerializerRowWriter.h to /trunk/src/libchcore/TSQLiteSerializerRowData.cpp
--- a/trunk/src/libchcore/TSQLiteSerializerRowWriter.h
+++ b/trunk/src/libchcore/TSQLiteSerializerRowData.cpp
@@ -1,5 +1,5 @@
 // ============================================================================
-//  Copyright (C) 2001-2014 by Jozef Starosczyk
+//  Copyright (C) 2001-2013 by Jozef Starosczyk
 //  ixen@copyhandler.com
 //
 //  This program is free software; you can redistribute it and/or modify
@@ -16,38 +16,71 @@
 //  Free Software Foundation, Inc.,
 //  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // ============================================================================
-#ifndef __TSQLITESERIALIZERROWWRITER_H__
-#define __TSQLITESERIALIZERROWWRITER_H__
-
-#include "libchcore.h"
-#include "ISerializerRowWriter.h"
-#include "TSQLiteColumnDefinition.h"
-#include "ISerializerContainer.h"
-#include "TRowData.h"
+#include "stdafx.h"
+#include "TSQLiteSerializerRowData.h"
+#include "TSQLiteStatement.h"
+#include <boost/format.hpp>
 
 BEGIN_CHCORE_NAMESPACE
 
-class LIBCHCORE_API TSQLiteSerializerRowWriter : public ISerializerRowWriter
+TSQLiteSerializerRowData::TSQLiteSerializerRowData(size_t stRowID, const TSQLiteColumnDefinitionPtr& spColumnDefinition, bool bAdded) :
+	m_stRowID(stRowID),
+	m_spColumns(spColumnDefinition),
+	m_bAdded(bAdded)
 {
-public:
-	TSQLiteSerializerRowWriter(size_t stRowID, const TSQLiteColumnDefinitionPtr& spColumnDefinition, bool bAdded);
-	virtual ~TSQLiteSerializerRowWriter();
+}
 
-	virtual ISerializerRowWriter& operator%(const TRowData& rData);
-	virtual ISerializerRowWriter& SetValue(const TRowData& rData);
+TSQLiteSerializerRowData::~TSQLiteSerializerRowData()
+{
+}
 
-private:
-	size_t m_stRowID;
-	bool m_bAdded;
-#pragma warning(push)
-#pragma warning(disable: 4251)
-	TSQLiteColumnDefinitionPtr m_spColumns;
-	std::map<size_t, TRowData::InternalVariant> m_mapValues;
-#pragma warning(pop)
-};
+ISerializerRowData& TSQLiteSerializerRowData::operator%(const TRowData& rData)
+{
+	size_t stColumn = m_spColumns->GetColumnIndex(rData.m_strColName);
+	std::map<size_t, TRowData::InternalVariant>::iterator iterFnd = m_mapValues.find(stColumn);
+	if(iterFnd == m_mapValues.end())
+		m_mapValues.insert(std::make_pair(stColumn, rData.m_varValue));
+	else
+		(*iterFnd).second = rData.m_varValue;
 
-typedef boost::shared_ptr<TSQLiteSerializerRowWriter> TSQLiteSerializerRowWriterPtr;
+	return *this;
+}
+
+ISerializerRowData& TSQLiteSerializerRowData::SetValue(const TRowData& rData)
+{
+	size_t stColumn = m_spColumns->GetColumnIndex(rData.m_strColName);
+	std::map<size_t, TRowData::InternalVariant>::iterator iterFnd = m_mapValues.find(stColumn);
+	if(iterFnd == m_mapValues.end())
+		m_mapValues.insert(std::make_pair(stColumn, rData.m_varValue));
+	else
+		(*iterFnd).second = rData.m_varValue;
+
+	return *this;
+}
+
+void TSQLiteSerializerRowData::Flush(const sqlite::TSQLiteDatabasePtr& spDatabase, const TString& strContainerName)
+{
+	using namespace sqlite;
+
+	TSQLiteStatement tStatement(spDatabase);
+
+	if(m_bAdded)
+	{
+		// insert into container_name(col1, col2) values(val1, val2)
+	}
+	else
+	{
+		// update container_name set col1=val1, col2=val2 where id=?
+		TString strPairs = boost::str(boost::wformat(L"UPDATE %1% SET ") % strContainerName).c_str();
+		for(MapVariants::iterator iterVariant = m_mapValues.begin(); iterVariant != m_mapValues.end(); ++iterVariant)
+		{
+			strPairs += boost::str(boost::wformat(_T("%1%=?,")) % m_spColumns->GetColumnName(iterVariant->first)).c_str();
+
+			//tStatement.BindValue();
+		}
+
+		strPairs.TrimRightSelf(_T(","));
+	}
+}
 
 END_CHCORE_NAMESPACE
-
-#endif