From 82ed8beb41e9b9c96f4f16177578544dd02c6a79 Mon Sep 17 00:00:00 2001 From: randomdan Date: Tue, 10 Dec 2013 22:23:38 +0000 Subject: Centralise the DB code --- p2pvr/lib/dbClient.cpp | 22 ++++++++++++++++++++++ p2pvr/lib/dbClient.h | 18 ++++++++++++++++++ p2pvr/lib/si.cpp | 19 ------------------- p2pvr/lib/si.h | 10 ++-------- 4 files changed, 42 insertions(+), 27 deletions(-) create mode 100644 p2pvr/lib/dbClient.cpp create mode 100644 p2pvr/lib/dbClient.h diff --git a/p2pvr/lib/dbClient.cpp b/p2pvr/lib/dbClient.cpp new file mode 100644 index 0000000..e085c86 --- /dev/null +++ b/p2pvr/lib/dbClient.cpp @@ -0,0 +1,22 @@ +#include "dbClient.h" +#include +#include + +DatabaseClient::SelectPtr +DatabaseClient::Select(const std::string & sql) const +{ + auto db = dataSource("postgres"); + return SelectPtr(db->getReadonly().newSelectCommand(sql)); +} +DatabaseClient::SelectPtr +DatabaseClient::Select(const std::string & sql, const std::list & vs) const +{ + SelectPtr sel(Select(sql)); + unsigned int offset = 0; + BOOST_FOREACH(const auto & v, vs) { + boost::apply_visitor(SqlVariableBinder(sel.get(), offset++), v); + } + return sel; +} + + diff --git a/p2pvr/lib/dbClient.h b/p2pvr/lib/dbClient.h new file mode 100644 index 0000000..62dafef --- /dev/null +++ b/p2pvr/lib/dbClient.h @@ -0,0 +1,18 @@ +#ifndef DBCLIENT_H +#define DBCLIENT_H + +#include +#include +#include +#include + +class DatabaseClient : public virtual CommonObjects { + public: + typedef boost::shared_ptr SelectPtr; + protected: + SelectPtr Select(const std::string &) const; + SelectPtr Select(const std::string &, const std::list &) const; +}; + +#endif + diff --git a/p2pvr/lib/si.cpp b/p2pvr/lib/si.cpp index 98b2316..e63e060 100644 --- a/p2pvr/lib/si.cpp +++ b/p2pvr/lib/si.cpp @@ -2,26 +2,7 @@ #include "dvbsiHelpers.h" #include "sqlContainerCreator.h" #include -#include #include -#include - -SI::SelectPtr -SI::Select(const std::string & sql) const -{ - auto db = dataSource("postgres"); - return SelectPtr(db->getReadonly().newSelectCommand(sql)); -} -SI::SelectPtr -SI::Select(const std::string & sql, const std::list & vs) const -{ - SelectPtr sel(Select(sql)); - unsigned int offset = 0; - BOOST_FOREACH(const auto & v, vs) { - boost::apply_visitor(SqlVariableBinder(sel.get(), offset++), v); - } - return sel; -} P2PVR::Deliveries SI::GetAllDeliveries(short type, const Ice::Current &) diff --git a/p2pvr/lib/si.h b/p2pvr/lib/si.h index 508c0fe..053ac77 100644 --- a/p2pvr/lib/si.h +++ b/p2pvr/lib/si.h @@ -2,21 +2,15 @@ #define P2PVR_SI_H #include -#include -#include +#include "dbClient.h" -class SI : public P2PVR::SI, public virtual CommonObjects { +class SI : public P2PVR::SI, public DatabaseClient { public: - typedef boost::shared_ptr SelectPtr; - P2PVR::Deliveries GetAllDeliveries(short type, const Ice::Current &); DVBSI::DeliveryPtr GetDeliveryForService(int id, const Ice::Current &); DVBSI::DeliveryPtr GetDeliveryForTransport(int id, const Ice::Current &); DVBSI::ServiceList GetServices(const Ice::Current &); DVBSI::ServicePtr GetService(int id, const Ice::Current &); - protected: - SelectPtr Select(const std::string &) const; - SelectPtr Select(const std::string &, const std::list &) const; }; #endif -- cgit v1.2.3