diff options
author | randomdan <randomdan@localhost> | 2011-08-12 01:09:15 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-08-12 01:09:15 +0000 |
commit | f813f5f40927357e5a9a67db87c19bae62780b2b (patch) | |
tree | dc110ec024e6db28f298a6e41b8c619da27fbf93 | |
parent | Move the SqlWriter outside of SqlRows and make it work on generic commands (diff) | |
download | project2-f813f5f40927357e5a9a67db87c19bae62780b2b.tar.bz2 project2-f813f5f40927357e5a9a67db87c19bae62780b2b.tar.xz project2-f813f5f40927357e5a9a67db87c19bae62780b2b.zip |
Use the new dynamic sql builder to build sqlTask's SQL and bind its parameters from a more user friendly source
-rw-r--r-- | project2/sqlRows.h | 2 | ||||
-rw-r--r-- | project2/sqlTask.cpp | 16 | ||||
-rw-r--r-- | project2/sqlTask.h | 11 |
3 files changed, 15 insertions, 14 deletions
diff --git a/project2/sqlRows.h b/project2/sqlRows.h index 6cdd716..5614fa1 100644 --- a/project2/sqlRows.h +++ b/project2/sqlRows.h @@ -23,7 +23,7 @@ class SqlRows : public RowSet { const Variable dataSource; private: - DynamicSql::SqlCommand sqlCommand; + const DynamicSql::SqlCommand sqlCommand; typedef boost::shared_ptr<DB::SelectCommand> SelectPtr; class SqlState : public RowState { public: diff --git a/project2/sqlTask.cpp b/project2/sqlTask.cpp index 61bff46..3a1d334 100644 --- a/project2/sqlTask.cpp +++ b/project2/sqlTask.cpp @@ -30,10 +30,9 @@ class SqlIfChangesStorer : public StorerBase<NoOutputExecute, ANONORDEREDSTORAGE SqlTask::SqlTask(const xmlpp::Element * p) : SourceObject(p), Task(p), - IHaveParameters(p), dataSource(p, "datasource"), - sql(xmlChildText(p, "sql")), - modify(NULL) + filter(p, "filter", false, ""), + sqlCommand(dynamic_cast<xmlpp::Element *>(p->get_children("sql").front())) { LoaderBase loader(true); loader.supportedStorers.insert(new SqlIfChangesStorer(&changesNOEs, &noChangesNOEs)); @@ -42,22 +41,21 @@ SqlTask::SqlTask(const xmlpp::Element * p) : SqlTask::~SqlTask() { - delete modify; } void SqlTask::loadComplete(const CommonObjects * co) { - modify = co->dataSource<RdbmsDataSource>(dataSource())->getWritable().newModifyCommand(sql); + db = co->dataSource<RdbmsDataSource>(dataSource()); } void SqlTask::execute() const { - BOOST_FOREACH(Parameters::value_type p, parameters) { - boost::apply_visitor<const SqlVariableBinder, const VariableType>(SqlVariableBinder(modify, - atoi(p.second->name.c_str())), p.second->value); - } + boost::shared_ptr<DB::ModifyCommand> modify = boost::shared_ptr<DB::ModifyCommand>( + db->getWritable().newModifyCommand(sqlCommand.getSqlFor(filter()))); + unsigned int offset = 0; + sqlCommand.bindParams(modify.get(), offset); if (modify->execute() == 0) { BOOST_FOREACH(const SubNOEs::value_type & sq, noChangesNOEs) { sq->execute(); diff --git a/project2/sqlTask.h b/project2/sqlTask.h index 3815a90..384b000 100644 --- a/project2/sqlTask.h +++ b/project2/sqlTask.h @@ -5,12 +5,14 @@ #include <boost/intrusive_ptr.hpp> #include <map> #include "task.h" -#include "iHaveParameters.h" +#include "variables.h" +#include "sqlWriter.h" namespace DB { class ModifyCommand; } +class RdbmsDataSource; /// Project2 component to execute a modifying SQL statement against an RDBMS data source -class SqlTask : public Task, IHaveParameters { +class SqlTask : public Task { public: SqlTask(const xmlpp::Element * p); virtual ~SqlTask(); @@ -18,14 +20,15 @@ class SqlTask : public Task, IHaveParameters { virtual void execute() const; const Variable dataSource; - const std::string sql; + const Variable filter; typedef ANONORDEREDSTORAGEOF(NoOutputExecute) SubNOEs; SubNOEs changesNOEs; SubNOEs noChangesNOEs; protected: - mutable DB::ModifyCommand * modify; + const DynamicSql::SqlCommand sqlCommand; + const RdbmsDataSource * db; }; #endif |