From cb6198827edbeb869f099e8599eb7a8924c49824 Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 9 Feb 2011 10:37:07 +0000 Subject: Make different DB connectors optional --- project2/Jamfile.jam | 22 +++++++++++++++++----- project2/dataSource.h | 1 - project2/rdbmsDataSource.cpp | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam index 8f4ca6b..53b530f 100644 --- a/project2/Jamfile.jam +++ b/project2/Jamfile.jam @@ -35,6 +35,8 @@ alias p2parts : : : : ; feature uuid : boost ossp : propagated ; +feature odbc : yes no ; +feature pq : yes no ; lib p2uuid : uuid.cpp @@ -98,16 +100,26 @@ lib p2xmlSession : p2uuid ; +obj rdbmsDataSource : + rdbmsDataSource.cpp : + yes:WITH_ODBC + yes:WITH_PQ + yes:../libodbcpp//odbcpp + yes:../libpqpp//pqpp + libxmlpp + ../libmisc//misc + ; + lib p2sql : - [ glob sql*.cpp tablepatch.cpp rdbmsDataSource.cpp ] + [ glob sql*.cpp ] tablepatch.cpp rdbmsDataSource ../libdbpp//dbpp - ../libodbcpp//odbcpp - ../libpqpp//pqpp : + yes:../libodbcpp//odbcpp + yes:../libpqpp//pqpp libxmlpp : : - ../libodbcpp//odbcpp - ../libpqpp//pqpp + yes:../libodbcpp//odbcpp + yes:../libpqpp//pqpp ; lib p2url : diff --git a/project2/dataSource.h b/project2/dataSource.h index b1147da..478feb6 100644 --- a/project2/dataSource.h +++ b/project2/dataSource.h @@ -1,7 +1,6 @@ #ifndef DATASOURCE_H #define DATASOURCE_H -#include #include #include #include "sourceObject.h" diff --git a/project2/rdbmsDataSource.cpp b/project2/rdbmsDataSource.cpp index 98e2d5a..bd3c0b1 100644 --- a/project2/rdbmsDataSource.cpp +++ b/project2/rdbmsDataSource.cpp @@ -6,8 +6,12 @@ #include #include +#ifdef WITH_PQ #include "../libpqpp/connection.h" +#endif +#ifdef WITH_ODBC #include "../libodbcpp/connection.h" +#endif class UnknownConnectionProvider : public std::exception { }; @@ -200,25 +204,36 @@ RdbmsDataSource::RdbmsConnection::isExpired() const RdbmsDataSource::ConnectionInfo::ConnectionInfo(const xmlpp::Element * n) { +#if WITH_ODBC BOOST_FOREACH(const xmlpp::Node * node, n->find("odbc")) { type = "ODBC"; dsn = dynamic_cast(node)->get_child_text()->get_content(); } +#endif +#if WITH_PQ BOOST_FOREACH(const xmlpp::Node * node, n->find("postgresql")) { type = "PQ"; dsn = dynamic_cast(node)->get_child_text()->get_content(); } +#endif + if (type.empty() || dsn.empty()) { + throw UnknownConnectionProvider(); + } } DB::Connection * RdbmsDataSource::ConnectionInfo::connect() const { +#if WITH_ODBC if (type == "ODBC") { return new ODBC::Connection(dsn); } +#endif +#if WITH_PQ if (type == "PQ") { return new PQ::Connection(dsn); } +#endif throw UnknownConnectionProvider(); } -- cgit v1.2.3