diff --git a/libs/libmysqlxx/include/mysqlxx/Connection.h b/libs/libmysqlxx/include/mysqlxx/Connection.h index c932f5e8274..0c91c94433f 100644 --- a/libs/libmysqlxx/include/mysqlxx/Connection.h +++ b/libs/libmysqlxx/include/mysqlxx/Connection.h @@ -3,6 +3,8 @@ #include +#include + #include @@ -21,7 +23,19 @@ public: const char* password = 0, unsigned int port = 0); - Connection(const std::string & config_name); + Connection(const std::string & config_name) + { + is_connected = false; + Poco::Util::LayeredConfiguration & cfg = Poco::Util::Application::instance().config(); + + std::string db = cfg.getString(config_name + ".db"); + std::string server = cfg.getString(config_name + ".host"); + std::string user = cfg.getString(config_name + ".user"); + std::string password = cfg.getString(config_name + ".password"); + unsigned port = cfg.getInt(config_name + ".port"); + + connect(db.c_str(), server.c_str(), user.c_str(), password.c_str(), port); + } virtual ~Connection(); diff --git a/libs/libmysqlxx/include/mysqlxx/Date.h b/libs/libmysqlxx/include/mysqlxx/Date.h new file mode 100644 index 00000000000..e5567db08a5 --- /dev/null +++ b/libs/libmysqlxx/include/mysqlxx/Date.h @@ -0,0 +1,94 @@ +#ifndef MYSQLXX_DATE_H +#define MYSQLXX_DATE_H + +#include +#include + +#include + + +namespace mysqlxx +{ + +class Date +{ +private: + unsigned char m_day; + unsigned char m_month; + unsigned short m_year; + +public: + Date(time_t time) + { + Yandex::DateLUTSingleton & date_lut = Yandex::DateLUTSingleton::instance(); + const Yandex::DateLUT::Values & values = date_lut.getValues(time); + + m_day = values.day_of_month; + m_month = values.month; + m_year = values.year; + } + + /// Для совместимости + Date(unsigned short year_, unsigned char month_, unsigned char day_) + : m_day(day_), m_month(month_), m_year(year_) + { + } + + /// Для совместимости + Date(const std::string & s) + { + if (s.size() < 10) + throw Exception("Cannot parse Date: " + s); + + m_year = s[0] * 1000 + s[1] * 100 + s[2] * 10 + s[3]; + m_month = s[5] * 10 + s[6]; + m_day = s[8] * 10 + s[9]; + } + + /// Для совместимости + Date() : m_day(1), m_month(1), m_year(2000) + { + } + + /// Для совместимости + operator time_t() const + { + return Yandex::DateLUTSingleton::instance().makeDate(m_year, m_month, m_day); + } + + unsigned char day() const { return m_day; } + unsigned char month() const { return m_month; } + unsigned short year() const { return m_year; } + + void day(unsigned char x) { m_day = x; } + void month(unsigned char x) { m_month = x; } + void year(unsigned short x) { m_year = x; } + + bool operator< (const Date & other) const + { + return m_year < other.m_year + || (m_year == other.m_year && m_month < other.m_month) + || (m_year == other.m_year && m_month == other.m_month && m_day < other.m_day); + } + + bool operator== (const Date & other) const + { + return m_year == other.m_year && m_month == other.m_month && m_day == other.m_day; + } + + bool operator!= (const Date & other) const + { + return !(*this == other); + } +}; + +inline std::ostream & operator<< (std::ostream & ostr, const Date & date) +{ + return ostr << date.year() + << '-' << (date.month() < 10 ? "0" : "") << date.month() + << '-' << (date.day() < 10 ? "0" : "") << date.day(); +} + +} + +#endif diff --git a/libs/libmysqlxx/include/mysqlxx/Null.h b/libs/libmysqlxx/include/mysqlxx/Null.h new file mode 100644 index 00000000000..1cd9d51adeb --- /dev/null +++ b/libs/libmysqlxx/include/mysqlxx/Null.h @@ -0,0 +1,81 @@ +#ifndef MYSQLXX_NULL_H +#define MYSQLXX_NULL_H + +#include + + +namespace mysqlxx +{ + + +namespace detail +{ + struct NullTypeHelper + { + int x; + }; +} + +typedef int detail::NullTypeHelper::* NullType; + +const NullType null = 0; + + +template +class Null +{ +public: + T data; + bool is_null; + + Null() : is_null(true) {} + Null(NullType data) : is_null(true) {} + Null(const T & data_) : data(data_), is_null(false) {} + + operator T & () + { + if (is_null) + throw Exception("Value is NULL"); + return data; + } + + operator const T & () const + { + if (is_null) + throw Exception("Value is NULL"); + return data; + } + + Null & operator= (const T & data_) { is_null = false; data = data_; return *this; } + Null & operator= (const Null & other) { is_null = other.is_null; data = other.data; return *this; } + Null & operator= (const NullType other) { is_null = true; data = T(); return *this; } + + bool isNull() const { return is_null; } + + bool operator< (const Null & other) const + { + return is_null < other.is_null + || (is_null == other.is_null && data < other.data); + } + + bool operator< (const NullType other) const { return false; } + + bool operator== (const Null & other) const + { + return is_null == other.is_null && data == other.data; + } + + bool operator== (const NullType other) const { return is_null; } + + bool operator!= (const Null & other) const + { + return !(*this == other); + } + + bool operator!= (const NullType other) const { return !is_null; } +}; + + +} + +#endif diff --git a/libs/libmysqlxx/include/mysqlxx/Types.h b/libs/libmysqlxx/include/mysqlxx/Types.h index eb2a98018a2..5071591d5e2 100644 --- a/libs/libmysqlxx/include/mysqlxx/Types.h +++ b/libs/libmysqlxx/include/mysqlxx/Types.h @@ -3,9 +3,6 @@ #include #include -#include - -#include namespace mysqlxx @@ -25,146 +22,6 @@ typedef time_t sql_timestamp; typedef time_t sql_date; typedef std::string sql_char; -class Date -{ -private: - unsigned char m_day; - unsigned char m_month; - unsigned short m_year; - -public: - Date(time_t time) - { - Yandex::DateLUTSingleton & date_lut = Yandex::DateLUTSingleton::instance(); - const Yandex::DateLUT::Values & values = date_lut.getValues(time); - - m_day = values.day_of_month; - m_month = values.month; - m_year = values.year; - } - - /// Для совместимости - Date(unsigned short year_, unsigned char month_, unsigned char day_) - : m_day(day_), m_month(month_), m_year(year_) - { - } - - /// Для совместимости - Date(const std::string & s) - { - if (s.size() < 10) - throw Exception("Cannot parse Date: " + s); - - m_year = s[0] * 1000 + s[1] * 100 + s[2] * 10 + s[3]; - m_month = s[5] * 10 + s[6]; - m_day = s[8] * 10 + s[9]; - } - - /// Для совместимости - Date() : m_day(1), m_month(1), m_year(2000) - { - } - - /// Для совместимости - operator time_t() const - { - return Yandex::DateLUTSingleton::instance().makeDate(m_year, m_month, m_day); - } - - unsigned char day() const { return m_day; } - unsigned char month() const { return m_month; } - unsigned short year() const { return m_year; } - - void day(unsigned char x) { m_day = x; } - void month(unsigned char x) { m_month = x; } - void year(unsigned short x) { m_year = x; } - - bool operator< (const Date & other) const - { - return m_year < other.m_year - || (m_year == other.m_year && m_month < other.m_month) - || (m_year == other.m_year && m_month == other.m_month && m_day < other.m_day); - } - - bool operator== (const Date & other) const - { - return m_year == other.m_year && m_month == other.m_month && m_day == other.m_day; - } - - bool operator!= (const Date & other) const - { - return !(*this == other); - } -}; - -inline std::ostream & operator<< (std::ostream & ostr, const Date & date) -{ - return ostr << date.year() - << '-' << (date.month() < 10 ? "0" : "") << date.month() - << '-' << (date.day() < 10 ? "0" : "") << date.day(); -} - - -struct NullType -{ -}; - -extern NullType null; - - -template -class Null -{ -public: - T data; - bool is_null; - - Null() : is_null(true) {} - Null(NullType data) : is_null(true) {} - Null(const T & data_) : data(data_), is_null(false) {} - - operator T & () - { - if (is_null) - throw Exception("Value is NULL"); - return data; - } - - operator const T & () const - { - if (is_null) - throw Exception("Value is NULL"); - return data; - } - - Null & operator= (const T & data_) { is_null = false; data = data_; return *this; } - - bool isNull() const { return is_null; } - - bool operator< (const Null & other) const - { - return is_null < other.is_null - || (is_null == other.is_null && data < other.data); - } - - bool operator< (const NullType other) const { return false; } - - bool operator== (const Null & other) const - { - return is_null == other.is_null && data == other.data; - } - - bool operator== (const NullType other) const { return is_null; } - - bool operator!= (const Null & other) const - { - return !(*this == other); - } - - bool operator!= (const NullType other) const { return !is_null; } -}; - - } #endif diff --git a/libs/libmysqlxx/include/mysqlxx/mysqlxx.h b/libs/libmysqlxx/include/mysqlxx/mysqlxx.h index 72c0d903e12..528115b726c 100644 --- a/libs/libmysqlxx/include/mysqlxx/mysqlxx.h +++ b/libs/libmysqlxx/include/mysqlxx/mysqlxx.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include /** mysqlxx - чрезвычайно простая библиотека для замены библиотеки mysql++. * diff --git a/libs/libmysqlxx/src/Connection.cpp b/libs/libmysqlxx/src/Connection.cpp index d7529139820..625f9cc7c58 100644 --- a/libs/libmysqlxx/src/Connection.cpp +++ b/libs/libmysqlxx/src/Connection.cpp @@ -1,5 +1,3 @@ -#include - #include #include @@ -23,20 +21,6 @@ Connection::Connection( connect(db, server, user, password, port); } -Connection::Connection(const std::string & config_name) -{ - is_connected = false; - Poco::Util::LayeredConfiguration & cfg = Poco::Util::Application::instance().config(); - - std::string db = cfg.getString(config_name + ".db"); - std::string server = cfg.getString(config_name + ".host"); - std::string user = cfg.getString(config_name + ".user"); - std::string password = cfg.getString(config_name + ".password"); - unsigned port = cfg.getInt(config_name + ".port"); - - connect(db.c_str(), server.c_str(), user.c_str(), password.c_str(), port); -} - Connection::~Connection() { disconnect(); diff --git a/libs/libmysqlxx/src/Exception.cpp b/libs/libmysqlxx/src/Exception.cpp deleted file mode 100644 index 6a396e082fd..00000000000 --- a/libs/libmysqlxx/src/Exception.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -#include - - -namespace mysqlxx -{ - -} diff --git a/libs/libmysqlxx/src/Row.cpp b/libs/libmysqlxx/src/Row.cpp deleted file mode 100644 index e6e4be9c83b..00000000000 --- a/libs/libmysqlxx/src/Row.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -namespace mysqlxx -{ - -} diff --git a/libs/libmysqlxx/src/String.cpp b/libs/libmysqlxx/src/String.cpp deleted file mode 100644 index 70bb268470b..00000000000 --- a/libs/libmysqlxx/src/String.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include - - -namespace mysqlxx -{ - -} diff --git a/libs/libmysqlxx/src/Types.cpp b/libs/libmysqlxx/src/Types.cpp deleted file mode 100644 index 55242119cf4..00000000000 --- a/libs/libmysqlxx/src/Types.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include - -namespace mysqlxx -{ - -NullType null = NullType(); - -}