summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-29 03:32:42 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-12-29 06:00:07 +0000
commit65b2e133e14cd667e98537db594b14faadb7e70c (patch)
treeeba097b8595059f449c1ba709e621c2f5f92e949
parentMove SqlWriter to its own files (diff)
downloadlibdbpp-65b2e133e14cd667e98537db594b14faadb7e70c.tar.bz2
libdbpp-65b2e133e14cd667e98537db594b14faadb7e70c.tar.xz
libdbpp-65b2e133e14cd667e98537db594b14faadb7e70c.zip
Move TablePatch to its own files
-rw-r--r--libdbpp/connection.cpp7
-rw-r--r--libdbpp/connection.h15
-rw-r--r--libdbpp/tablepatch.cpp8
-rw-r--r--libdbpp/tablepatch.h37
-rw-r--r--libdbpp/unittests/testPatch.cpp1
5 files changed, 40 insertions, 28 deletions
diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp
index 79f7d32..aaa7591 100644
--- a/libdbpp/connection.cpp
+++ b/libdbpp/connection.cpp
@@ -68,13 +68,6 @@ DB::Connection::insertId() const
throw std::runtime_error("insertId not implemented for this driver.");
}
-DB::TablePatch::TablePatch() :
- insteadOfDelete(nullptr),
- where(nullptr),
- order(nullptr)
-{
-}
-
std::string
DB::TransactionRequired::message() const throw()
{
diff --git a/libdbpp/connection.h b/libdbpp/connection.h
index ac18c24..7ee1bc9 100644
--- a/libdbpp/connection.h
+++ b/libdbpp/connection.h
@@ -16,9 +16,9 @@ namespace AdHoc {
namespace DB {
class Command;
- class SqlWriter;
class SelectCommand;
class ModifyCommand;
+ class TablePatch;
enum BulkDeleteStyle {
BulkDeleteUsingSubSelect,
@@ -57,19 +57,6 @@ namespace DB {
const time_t FailureTime;
};
- class DLL_PUBLIC TablePatch {
- public:
- TablePatch();
-
- TableName src;
- TableName dest;
- PrimaryKey pk;
- ColumnNames cols;
- SqlWriter * insteadOfDelete;
- SqlWriter * where;
- SqlWriter * order;
- };
-
/// Exception thrown when finishing a connection that still has a transaction open.
class DLL_PUBLIC TransactionStillOpen : public AdHoc::StdException {
private:
diff --git a/libdbpp/tablepatch.cpp b/libdbpp/tablepatch.cpp
index 1aea416..114a2b4 100644
--- a/libdbpp/tablepatch.cpp
+++ b/libdbpp/tablepatch.cpp
@@ -1,12 +1,20 @@
#include "connection.h"
#include "modifycommand.h"
#include "selectcommand.h"
+#include "tablepatch.h"
#include "sqlWriter.h"
#include <buffer.h>
#include <safeMapFind.h>
#include <scopeExit.h>
#include <boost/algorithm/string/join.hpp>
+DB::TablePatch::TablePatch() :
+ insteadOfDelete(nullptr),
+ where(nullptr),
+ order(nullptr)
+{
+}
+
DB::PatchResult
DB::Connection::patchTable(TablePatch * tp)
{
diff --git a/libdbpp/tablepatch.h b/libdbpp/tablepatch.h
index 9615b5c..b197254 100644
--- a/libdbpp/tablepatch.h
+++ b/libdbpp/tablepatch.h
@@ -8,15 +8,38 @@
#include <modifycommand.h>
#include <selectcommand.h>
-class TablePatch {
- public:
+namespace DB {
+ class SqlWriter;
+ /// Table patch settings.
+ class DLL_PUBLIC TablePatch {
+ private:
+ typedef std::string TableName;
+ typedef std::string ColumnName;
+ typedef std::set<ColumnName> ColumnNames;
+ typedef ColumnNames PrimaryKey;
+ typedef PrimaryKey::const_iterator PKI;
- private:
- void doDeletes(DynamicSql::SqlWriterPtr insteadOfDelete, DynamicSql::SqlWriterPtr where, DynamicSql::SqlWriterPtr order);
- void doUpdates(DynamicSql::SqlWriterPtr where, DynamicSql::SqlWriterPtr order);
- void doInserts(DynamicSql::SqlWriterPtr order);
-};
+ public:
+ /// Default constructor
+ TablePatch();
+
+ /// Source table name.
+ TableName src;
+ /// Destination table name.
+ TableName dest;
+ /// Columns comprising the [effective] primary key.
+ PrimaryKey pk;
+ /// Columns to be updated in the path.
+ ColumnNames cols;
+ /// An optional SQL writer to replace the default delete operation.
+ SqlWriter * insteadOfDelete;
+ /// An optional SQL writer to append a where clause.
+ SqlWriter * where;
+ /// An optional SQL writer to append an order by clause.
+ SqlWriter * order;
+ };
+}
#endif
diff --git a/libdbpp/unittests/testPatch.cpp b/libdbpp/unittests/testPatch.cpp
index a393f8c..2b44d07 100644
--- a/libdbpp/unittests/testPatch.cpp
+++ b/libdbpp/unittests/testPatch.cpp
@@ -5,6 +5,7 @@
#include <definedDirs.h>
#include <pq-mock.h>
#include <command.h>
+#include <tablepatch.h>
#include <sqlWriter.h>
#include <buffer.h>