diff options
author | randomdan <randomdan@localhost> | 2011-02-10 19:10:31 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-02-10 19:10:31 +0000 |
commit | eae577fee5efd194554d9440c5202a91c91d10b2 (patch) | |
tree | cbd1a3a7b021040cece5b84a5d23195110d222d0 | |
parent | Get rid of that stupid LexicalCall and it's messy templates (what WAS I think... (diff) | |
download | project2-eae577fee5efd194554d9440c5202a91c91d10b2.tar.bz2 project2-eae577fee5efd194554d9440c5202a91c91d10b2.tar.xz project2-eae577fee5efd194554d9440c5202a91c91d10b2.zip |
Rename OdbcVariableBinder, it's not (anymore) ODBC specific
Make rdbmsDataSource's type an int, string was just silly
-rw-r--r-- | project2/rdbmsDataSource.cpp | 24 | ||||
-rw-r--r-- | project2/rdbmsDataSource.h | 2 | ||||
-rw-r--r-- | project2/sqlCheck.cpp | 2 | ||||
-rw-r--r-- | project2/sqlMergeTask.cpp | 4 | ||||
-rw-r--r-- | project2/sqlRows.cpp | 2 | ||||
-rw-r--r-- | project2/sqlTask.cpp | 2 | ||||
-rw-r--r-- | project2/sqlVariableBinder.cpp | 30 | ||||
-rw-r--r-- | 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 <errno.h> #include <sqlext.h> +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<const xmlpp::Element *>(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<const xmlpp::Element *>(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<RdbmsConnection> 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<const OdbcVariableBinder, const VariableType>(OdbcVariableBinder(query, atoi(p.second->name.c_str())), p.second->value); + boost::apply_visitor<const SqlVariableBinder, const VariableType>(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<const OdbcVariableBinder, const VariableType>(OdbcVariableBinder(insert, col++), v.second->value); + boost::apply_visitor<const SqlVariableBinder, const VariableType>(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<const OdbcVariableBinder, const VariableType>(OdbcVariableBinder(cmd, idxs[c]), iter->getCurrentValue(c)); + boost::apply_visitor<const SqlVariableBinder, const VariableType>(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<const OdbcVariableBinder, const VariableType>(OdbcVariableBinder(cmd, offset++), rp->getParameter(name)); + boost::apply_visitor<const SqlVariableBinder, const VariableType>(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<const OdbcVariableBinder, const VariableType>(OdbcVariableBinder(modify, atoi(p.second->name.c_str())), p.second->value); + boost::apply_visitor<const SqlVariableBinder, const VariableType>(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 <boost/date_time/posix_time/conversion.hpp> -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<const Glib::ustring> & i) const +SqlVariableBinder::operator()(const boost::shared_ptr<const Glib::ustring> & 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<const boost::posix_time::ptime> & i) const +SqlVariableBinder::operator()(const boost::shared_ptr<const boost::posix_time::ptime> & 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 <boost/variant.hpp> #include <boost/shared_ptr.hpp> @@ -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<const Glib::ustring> & i) const; void operator()(const long long unsigned int & i) const; |