#include "sqlCheck.h" #include "xmlObjectLoader.h" #include "appEngine.h" #include "selectcommand.h" #include "column.h" #include "rdbmsDataSource.h" #include ElementLoaderImpl<_SqlCheck> 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() { query = new ODBC::SelectCommand(ApplicationEngine::getCurrent()->dataSource<_RdbmsDataSource>( dataSource)->getReadonly(), sql); } bool _SqlCheck::performCheck() const { BOOST_FOREACH(Parameters::value_type p, parameters) { query->bindParamS(p.second->bind, 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; }