diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-10-13 00:42:13 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-10-13 00:42:13 +0100 |
commit | 08edf88437e4ca126773ab0b0e2a2f97f78e9656 (patch) | |
tree | 8b519615f9b83cf6c640d47dbeba6ff5619772e3 | |
parent | Throw specific exception on unsupport model type and add covering test (diff) | |
download | slicer-08edf88437e4ca126773ab0b0e2a2f97f78e9656.tar.bz2 slicer-08edf88437e4ca126773ab0b0e2a2f97f78e9656.tar.xz slicer-08edf88437e4ca126773ab0b0e2a2f97f78e9656.zip |
Split SqlSource into its own files
-rw-r--r-- | slicer/db/sqlSelectDeserializer.cpp | 80 | ||||
-rw-r--r-- | slicer/db/sqlSource.cpp | 84 | ||||
-rw-r--r-- | slicer/db/sqlSource.h | 35 |
3 files changed, 120 insertions, 79 deletions
diff --git a/slicer/db/sqlSelectDeserializer.cpp b/slicer/db/sqlSelectDeserializer.cpp index 96c58c1..d4198b5 100644 --- a/slicer/db/sqlSelectDeserializer.cpp +++ b/slicer/db/sqlSelectDeserializer.cpp @@ -1,6 +1,6 @@ #include "sqlSelectDeserializer.h" +#include "sqlSource.h" #include <boost/algorithm/string/predicate.hpp> -#include <boost/numeric/conversion/cast.hpp> namespace Slicer { NoRowsReturned::NoRowsReturned() : std::runtime_error("No rows returned") { } @@ -9,84 +9,6 @@ namespace Slicer { UnsupportedModelType::UnsupportedModelType() : std::invalid_argument("Unspported model type") { } - class SqlSource : public Slicer::ValueSource, - public Slicer::TValueSource<boost::posix_time::time_duration>, - public Slicer::TValueSource<boost::posix_time::ptime> - { - public: - SqlSource(const DB::Column & c) : - column(c) - { - } - - bool isNull() const - { - return column.isNull(); - } - - void set(boost::posix_time::ptime & b) const override - { - column >> b; - } - - void set(boost::posix_time::time_duration & b) const override - { - column >> b; - } - - void set(bool & b) const override - { - column >> b; - } - - void set(Ice::Byte & b) const override - { - int64_t cb; - column >> cb; - b = boost::numeric_cast<Ice::Byte>(cb); - } - - void set(Ice::Short & b) const override - { - int64_t cb; - column >> cb; - b = boost::numeric_cast<Ice::Byte>(cb); - } - - void set(Ice::Int & b) const override - { - int64_t cb; - column >> cb; - b = boost::numeric_cast<Ice::Int>(cb); - } - - void set(Ice::Long & b) const override - { - column >> b; - } - - void set(Ice::Float & b) const override - { - double cb; - column >> cb; - b = boost::numeric_cast<Ice::Float>(cb); - } - - void set(Ice::Double & b) const override - { - column >> b; - } - - void set(std::string & b) const override - { - column >> b; - } - - private: - const DB::Column & column; - }; - typedef IceUtil::Handle<SqlSource> SqlSourcePtr; - SqlSelectDeserializer::SqlSelectDeserializer(DB::SelectCommand & c, IceUtil::Optional<std::string> tc) : cmd(c), typeIdColName(tc) diff --git a/slicer/db/sqlSource.cpp b/slicer/db/sqlSource.cpp new file mode 100644 index 0000000..0a3b684 --- /dev/null +++ b/slicer/db/sqlSource.cpp @@ -0,0 +1,84 @@ +#include "sqlSource.h" +#include <boost/numeric/conversion/cast.hpp> + +namespace Slicer { + SqlSource::SqlSource(const DB::Column & c) : + column(c) + { + } + + bool + SqlSource::isNull() const + { + return column.isNull(); + } + + void + SqlSource::set(boost::posix_time::ptime & b) const + { + column >> b; + } + + void + SqlSource::set(boost::posix_time::time_duration & b) const + { + column >> b; + } + + void + SqlSource::set(bool & b) const + { + column >> b; + } + + void + SqlSource::set(Ice::Byte & b) const + { + int64_t cb; + column >> cb; + b = boost::numeric_cast<Ice::Byte>(cb); + } + + void + SqlSource::set(Ice::Short & b) const + { + int64_t cb; + column >> cb; + b = boost::numeric_cast<Ice::Byte>(cb); + } + + void + SqlSource::set(Ice::Int & b) const + { + int64_t cb; + column >> cb; + b = boost::numeric_cast<Ice::Int>(cb); + } + + void + SqlSource::set(Ice::Long & b) const + { + column >> b; + } + + void + SqlSource::set(Ice::Float & b) const + { + double cb; + column >> cb; + b = boost::numeric_cast<Ice::Float>(cb); + } + + void + SqlSource::set(Ice::Double & b) const + { + column >> b; + } + + void + SqlSource::set(std::string & b) const + { + column >> b; + } +} + diff --git a/slicer/db/sqlSource.h b/slicer/db/sqlSource.h new file mode 100644 index 0000000..bf728dc --- /dev/null +++ b/slicer/db/sqlSource.h @@ -0,0 +1,35 @@ +#ifndef SLICER_DB_SQLSOURCE_H +#define SLICER_DB_SQLSOURCE_H + +#include <slicer/modelParts.h> +#include <column.h> +#include <boost/date_time/posix_time/ptime.hpp> + +namespace Slicer { + class SqlSource : public Slicer::ValueSource, + public Slicer::TValueSource<boost::posix_time::time_duration>, + public Slicer::TValueSource<boost::posix_time::ptime> + { + public: + SqlSource(const DB::Column & c); + + bool isNull() const; + void set(boost::posix_time::ptime & b) const override; + void set(boost::posix_time::time_duration & b) const override; + void set(bool & b) const override; + void set(Ice::Byte & b) const override; + void set(Ice::Short & b) const override; + void set(Ice::Int & b) const override; + void set(Ice::Long & b) const override; + void set(Ice::Float & b) const override; + void set(Ice::Double & b) const override; + void set(std::string & b) const override; + + private: + const DB::Column & column; + }; + typedef IceUtil::Handle<SqlSource> SqlSourcePtr; +} + +#endif + |