diff options
-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 |