#include "sqlCheck.h" #include "xmlObjectLoader.h" #include "selectcommand.h" #include "column.h" #include "rdbmsDataSource.h" #include #include "commonObjects.h" ElementLoaderImpl sqlCheckLoader("sqlcheck"); SqlCheck::SqlCheck(const xmlpp::Element * p) : SourceObject(p), IHaveParameters(p), ParamChecker(p), dataSource(p->get_attribute_value("datasource")), sql(xmlChildText(p, "sql")), testOp(p->get_attribute_value("testOp")), testValue(atof(p->get_attribute_value("testValue").c_str())), query(NULL) { } SqlCheck::~SqlCheck() { delete query; } void SqlCheck::loadComplete(const CommonObjects * co) { query = new ODBC::SelectCommand(co->dataSource(dataSource)->getReadonly(), sql); } bool SqlCheck::performCheck() const { BOOST_FOREACH(Parameters::value_type p, parameters) { query->bindParamS(atoi(p.second->name.c_str()), p.second->value); } bool retVal = false; while (query->fetch()) { int val = (*query)[0]; if ((testOp == "==" || testOp == "=") && val == testValue) { retVal = true; } else if (testOp == "<" && val < testValue) { retVal = true; } else if (testOp == ">" && val > testValue) { retVal = true; } else if (testOp == "!=" && val != testValue) { retVal = true; } else if ((testOp == "<=" || testOp == "=<") && val <= testValue) { retVal = true; } else if ((testOp == ">=" || testOp == "=>") && val >= testValue) { retVal = true; } } return retVal; }