diff options
author | randomdan <randomdan@localhost> | 2011-08-12 19:31:11 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-08-12 19:31:11 +0000 |
commit | b750f27017a8aabe27769bb45325ac76e12f1712 (patch) | |
tree | 55a54d786180d4c76ef98af92450f7baa81fbb60 | |
parent | Use the new dynamic sql builder to build sqlTask's SQL and bind its parameter... (diff) | |
download | project2-b750f27017a8aabe27769bb45325ac76e12f1712.tar.bz2 project2-b750f27017a8aabe27769bb45325ac76e12f1712.tar.xz project2-b750f27017a8aabe27769bb45325ac76e12f1712.zip |
Don't use parameters in sqlCheck anymore... just like sqlTask yesterday
-rw-r--r-- | project2/sqlCheck.cpp | 21 | ||||
-rw-r--r-- | project2/sqlCheck.h | 15 |
2 files changed, 19 insertions, 17 deletions
diff --git a/project2/sqlCheck.cpp b/project2/sqlCheck.cpp index c89608b..d86eb3b 100644 --- a/project2/sqlCheck.cpp +++ b/project2/sqlCheck.cpp @@ -13,25 +13,23 @@ DECLARE_LOADER("sqlcheck", SqlCheck); class CantCompareNulls : public std::exception { }; SqlCheck::SqlCheck(const xmlpp::Element * p) : - IHaveParameters(p), ParamChecker(p), dataSource(p, "datasource"), - sql(xmlChildText(p, "sql")), - testOp(p->get_attribute_value("testOp")), - testValue(atof(p->get_attribute_value("testValue").c_str())), - query(NULL) + filter(p, "filter", false, ""), + testOp(p, "testOp", false, "=="), + testValue(p, "testValue"), + sqlCommand(dynamic_cast<xmlpp::Element *>(p->get_children("sql").front())) { } SqlCheck::~SqlCheck() { - delete query; } void SqlCheck::loadComplete(const CommonObjects * co) { - query = co->dataSource<RdbmsDataSource>(dataSource())->getReadonly().newSelectCommand(sql); + db = co->dataSource<RdbmsDataSource>(dataSource()); } class HandleDoCompare : public DB::HandleField { @@ -89,10 +87,11 @@ class HandleDoCompare : public DB::HandleField { bool SqlCheck::performCheck() const { - BOOST_FOREACH(Parameters::value_type p, parameters) { - boost::apply_visitor<const SqlVariableBinder, const VariableType>(SqlVariableBinder(query, atoi(p.second->name.c_str())), p.second->value); - } - HandleDoCompare h(testValue, testOp); + boost::shared_ptr<DB::SelectCommand> query = boost::shared_ptr<DB::SelectCommand>( + db->getWritable().newSelectCommand(sqlCommand.getSqlFor(filter()))); + unsigned int offset = 0; + sqlCommand.bindParams(query.get(), offset); + HandleDoCompare h(testValue, testOp()); while (query->fetch()) { (*query)[0].apply(h); } diff --git a/project2/sqlCheck.h b/project2/sqlCheck.h index 1f2937f..c9933d7 100644 --- a/project2/sqlCheck.h +++ b/project2/sqlCheck.h @@ -2,12 +2,13 @@ #define SQLCHECK_H #include "paramChecker.h" -#include "iHaveParameters.h" +#include "sqlWriter.h" namespace DB { class SelectCommand; } +class RdbmsDataSource; /// Project2 component to check the value of a variable against an RDBMS data source -class SqlCheck : IHaveParameters, public ParamChecker { +class SqlCheck : public ParamChecker { public: SqlCheck(const xmlpp::Element * p); virtual ~SqlCheck(); @@ -16,11 +17,13 @@ class SqlCheck : IHaveParameters, public ParamChecker { bool performCheck() const; const Variable dataSource; - const Glib::ustring sql; - const std::string testOp; - const VariableType testValue; + const Variable filter; + const Variable testOp; + const Variable testValue; + private: - DB::SelectCommand * query; + const DynamicSql::SqlCommand sqlCommand; + const RdbmsDataSource * db; }; #endif |