From 65b2e133e14cd667e98537db594b14faadb7e70c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 29 Dec 2015 03:32:42 +0000 Subject: Move TablePatch to its own files --- libdbpp/connection.cpp | 7 ------- libdbpp/connection.h | 15 +-------------- libdbpp/tablepatch.cpp | 8 ++++++++ libdbpp/tablepatch.h | 37 ++++++++++++++++++++++++++++++------- libdbpp/unittests/testPatch.cpp | 1 + 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 #include #include #include +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 #include -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 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 #include #include +#include #include #include -- cgit v1.2.3