summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project2/console/consoleEnvironment.cpp24
-rw-r--r--project2/console/consoleEnvironment.h4
-rw-r--r--project2/environment.cpp8
-rw-r--r--project2/fileStrmVarWriter.cpp3
-rw-r--r--project2/fileStrmVarWriter.h1
-rw-r--r--project2/rdbmsDataSource.cpp2
-rw-r--r--project2/sqlRows.cpp4
-rw-r--r--project2/sqlVariableBinder.cpp8
-rw-r--r--project2/sqlVariableBinder.h2
-rw-r--r--project2/variableConvert.cpp18
-rw-r--r--project2/variables.h2
11 files changed, 57 insertions, 19 deletions
diff --git a/project2/console/consoleEnvironment.cpp b/project2/console/consoleEnvironment.cpp
index 6b2a753..f2d4667 100644
--- a/project2/console/consoleEnvironment.cpp
+++ b/project2/console/consoleEnvironment.cpp
@@ -7,18 +7,18 @@
#include "../exceptions.h"
#include <iostream>
#include <string>
+#include <boost/algorithm/string/predicate.hpp>
#include <boost/program_options.hpp>
+#include <boost/bind.hpp>
namespace po = boost::program_options;
template<typename _CharT, typename _Traits>
std::basic_istream<_CharT, _Traits> &
-operator>>(std::basic_istream<_CharT, _Traits> & s, ConsoleEnvironment::QueryParams & q)
+operator>>(std::basic_istream<_CharT, _Traits> & s, ConsoleEnvironment::QueryParams::value_type & q)
{
- std::string n, v;
- std::getline(s, n, '=');
- std::getline(s, v);
- q.insert(ConsoleEnvironment::QueryParams::value_type(n, v));
+ std::getline(s, q.first, '=');
+ std::getline(s, q.second);
return s;
}
@@ -40,7 +40,8 @@ ConsoleEnvironment::addOptions(boost::program_options::positional_options_descri
("help,h", "Print usage and exit")
("syslogident,i", po::value<std::string>(&scriptname)->default_value(scriptname), "Log to syslog with ident <arg>")
("platform,p", po::value<std::string>(&platform), "Platform")
- ("queryparam,q", po::value<QueryParams>(&queryParams), "Platform")
+ ("queryparam,q", po::value<QueryParams>(&queryParams), "Query parameter")
+ ("uriparam,u", po::value<UriParams>(&uriParams), "URL paramater")
("file,f", po::value<ToDoList>(&todolist), "File to process")
;
poptions.add("file", -1);
@@ -61,15 +62,20 @@ ConsoleEnvironment::postinit(const boost::program_options::options_description &
}
Glib::ustring
-ConsoleEnvironment::getParamUri(unsigned int) const
+ConsoleEnvironment::getParamUri(unsigned int idx) const
{
- throw NotSupported(__PRETTY_FUNCTION__);
+ if (idx < uriParams.size()) {
+ return uriParams[idx];
+ }
+ throw UriElementOutOfRange(idx);
}
Glib::ustring
ConsoleEnvironment::getParamQuery(const std::string & p) const
{
- QueryParams::const_iterator i = queryParams.find(p);
+ QueryParams::const_iterator i = std::find_if(queryParams.begin(), queryParams.end(),
+ boost::bind(&boost::algorithm::equals<std::string, std::string>, p,
+ boost::bind(&ConsoleEnvironment::QueryParams::value_type::first, _1)));
if (i != queryParams.end()) {
return i->second;
}
diff --git a/project2/console/consoleEnvironment.h b/project2/console/consoleEnvironment.h
index 82fe11f..c72eed5 100644
--- a/project2/console/consoleEnvironment.h
+++ b/project2/console/consoleEnvironment.h
@@ -9,7 +9,8 @@
class ConsoleEnvironment : public Environment {
public:
typedef std::vector<boost::filesystem::path> ToDoList;
- typedef std::map<std::string, const Glib::ustring> QueryParams;
+ typedef std::vector<std::string> UriParams;
+ typedef std::vector<std::pair<std::string, std::string> > QueryParams;
ConsoleEnvironment(int argc, char ** argv);
virtual ~ConsoleEnvironment();
@@ -28,6 +29,7 @@ class ConsoleEnvironment : public Environment {
std::string scriptname;
std::string platform;
QueryParams queryParams;
+ UriParams uriParams;
ToDoList todolist;
};
diff --git a/project2/environment.cpp b/project2/environment.cpp
index 46ec6cf..d9e2687 100644
--- a/project2/environment.cpp
+++ b/project2/environment.cpp
@@ -39,13 +39,7 @@ Environment::init()
// Allow anything in release, but valid the config file in debug
// Some options only work in debug and you wouldn't want extra
// config entries to break an install
- po::store(po::parse_config_file(f, all,
-#if NDEBUG
- true
-#else
- false
-#endif
- ), settings);
+ po::store(po::parse_config_file(f, all, true), settings);
}
po::notify(settings);
diff --git a/project2/fileStrmVarWriter.cpp b/project2/fileStrmVarWriter.cpp
index 8b5b2ec..f2c8d7f 100644
--- a/project2/fileStrmVarWriter.cpp
+++ b/project2/fileStrmVarWriter.cpp
@@ -15,6 +15,9 @@ FileStreamVariableWriter::~FileStreamVariableWriter()
{
}
+void FileStreamVariableWriter::operator()(const Null &) const {
+ fprintf(out, "<null>");
+}
void FileStreamVariableWriter::operator()(const long long int & i) const {
fprintf(out, "%lld", i);
}
diff --git a/project2/fileStrmVarWriter.h b/project2/fileStrmVarWriter.h
index ecd65b6..6b0a258 100644
--- a/project2/fileStrmVarWriter.h
+++ b/project2/fileStrmVarWriter.h
@@ -8,6 +8,7 @@ class FileStreamVariableWriter : public boost::static_visitor<> {
FileStreamVariableWriter(FILE *, bool quoting);
~FileStreamVariableWriter();
+ void operator()(const Null &) const;
void operator()(const long long int & i) const;
void operator()(const long int & i) const;
void operator()(const int & i) const;
diff --git a/project2/rdbmsDataSource.cpp b/project2/rdbmsDataSource.cpp
index d7d77d3..8a095c7 100644
--- a/project2/rdbmsDataSource.cpp
+++ b/project2/rdbmsDataSource.cpp
@@ -129,6 +129,7 @@ RdbmsDataSource::commit()
DBHosts::const_iterator m = dbhosts.find(masterDsn);
if (m != dbhosts.end() && m->second->connection->inTx()) {
m->second->connection->commitTx();
+ m->second->connection->finish();
}
}
@@ -138,6 +139,7 @@ RdbmsDataSource::rollback()
DBHosts::const_iterator m = dbhosts.find(masterDsn);
if (m != dbhosts.end() && m->second->connection->inTx()) {
m->second->connection->rollbackTx();
+ m->second->connection->finish();
}
changedDSNs.erase(name);
}
diff --git a/project2/sqlRows.cpp b/project2/sqlRows.cpp
index bb94034..d33a09f 100644
--- a/project2/sqlRows.cpp
+++ b/project2/sqlRows.cpp
@@ -45,7 +45,9 @@ SqlRows::setFilter(const Glib::ustring & name)
class HandleAsVariableType : public DB::HandleField {
public:
- void null() { }
+ void null() {
+ variable = Null();
+ }
void string(const char * c, size_t l) {
variable = boost::shared_ptr<Glib::ustring>(new Glib::ustring(c, c + l));
}
diff --git a/project2/sqlVariableBinder.cpp b/project2/sqlVariableBinder.cpp
index 22cf34a..02528d3 100644
--- a/project2/sqlVariableBinder.cpp
+++ b/project2/sqlVariableBinder.cpp
@@ -1,5 +1,6 @@
#include "sqlVariableBinder.h"
#include "command.h"
+#include "variables.h"
#include <boost/date_time/posix_time/conversion.hpp>
SqlVariableBinder::SqlVariableBinder(DB::Command * c, unsigned int i) :
@@ -8,6 +9,11 @@ SqlVariableBinder::SqlVariableBinder(DB::Command * c, unsigned int i) :
{
}
void
+SqlVariableBinder::operator()(const Null &) const
+{
+ cmd->bindNull(idx);
+}
+void
SqlVariableBinder::operator()(const Glib::ustring & i) const
{
cmd->bindParamS(idx, i);
@@ -16,7 +22,7 @@ void
SqlVariableBinder::operator()(const boost::shared_ptr<const Glib::ustring> & i) const
{
if (!i) return cmd->bindNull(idx);
- (*this)(*i);
+ cmd->bindParamS(idx, *i);
}
void
SqlVariableBinder::operator()(const long long unsigned int & i) const
diff --git a/project2/sqlVariableBinder.h b/project2/sqlVariableBinder.h
index 2839e34..42a4567 100644
--- a/project2/sqlVariableBinder.h
+++ b/project2/sqlVariableBinder.h
@@ -9,9 +9,11 @@
namespace DB {
class Command;
}
+class Null;
class SqlVariableBinder : public boost::static_visitor<> {
public:
SqlVariableBinder(DB::Command * c, unsigned int i);
+ void operator()(const Null & i) const;
void operator()(const Glib::ustring & i) const;
void operator()(const boost::shared_ptr<const Glib::ustring> & i) const;
void operator()(const long long unsigned int & i) const;
diff --git a/project2/variableConvert.cpp b/project2/variableConvert.cpp
index a084639..1ac2253 100644
--- a/project2/variableConvert.cpp
+++ b/project2/variableConvert.cpp
@@ -25,6 +25,12 @@ set(const VariableType * var, const T * t)
return set(var, t, deleter<T>);
}
+class NullVariable : std::runtime_error {
+ public:
+ NullVariable() : std::runtime_error("Variable has null value where one is required") {
+ }
+};
+
// Convert to Glib::ustring
class ConvertVisitorGlibUstring : public boost::static_visitor<const Glib::ustring &> {
public:
@@ -42,6 +48,9 @@ class ConvertVisitorGlibUstring : public boost::static_visitor<const Glib::ustri
const Glib::ustring & operator()(const boost::shared_ptr<const boost::posix_time::ptime> & r) const {
return *set(var, new Glib::ustring(boost::posix_time::to_iso_extended_string(*r)));
}
+ const Glib::ustring & operator()(const Null &) const {
+ throw NullVariable();
+ }
template <typename T>
const Glib::ustring & operator()(const T & r) const {
return *set(var, new Glib::ustring(boost::lexical_cast<Glib::ustring>(r)));
@@ -66,6 +75,9 @@ class ConvertVisitorStdString : public boost::static_visitor<const std::string &
const std::string & operator()(const boost::shared_ptr<const boost::posix_time::ptime> & r) const {
return *set(var, new std::string(boost::posix_time::to_iso_extended_string(*r)));
}
+ const std::string & operator()(const Null &) const {
+ throw NullVariable();
+ }
template <typename T>
const std::string & operator()(const T & r) const {
return *set(var, new std::string(boost::lexical_cast<std::string>(r)));
@@ -90,6 +102,9 @@ class ConvertVisitorCharStar : public boost::static_visitor<const char *> {
const char * operator()(const boost::shared_ptr<const boost::posix_time::ptime> & r) const {
return set(var, new std::string(boost::posix_time::to_iso_extended_string(*r)))->c_str();
}
+ const char * operator()(const Null &) const {
+ return set<char>(var, NULL, NULL);
+ }
template <typename T>
const char * operator()(const T & r) const {
return set(var, new std::string(boost::lexical_cast<std::string>(r)))->c_str();
@@ -116,6 +131,9 @@ class ConvertVisitorUCharStar : public boost::static_visitor<const unsigned char
return reinterpret_cast<const unsigned char *>(
set(var, new std::string(boost::posix_time::to_iso_extended_string(*r)))->c_str());
}
+ const unsigned char * operator()(const Null &) const {
+ return set<unsigned char>(var, NULL, NULL);
+ }
template <typename T>
const unsigned char * operator()(const T & r) const {
return set(var, new std::basic_string<unsigned char>(boost::lexical_cast<std::basic_string<unsigned char> >(r)))->c_str();
diff --git a/project2/variables.h b/project2/variables.h
index 7303e5a..ecb8268 100644
--- a/project2/variables.h
+++ b/project2/variables.h
@@ -13,7 +13,9 @@
#include <boost/shared_ptr.hpp>
class RowUser;
+class Null { };
typedef boost::variant<
+ Null,
// Strings
Glib::ustring,
boost::shared_ptr<const Glib::ustring>,