summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-08-12 19:31:11 +0000
committerrandomdan <randomdan@localhost>2011-08-12 19:31:11 +0000
commitabf584221e07e4d3e5126e7c6ce520d8f7bf6975 (patch)
tree55a54d786180d4c76ef98af92450f7baa81fbb60
parentUse the new dynamic sql builder to build sqlTask's SQL and bind its parameter... (diff)
downloadproject2-abf584221e07e4d3e5126e7c6ce520d8f7bf6975.tar.bz2
project2-abf584221e07e4d3e5126e7c6ce520d8f7bf6975.tar.xz
project2-abf584221e07e4d3e5126e7c6ce520d8f7bf6975.zip
Don't use parameters in sqlCheck anymore... just like sqlTask yesterday
-rw-r--r--project2/sqlCheck.cpp21
-rw-r--r--project2/sqlCheck.h15
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