From dc1db64c6f99b8c87e93161ca1e25224ea9e615c Mon Sep 17 00:00:00 2001 From: randomdan Date: Tue, 13 Jul 2010 22:32:39 +0000 Subject: Reuse select commands for sql view and iterate --- project2/sqlIterate.cpp | 11 ++++++++--- project2/sqlIterate.h | 1 + project2/sqlTask.cpp | 1 - project2/sqlView.cpp | 11 ++++++++--- project2/sqlView.h | 1 + 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/project2/sqlIterate.cpp b/project2/sqlIterate.cpp index 81f1561..e80e1ee 100644 --- a/project2/sqlIterate.cpp +++ b/project2/sqlIterate.cpp @@ -20,6 +20,11 @@ _SqlIterate::_SqlIterate(const xmlpp::Element * p) : { } +_SqlIterate::~_SqlIterate() +{ + delete query; +} + Glib::ustring _SqlIterate::getCurrentValue(const Glib::ustring & id) const { @@ -28,14 +33,14 @@ _SqlIterate::getCurrentValue(const Glib::ustring & id) const void _SqlIterate::execute(const ApplicationEngine * ep, const PerRowValues * parent) const { - query = new ODBC::SelectCommand(ep->dataSource<_RdbmsDataSource>(dataSource)->getReadonly(), sql); + if (!query) { + query = new ODBC::SelectCommand(ep->dataSource<_RdbmsDataSource>(dataSource)->getReadonly(), sql); + } BOOST_FOREACH(Parameters::value_type p, parameters) { query->bindParamS(p.second->bind, p.second->value()); } while (query->fetch()) { executeChildren(ep, this); } - delete query; - query = NULL; } diff --git a/project2/sqlIterate.h b/project2/sqlIterate.h index 0c26bdd..382bf38 100644 --- a/project2/sqlIterate.h +++ b/project2/sqlIterate.h @@ -13,6 +13,7 @@ class ApplicationEngine; class _SqlIterate : public IHaveParameters, public _Iterate { public: _SqlIterate(const xmlpp::Element * p); + ~_SqlIterate(); void execute(const ApplicationEngine *, const PerRowValues * parent = NULL) const; Glib::ustring getCurrentValue(const Glib::ustring & id) const; const std::string dataSource; diff --git a/project2/sqlTask.cpp b/project2/sqlTask.cpp index 930502c..08da656 100644 --- a/project2/sqlTask.cpp +++ b/project2/sqlTask.cpp @@ -4,7 +4,6 @@ #include "modifycommand.h" #include "appEngine.h" #include "rdbmsDataSource.h" -#include "sqlView.h" _SqlTask::_SqlTask(const xmlpp::Element * p) : _SourceObject(p), diff --git a/project2/sqlView.cpp b/project2/sqlView.cpp index 41fa441..7995ca9 100644 --- a/project2/sqlView.cpp +++ b/project2/sqlView.cpp @@ -21,6 +21,11 @@ _SqlView::_SqlView(const xmlpp::Element * p) : _LoaderBase::collectAll(loaders, "project2", p, true, true); } +_SqlView::~_SqlView() +{ + delete query; +} + Glib::ustring _SqlView::getCurrentValue(const Glib::ustring & id) const { @@ -30,7 +35,9 @@ _SqlView::getCurrentValue(const Glib::ustring & id) const void _SqlView::execute(xmlpp::Element * par, const ApplicationEngine * ep, const _View * parent) const { typedef std::map Columns; - query = new ODBC::SelectCommand(ep->dataSource<_RdbmsDataSource>(dataSource)->getReadonly(), sql); + if (!query) { + query = new ODBC::SelectCommand(ep->dataSource<_RdbmsDataSource>(dataSource)->getReadonly(), sql); + } BOOST_FOREACH(Parameters::value_type p, parameters) { query->bindParamS(p.second->bind, p.second->value); } @@ -81,7 +88,5 @@ void _SqlView::execute(xmlpp::Element * par, const ApplicationEngine * ep, const } executeChildren(record, ep, this); } - delete query; - query = NULL; } diff --git a/project2/sqlView.h b/project2/sqlView.h index 5fd8a48..c025c88 100644 --- a/project2/sqlView.h +++ b/project2/sqlView.h @@ -14,6 +14,7 @@ class ApplicationEngine; class _SqlView : public IHaveParameters, public _View { public: _SqlView(const xmlpp::Element * p); + ~_SqlView(); void execute(xmlpp::Element *, const ApplicationEngine *, const _View * parent = NULL) const; Glib::ustring getCurrentValue(const Glib::ustring & id) const; const std::string dataSource; -- cgit v1.2.3