diff options
author | randomdan <randomdan@localhost> | 2010-07-13 22:32:39 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2010-07-13 22:32:39 +0000 |
commit | bd844a13431fd095de257721ee552adddd0ef12f (patch) | |
tree | f1c0558975d434792ea2ace95895ca491b7b8444 | |
parent | Don't cache session variables, they can change (diff) | |
download | project2-bd844a13431fd095de257721ee552adddd0ef12f.tar.bz2 project2-bd844a13431fd095de257721ee552adddd0ef12f.tar.xz project2-bd844a13431fd095de257721ee552adddd0ef12f.zip |
Reuse select commands for sql view and iterate
-rw-r--r-- | project2/sqlIterate.cpp | 11 | ||||
-rw-r--r-- | project2/sqlIterate.h | 1 | ||||
-rw-r--r-- | project2/sqlTask.cpp | 1 | ||||
-rw-r--r-- | project2/sqlView.cpp | 11 | ||||
-rw-r--r-- | 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<std::string, xmlpp::Element *> 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; |