From a449583472214fbbef19521e626b522ab7e3fd24 Mon Sep 17 00:00:00 2001 From: randomdan Date: Thu, 10 Feb 2011 19:10:31 +0000 Subject: Rename OdbcVariableBinder, it's not (anymore) ODBC specific Make rdbmsDataSource's type an int, string was just silly --- project2/rdbmsDataSource.cpp | 24 +++++++++++------------- project2/rdbmsDataSource.h | 2 +- project2/sqlCheck.cpp | 2 +- project2/sqlMergeTask.cpp | 4 ++-- project2/sqlRows.cpp | 2 +- project2/sqlTask.cpp | 2 +- project2/sqlVariableBinder.cpp | 30 +++++++++++++++--------------- project2/sqlVariableBinder.h | 8 ++++---- 8 files changed, 36 insertions(+), 38 deletions(-) diff --git a/project2/rdbmsDataSource.cpp b/project2/rdbmsDataSource.cpp index 6d9e566..0c37814 100644 --- a/project2/rdbmsDataSource.cpp +++ b/project2/rdbmsDataSource.cpp @@ -6,11 +6,14 @@ #include #include +static const int NOTSET = 0; #ifdef WITH_PQ #include "../libpqpp/connection.h" +static const int PQ_TYPEID = 1; #endif #ifdef WITH_ODBC #include "../libodbcpp/connection.h" +static const int ODBC_TYPEID = 2; #endif class UnknownConnectionProvider : public std::exception { }; @@ -202,21 +205,22 @@ RdbmsDataSource::RdbmsConnection::isExpired() const return (time(NULL) > lastUsedTime + keepAliveTime); } -RdbmsDataSource::ConnectionInfo::ConnectionInfo(const xmlpp::Element * n) +RdbmsDataSource::ConnectionInfo::ConnectionInfo(const xmlpp::Element * n) : + typeId(NOTSET) { #if WITH_ODBC BOOST_FOREACH(const xmlpp::Node * node, n->find("odbc")) { - type = "ODBC"; + typeId = ODBC_TYPEID; dsn = dynamic_cast(node)->get_child_text()->get_content(); } #endif #if WITH_PQ BOOST_FOREACH(const xmlpp::Node * node, n->find("postgresql")) { - type = "PQ"; + typeId = PQ_TYPEID; dsn = dynamic_cast(node)->get_child_text()->get_content(); } #endif - if (type.empty() || dsn.empty()) { + if (typeId == NOTSET || dsn.empty()) { throw UnknownConnectionProvider(); } } @@ -225,12 +229,12 @@ DB::Connection * RdbmsDataSource::ConnectionInfo::connect() const { #if WITH_ODBC - if (type == "ODBC") { + if (typeId == ODBC_TYPEID) { return new ODBC::Connection(dsn); } #endif #if WITH_PQ - if (type == "PQ") { + if (typeId == PQ_TYPEID) { return new PQ::Connection(dsn); } #endif @@ -240,12 +244,6 @@ RdbmsDataSource::ConnectionInfo::connect() const bool RdbmsDataSource::ConnectionInfo::operator<(const RdbmsDataSource::ConnectionInfo & other) const { - if (type < other.type) { - return true; - } - if (type == other.type && dsn < other.dsn) { - return true; - } - return false; + return ((typeId < other.typeId) || ((typeId == other.typeId) && (dsn < other.dsn))); } diff --git a/project2/rdbmsDataSource.h b/project2/rdbmsDataSource.h index 84c6d03..04c4b88 100644 --- a/project2/rdbmsDataSource.h +++ b/project2/rdbmsDataSource.h @@ -34,7 +34,7 @@ class RdbmsDataSource : public DataSource { private: std::string dsn; - std::string type; + int typeId; }; typedef boost::shared_ptr ConnectionPtr; diff --git a/project2/sqlCheck.cpp b/project2/sqlCheck.cpp index c8d5a23..afb880a 100644 --- a/project2/sqlCheck.cpp +++ b/project2/sqlCheck.cpp @@ -80,7 +80,7 @@ bool SqlCheck::performCheck() const { BOOST_FOREACH(Parameters::value_type p, parameters) { - boost::apply_visitor(OdbcVariableBinder(query, atoi(p.second->name.c_str())), p.second->value); + boost::apply_visitor(SqlVariableBinder(query, atoi(p.second->name.c_str())), p.second->value); } HandleDoCompare h(testValue, testOp); while (query->fetch()) { diff --git a/project2/sqlMergeTask.cpp b/project2/sqlMergeTask.cpp index 12e8a48..0008f72 100644 --- a/project2/sqlMergeTask.cpp +++ b/project2/sqlMergeTask.cpp @@ -25,7 +25,7 @@ class SqlMergeInsert : public IHaveParameters, public virtual SourceObject, publ void execute() const { unsigned int col = 0; BOOST_FOREACH(const Parameters::value_type & v, parameters) { - boost::apply_visitor(OdbcVariableBinder(insert, col++), v.second->value); + boost::apply_visitor(SqlVariableBinder(insert, col++), v.second->value); } insert->execute(); } @@ -255,7 +255,7 @@ class Populate : public NoOutputExecute { unsigned int cols = iter->columnCount(); for (unsigned int c = 0; c < cols; c += 1) { try { - boost::apply_visitor(OdbcVariableBinder(cmd, idxs[c]), iter->getCurrentValue(c)); + boost::apply_visitor(SqlVariableBinder(cmd, idxs[c]), iter->getCurrentValue(c)); } catch (const RowSet::FieldDoesNotExist &) { cmd->bindNull(idxs[c]); diff --git a/project2/sqlRows.cpp b/project2/sqlRows.cpp index ebd0a4b..4758dd4 100644 --- a/project2/sqlRows.cpp +++ b/project2/sqlRows.cpp @@ -215,7 +215,7 @@ SqlRows::SqlParameter::writeSql(Glib::ustring & sql) const void SqlRows::SqlParameter::bindParams(const RowProcessor * rp, DB::SelectCommand * cmd, unsigned int & offset) const { - boost::apply_visitor(OdbcVariableBinder(cmd, offset++), rp->getParameter(name)); + boost::apply_visitor(SqlVariableBinder(cmd, offset++), rp->getParameter(name)); } SqlRows::SqlText::SqlText(const xmlpp::TextNode * n) : diff --git a/project2/sqlTask.cpp b/project2/sqlTask.cpp index 543dd41..eb28d26 100644 --- a/project2/sqlTask.cpp +++ b/project2/sqlTask.cpp @@ -33,7 +33,7 @@ void SqlTask::execute() const { BOOST_FOREACH(Parameters::value_type p, parameters) { - boost::apply_visitor(OdbcVariableBinder(modify, atoi(p.second->name.c_str())), p.second->value); + boost::apply_visitor(SqlVariableBinder(modify, atoi(p.second->name.c_str())), p.second->value); } modify->execute(); } diff --git a/project2/sqlVariableBinder.cpp b/project2/sqlVariableBinder.cpp index bc5b235..22cf34a 100644 --- a/project2/sqlVariableBinder.cpp +++ b/project2/sqlVariableBinder.cpp @@ -2,80 +2,80 @@ #include "command.h" #include -OdbcVariableBinder::OdbcVariableBinder(DB::Command * c, unsigned int i) : +SqlVariableBinder::SqlVariableBinder(DB::Command * c, unsigned int i) : cmd(c), idx(i) { } void -OdbcVariableBinder::operator()(const Glib::ustring & i) const +SqlVariableBinder::operator()(const Glib::ustring & i) const { cmd->bindParamS(idx, i); } void -OdbcVariableBinder::operator()(const boost::shared_ptr & i) const +SqlVariableBinder::operator()(const boost::shared_ptr & i) const { if (!i) return cmd->bindNull(idx); (*this)(*i); } void -OdbcVariableBinder::operator()(const long long unsigned int & i) const +SqlVariableBinder::operator()(const long long unsigned int & i) const { cmd->bindParamI(idx, i); } void -OdbcVariableBinder::operator()(const long unsigned int & i) const +SqlVariableBinder::operator()(const long unsigned int & i) const { cmd->bindParamI(idx, i); } void -OdbcVariableBinder::operator()(const unsigned int & i) const +SqlVariableBinder::operator()(const unsigned int & i) const { cmd->bindParamI(idx, i); } void -OdbcVariableBinder::operator()(const short unsigned int & i) const +SqlVariableBinder::operator()(const short unsigned int & i) const { cmd->bindParamI(idx, i); } void -OdbcVariableBinder::operator()(const long long int & i) const +SqlVariableBinder::operator()(const long long int & i) const { cmd->bindParamI(idx, i); } void -OdbcVariableBinder::operator()(const long int & i) const +SqlVariableBinder::operator()(const long int & i) const { cmd->bindParamI(idx, i); } void -OdbcVariableBinder::operator()(const int & i) const +SqlVariableBinder::operator()(const int & i) const { cmd->bindParamI(idx, i); } void -OdbcVariableBinder::operator()(const short int & i) const +SqlVariableBinder::operator()(const short int & i) const { cmd->bindParamI(idx, i); } void -OdbcVariableBinder::operator()(const double & i) const +SqlVariableBinder::operator()(const double & i) const { cmd->bindParamF(idx, i); } void -OdbcVariableBinder::operator()(const float & i) const +SqlVariableBinder::operator()(const float & i) const { cmd->bindParamF(idx, i); } void -OdbcVariableBinder::operator()(const boost::posix_time::ptime & i) const +SqlVariableBinder::operator()(const boost::posix_time::ptime & i) const { struct tm tm(boost::posix_time::to_tm(i)); cmd->bindParamT(idx, &tm); } void -OdbcVariableBinder::operator()(const boost::shared_ptr & i) const +SqlVariableBinder::operator()(const boost::shared_ptr & i) const { if (!i) return cmd->bindNull(idx); (*this)(*i); diff --git a/project2/sqlVariableBinder.h b/project2/sqlVariableBinder.h index 5a75f07..2839e34 100644 --- a/project2/sqlVariableBinder.h +++ b/project2/sqlVariableBinder.h @@ -1,5 +1,5 @@ -#ifndef ODBCVARIABLEBINDER_H -#define ODBCVARIABLEBINDER_H +#ifndef SQLVARIABLEBINDER_H +#define SQLVARIABLEBINDER_H #include #include @@ -9,9 +9,9 @@ namespace DB { class Command; } -class OdbcVariableBinder : public boost::static_visitor<> { +class SqlVariableBinder : public boost::static_visitor<> { public: - OdbcVariableBinder(DB::Command * c, unsigned int i); + SqlVariableBinder(DB::Command * c, unsigned int i); void operator()(const Glib::ustring & i) const; void operator()(const boost::shared_ptr & i) const; void operator()(const long long unsigned int & i) const; -- cgit v1.2.3