diff options
author | randomdan <randomdan@localhost> | 2011-02-19 17:01:55 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-02-19 17:01:55 +0000 |
commit | afcc00ce194bcd81cd829320b2bff396d6c808e1 (patch) | |
tree | a306b9fc1fc317cc1abd1e6d01517628b9ecf3ae | |
parent | Pass null values to presenters, it's up to them what to do with them (diff) | |
download | project2-afcc00ce194bcd81cd829320b2bff396d6c808e1.tar.bz2 project2-afcc00ce194bcd81cd829320b2bff396d6c808e1.tar.xz project2-afcc00ce194bcd81cd829320b2bff396d6c808e1.zip |
Use a smart pointer to ensure sqlRows query handle is always deleted
Add CommonObjects destructor to ensure rowSets are cleared before datasources
-rw-r--r-- | project2/commonObjects.cpp | 6 | ||||
-rw-r--r-- | project2/commonObjects.h | 2 | ||||
-rw-r--r-- | project2/sqlRows.cpp | 6 | ||||
-rw-r--r-- | project2/sqlRows.h | 3 |
4 files changed, 12 insertions, 5 deletions
diff --git a/project2/commonObjects.cpp b/project2/commonObjects.cpp index 2ca4846..89eb913 100644 --- a/project2/commonObjects.cpp +++ b/project2/commonObjects.cpp @@ -2,6 +2,12 @@ #include <libxml++/parsers/domparser.h> #include <libxml/xinclude.h> +CommonObjects::~CommonObjects() +{ + rowSets.clear(); + datasources.clear(); +} + RowSetPtr CommonObjects::getSource(const std::string & name) const { diff --git a/project2/commonObjects.h b/project2/commonObjects.h index a15a8da..32be835 100644 --- a/project2/commonObjects.h +++ b/project2/commonObjects.h @@ -9,6 +9,8 @@ class CommonObjects : public virtual IntrusivePtrBase { SimpleMessageException(DataSourceNotFound); SimpleMessageException(DataSourceNotCompatible); + virtual ~CommonObjects(); + RowSetPtr getSource(const std::string &) const; template <class DataSourceType> const DataSourceType * dataSource(const std::string & name) const diff --git a/project2/sqlRows.cpp b/project2/sqlRows.cpp index 22dafa9..5a57fc7 100644 --- a/project2/sqlRows.cpp +++ b/project2/sqlRows.cpp @@ -19,7 +19,6 @@ SqlRows::SqlRows(const xmlpp::Element * p) : RowSet(p), dataSource(p, "datasource"), sqlCommand(dynamic_cast<xmlpp::Element *>(p->get_children("sql").front())), - query(NULL), db(NULL) { } @@ -110,13 +109,12 @@ SqlRows::execute(const RowProcessor * rp) const unsigned int offset = 0; Glib::ustring sql; sqlCommand.writeSql(sql); - query = db->getReadonly().newSelectCommand(sql); - sqlCommand.bindParams(rp, query, offset); + query = SelectPtr(db->getReadonly().newSelectCommand(sql)); + sqlCommand.bindParams(rp, query.get(), offset); while (query->fetch()) { rp->rowReady(); rowNum += 1; } - delete query; } SqlRows::SqlWriter::SqlWriter() diff --git a/project2/sqlRows.h b/project2/sqlRows.h index a1f4fab..099a56b 100644 --- a/project2/sqlRows.h +++ b/project2/sqlRows.h @@ -78,7 +78,8 @@ class SqlRows : public RowSet { Writers writers; }; SqlCommand sqlCommand; - mutable DB::SelectCommand * query; + typedef boost::shared_ptr<DB::SelectCommand> SelectPtr; + mutable SelectPtr query; const RdbmsDataSource * db; }; |