diff --git a/dbms/include/DB/Core/toField.h b/dbms/include/DB/Core/toField.h index 5e776ca035f..2e4390ccd04 100644 --- a/dbms/include/DB/Core/toField.h +++ b/dbms/include/DB/Core/toField.h @@ -16,12 +16,12 @@ inline Field toField(const T & x) return Field(typename NearestFieldType::Type(x)); } -inline Field toField(const mysqlxx::Date & x) +inline Field toField(const LocalDate & x) { return toField(static_cast(x.getDayNum())); } -inline Field toField(const mysqlxx::DateTime & x) +inline Field toField(const LocalDateTime & x) { return toField(static_cast(static_cast(x))); } diff --git a/dbms/include/DB/Dictionaries/MySQLDictionarySource.h b/dbms/include/DB/Dictionaries/MySQLDictionarySource.h index 8cffc3de323..9666ed23d14 100644 --- a/dbms/include/DB/Dictionaries/MySQLDictionarySource.h +++ b/dbms/include/DB/Dictionaries/MySQLDictionarySource.h @@ -113,9 +113,9 @@ private: } - mysqlxx::DateTime getLastModification() const + LocalDateTime getLastModification() const { - mysqlxx::DateTime update_time{std::time(nullptr)}; + LocalDateTime update_time{std::time(nullptr)}; if (dont_check_update_time) return update_time; @@ -417,7 +417,7 @@ private: Block sample_block; mutable mysqlxx::PoolWithFailover pool; const std::string load_all_query; - mysqlxx::DateTime last_modification; + LocalDateTime last_modification; }; } diff --git a/dbms/include/DB/IO/ReadHelpers.h b/dbms/include/DB/IO/ReadHelpers.h index 80ba9ad9167..fecd58b876d 100644 --- a/dbms/include/DB/IO/ReadHelpers.h +++ b/dbms/include/DB/IO/ReadHelpers.h @@ -9,8 +9,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -429,7 +429,7 @@ inline void readDateText(DayNum_t & date, ReadBuffer & buf) date = DateLUT::instance().makeDayNum(year, month, day); } -inline void readDateText(mysqlxx::Date & date, ReadBuffer & buf) +inline void readDateText(LocalDate & date, ReadBuffer & buf) { char s[10]; size_t size = buf.read(s, 10); @@ -491,7 +491,7 @@ inline void readDateTimeText(time_t & datetime, ReadBuffer & buf) readDateTimeTextFallback(datetime, buf); } -inline void readDateTimeText(mysqlxx::DateTime & datetime, ReadBuffer & buf) +inline void readDateTimeText(LocalDateTime & datetime, ReadBuffer & buf) { char s[19]; size_t size = buf.read(s, 19); @@ -527,8 +527,8 @@ inline void readBinary(bool & x, ReadBuffer & buf) { readPODBinary(x, buf); } inline void readBinary(uint128 & x, ReadBuffer & buf) { readPODBinary(x, buf); } inline void readBinary(VisitID_t & x, ReadBuffer & buf) { readPODBinary(x, buf); } -inline void readBinary(mysqlxx::Date & x, ReadBuffer & buf) { readPODBinary(x, buf); } -inline void readBinary(mysqlxx::DateTime & x, ReadBuffer & buf) { readPODBinary(x, buf); } +inline void readBinary(LocalDate & x, ReadBuffer & buf) { readPODBinary(x, buf); } +inline void readBinary(LocalDateTime & x, ReadBuffer & buf) { readPODBinary(x, buf); } /// Общие методы для чтения значения в текстовом виде из tab-separated формата. @@ -546,8 +546,8 @@ inline void readText(String & x, ReadBuffer & buf) { readEscapedString(x, buf); inline void readText(bool & x, ReadBuffer & buf) { readBoolText(x, buf); } inline void readText(VisitID_t & x, ReadBuffer & buf) { readIntText(x, buf); } -inline void readText(mysqlxx::Date & x, ReadBuffer & buf) { readDateText(x, buf); } -inline void readText(mysqlxx::DateTime & x, ReadBuffer & buf) { readDateTimeText(x, buf); } +inline void readText(LocalDate & x, ReadBuffer & buf) { readDateText(x, buf); } +inline void readText(LocalDateTime & x, ReadBuffer & buf) { readDateTimeText(x, buf); } /// Общие методы для чтения значения в текстовом виде, при необходимости, в кавычках. @@ -566,14 +566,14 @@ inline void readQuoted(bool & x, ReadBuffer & buf) { readBoolText(x, buf); } inline void readQuoted(VisitID_t & x, ReadBuffer & buf) { readIntText(x, buf); } -inline void readQuoted(mysqlxx::Date & x, ReadBuffer & buf) +inline void readQuoted(LocalDate & x, ReadBuffer & buf) { assertString("'", buf); readDateText(x, buf); assertString("'", buf); } -inline void readQuoted(mysqlxx::DateTime & x, ReadBuffer & buf) +inline void readQuoted(LocalDateTime & x, ReadBuffer & buf) { assertString("'", buf); readDateTimeText(x, buf); @@ -597,14 +597,14 @@ inline void readDoubleQuoted(bool & x, ReadBuffer & buf) { readBoolText(x, buf inline void readDoubleQuoted(VisitID_t & x, ReadBuffer & buf) { readIntText(x, buf); } -inline void readDoubleQuoted(mysqlxx::Date & x, ReadBuffer & buf) +inline void readDoubleQuoted(LocalDate & x, ReadBuffer & buf) { assertString("\"", buf); readDateText(x, buf); assertString("\"", buf); } -inline void readDoubleQuoted(mysqlxx::DateTime & x, ReadBuffer & buf) +inline void readDoubleQuoted(LocalDateTime & x, ReadBuffer & buf) { assertString("\"", buf); readDateTimeText(x, buf); diff --git a/dbms/include/DB/IO/WriteHelpers.h b/dbms/include/DB/IO/WriteHelpers.h index c9e3dc89c58..3ee5dca79f2 100644 --- a/dbms/include/DB/IO/WriteHelpers.h +++ b/dbms/include/DB/IO/WriteHelpers.h @@ -393,7 +393,7 @@ inline void writeDateText(DayNum_t date, WriteBuffer & buf) buf.write(s, 10); } -inline void writeDateText(mysqlxx::Date date, WriteBuffer & buf) +inline void writeDateText(LocalDate date, WriteBuffer & buf) { char s[10] = {'0', '0', '0', '0', '-', '0', '0', '-', '0', '0'}; @@ -449,7 +449,7 @@ inline void writeDateTimeText(time_t datetime, WriteBuffer & buf) } template -inline void writeDateTimeText(mysqlxx::DateTime datetime, WriteBuffer & buf) +inline void writeDateTimeText(LocalDateTime datetime, WriteBuffer & buf) { char s[19] = {'0', '0', '0', '0', date_delimeter, '0', '0', date_delimeter, '0', '0', ' ', '0', '0', time_delimeter, '0', '0', time_delimeter, '0', '0'}; @@ -508,8 +508,8 @@ inline void writeBinary(const bool & x, WriteBuffer & buf) { writePODBinary(x, inline void writeBinary(const uint128 & x, WriteBuffer & buf) { writePODBinary(x, buf); } inline void writeBinary(const VisitID_t & x, WriteBuffer & buf) { writePODBinary(static_cast(x), buf); } -inline void writeBinary(const mysqlxx::Date & x, WriteBuffer & buf) { writePODBinary(x, buf); } -inline void writeBinary(const mysqlxx::DateTime & x, WriteBuffer & buf) { writePODBinary(x, buf); } +inline void writeBinary(const LocalDate & x, WriteBuffer & buf) { writePODBinary(x, buf); } +inline void writeBinary(const LocalDateTime & x, WriteBuffer & buf) { writePODBinary(x, buf); } /// Методы для вывода значения в текстовом виде для tab-separated формата. @@ -531,8 +531,8 @@ inline void writeText(const char * x, WriteBuffer & buf) { writeEscapedString( inline void writeText(const char * x, size_t size, WriteBuffer & buf) { writeEscapedString(x, size, buf); } inline void writeText(const VisitID_t & x, WriteBuffer & buf) { writeIntText(static_cast(x), buf); } -inline void writeText(const mysqlxx::Date & x, WriteBuffer & buf) { writeDateText(x, buf); } -inline void writeText(const mysqlxx::DateTime & x, WriteBuffer & buf) { writeDateTimeText(x, buf); } +inline void writeText(const LocalDate & x, WriteBuffer & buf) { writeDateText(x, buf); } +inline void writeText(const LocalDateTime & x, WriteBuffer & buf) { writeDateTimeText(x, buf); } template inline void writeText(const mysqlxx::Null & x, WriteBuffer & buf) @@ -563,14 +563,14 @@ inline void writeQuoted(const VisitID_t & x, WriteBuffer & buf) writeIntText(static_cast(x), buf); } -inline void writeQuoted(const mysqlxx::Date & x, WriteBuffer & buf) +inline void writeQuoted(const LocalDate & x, WriteBuffer & buf) { writeChar('\'', buf); writeDateText(x, buf); writeChar('\'', buf); } -inline void writeQuoted(const mysqlxx::DateTime & x, WriteBuffer & buf) +inline void writeQuoted(const LocalDateTime & x, WriteBuffer & buf) { writeChar('\'', buf); writeDateTimeText(x, buf); @@ -606,14 +606,14 @@ inline void writeDoubleQuoted(const VisitID_t & x, WriteBuffer & buf) writeIntText(static_cast(x), buf); } -inline void writeDoubleQuoted(const mysqlxx::Date & x, WriteBuffer & buf) +inline void writeDoubleQuoted(const LocalDate & x, WriteBuffer & buf) { writeChar('"', buf); writeDateText(x, buf); writeChar('"', buf); } -inline void writeDoubleQuoted(const mysqlxx::DateTime & x, WriteBuffer & buf) +inline void writeDoubleQuoted(const LocalDateTime & x, WriteBuffer & buf) { writeChar('"', buf); writeDateTimeText(x, buf); diff --git a/dbms/src/Client/Client.cpp b/dbms/src/Client/Client.cpp index 4b874e5e529..d0c25cbf5b6 100644 --- a/dbms/src/Client/Client.cpp +++ b/dbms/src/Client/Client.cpp @@ -263,7 +263,7 @@ private: if (current_time % 3 != 0) return false; - mysqlxx::Date now(current_time); + LocalDate now(current_time); return (now.month() == 12 && now.day() >= 20) || (now.month() == 1 && now.day() <= 5); } diff --git a/dbms/src/IO/tests/operators.cpp b/dbms/src/IO/tests/operators.cpp index 789454aae9c..f165c3ab95a 100644 --- a/dbms/src/IO/tests/operators.cpp +++ b/dbms/src/IO/tests/operators.cpp @@ -13,8 +13,8 @@ int main(int argc, char ** argv) << DB::quote << "Hello, world!" << '\n' << DB::double_quote << "Hello, world!" << '\n' << DB::binary << "Hello, world!" << '\n' - << mysqlxx::DateTime(time(0)) << '\n' - << mysqlxx::Date(time(0)) << '\n' + << LocalDateTime(time(0)) << '\n' + << LocalDate(time(0)) << '\n' << 1234567890123456789UL << '\n' << DB::flush; } diff --git a/dbms/src/Interpreters/Quota.cpp b/dbms/src/Interpreters/Quota.cpp index 464a1c8a290..3c8556a1e27 100644 --- a/dbms/src/Interpreters/Quota.cpp +++ b/dbms/src/Interpreters/Quota.cpp @@ -57,7 +57,7 @@ String QuotaForInterval::toString() const std::stringstream res; res << std::fixed << std::setprecision(3) - << "Interval: " << mysqlxx::DateTime(rounded_time) << " - " << mysqlxx::DateTime(rounded_time + duration) << ".\n" + << "Interval: " << LocalDateTime(rounded_time) << " - " << LocalDateTime(rounded_time + duration) << ".\n" << "Queries: " << used.queries << ".\n" << "Errors: " << used.errors << ".\n" << "Result rows: " << used.result_rows << ".\n" @@ -129,7 +129,7 @@ void QuotaForInterval::check(size_t max_amount, size_t used_amount, time_t curre message << " has been exceeded. " << resource_name << ": " << used_amount << ", max: " << max_amount << ". " - << "Interval will end at " << mysqlxx::DateTime(rounded_time + duration) << "."; + << "Interval will end at " << LocalDateTime(rounded_time + duration) << "."; throw Exception(message.str(), ErrorCodes::QUOTA_EXPIRED); } diff --git a/dbms/src/Server/OLAPQueryParser.cpp b/dbms/src/Server/OLAPQueryParser.cpp index bc3e1e0c6a4..1526232a163 100644 --- a/dbms/src/Server/OLAPQueryParser.cpp +++ b/dbms/src/Server/OLAPQueryParser.cpp @@ -209,7 +209,7 @@ QueryParseResult QueryParser::parse(std::istream & s) result.limit = DB::parse(limit_nodes->item(0)->innerText()); LOG_DEBUG(log, "CounterID: " << result.CounterID - << ", dates: " << mysqlxx::Date(result.date_first) << " - " << mysqlxx::Date(result.date_last)); + << ", dates: " << LocalDate(result.date_first) << " - " << LocalDate(result.date_last)); /// получаем список имён атрибутов Poco::AutoPtr attributes = result.query->getElementsByTagName("attribute"); diff --git a/dbms/src/Server/StatusFile.cpp b/dbms/src/Server/StatusFile.cpp index 7be5064e7ed..09edd563b73 100644 --- a/dbms/src/Server/StatusFile.cpp +++ b/dbms/src/Server/StatusFile.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include @@ -69,7 +69,7 @@ StatusFile::StatusFile(const std::string & path_) WriteBufferFromFileDescriptor out(fd, 1024); out << "PID: " << getpid() << "\n" - << "Started at: " << mysqlxx::DateTime(time(0)) << "\n" + << "Started at: " << LocalDateTime(time(0)) << "\n" << "Revision: " << Revision::get() << "\n"; } } diff --git a/dbms/src/Storages/MergeTree/ReplicatedMergeTreeLogEntry.cpp b/dbms/src/Storages/MergeTree/ReplicatedMergeTreeLogEntry.cpp index eb995b626de..91275d52ec4 100644 --- a/dbms/src/Storages/MergeTree/ReplicatedMergeTreeLogEntry.cpp +++ b/dbms/src/Storages/MergeTree/ReplicatedMergeTreeLogEntry.cpp @@ -12,7 +12,7 @@ namespace DB void ReplicatedMergeTreeLogEntry::writeText(WriteBuffer & out) const { out << "format version: 3\n" - << "create_time: " << mysqlxx::DateTime(create_time ? create_time : time(0)) << "\n" + << "create_time: " << LocalDateTime(create_time ? create_time : time(0)) << "\n" << "source replica: " << source_replica << '\n' << "block_id: " << escape << block_id << '\n'; @@ -68,7 +68,7 @@ void ReplicatedMergeTreeLogEntry::readText(ReadBuffer & in) if (format_version >= 2) { - mysqlxx::DateTime create_time_dt; + LocalDateTime create_time_dt; in >> "create_time: " >> create_time_dt >> "\n"; create_time = create_time_dt; } diff --git a/dbms/src/Storages/System/StorageSystemParts.cpp b/dbms/src/Storages/System/StorageSystemParts.cpp index b32d90a1f7e..04553ec3669 100644 --- a/dbms/src/Storages/System/StorageSystemParts.cpp +++ b/dbms/src/Storages/System/StorageSystemParts.cpp @@ -227,7 +227,7 @@ BlockInputStreams StorageSystemParts::read( table_column->insert(table); engine_column->insert(engine); - mysqlxx::Date partition_date {part->month}; + LocalDate partition_date {part->month}; String partition = toString(partition_date.year()) + (partition_date.month() < 10 ? "0" : "") + toString(partition_date.month()); partition_column->insert(partition); diff --git a/dbms/src/Storages/tests/part_name.cpp b/dbms/src/Storages/tests/part_name.cpp index 8786c672c80..280b803f4ca 100644 --- a/dbms/src/Storages/tests/part_name.cpp +++ b/dbms/src/Storages/tests/part_name.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include int main(int argc, char ** argv) @@ -13,7 +13,7 @@ int main(int argc, char ** argv) std::cerr << name << '\n'; time_t time = DateLUT::instance().YYYYMMDDToDate(DB::parse(name)); - std::cerr << mysqlxx::DateTime(time) << '\n'; + std::cerr << LocalDateTime(time) << '\n'; } return 0; diff --git a/libs/libmysqlxx/include/mysqlxx/Date.h b/libs/libcommon/include/common/LocalDate.h similarity index 74% rename from libs/libmysqlxx/include/mysqlxx/Date.h rename to libs/libcommon/include/common/LocalDate.h index b1fa5b6b362..69e78605bd7 100644 --- a/libs/libmysqlxx/include/mysqlxx/Date.h +++ b/libs/libcommon/include/common/LocalDate.h @@ -2,17 +2,14 @@ #include #include +#include +#include #include -#include - - -namespace mysqlxx -{ /** Хранит дату в broken-down виде. * Может быть инициализирован из даты в текстовом виде '2011-01-01' и из time_t. - * Может быть инициализирован из даты в текстовом виде '20110101...(юзаются первые 8 символов) + * Может быть инициализирован из даты в текстовом виде '20110101... (используются первые 8 символов) * Неявно преобразуется в time_t. * Сериализуется в ostream в текстовом виде. * Внимание: преобразование в unix timestamp и обратно производится в текущей тайм-зоне! @@ -20,7 +17,7 @@ namespace mysqlxx * * packed - для memcmp (из-за того, что m_year - 2 байта, little endian, работает корректно только до 2047 года) */ -class __attribute__ ((__packed__)) Date +class __attribute__ ((__packed__)) LocalDate { private: unsigned short m_year; @@ -40,14 +37,14 @@ private: void init(const char * s, size_t length) { if (length < 8) - throw Exception("Cannot parse Date: " + std::string(s, length)); + throw std::runtime_error("Cannot parse LocalDate: " + std::string(s, length)); m_year = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0'); if (s[4] == '-') { if (length < 10) - throw Exception("Cannot parse Date: " + std::string(s, length)); + throw std::runtime_error("Cannot parse LocalDate: " + std::string(s, length)); m_month = (s[5] - '0') * 10 + (s[6] - '0'); m_day = (s[8] - '0') * 10 + (s[9] - '0'); } @@ -59,12 +56,12 @@ private: } public: - explicit Date(time_t time) + explicit LocalDate(time_t time) { init(time); } - Date(DayNum_t day_num) + LocalDate(DayNum_t day_num) { const auto & values = DateLUT::instance().getValues(day_num); m_year = values.year; @@ -72,31 +69,31 @@ public: m_day = values.day_of_month; } - Date(unsigned short year_, unsigned char month_, unsigned char day_) + LocalDate(unsigned short year_, unsigned char month_, unsigned char day_) : m_year(year_), m_month(month_), m_day(day_) { } - explicit Date(const std::string & s) + explicit LocalDate(const std::string & s) { init(s.data(), s.size()); } - Date(const char * data, size_t length) + LocalDate(const char * data, size_t length) { init(data, length); } - Date() : m_year(0), m_month(0), m_day(0) + LocalDate() : m_year(0), m_month(0), m_day(0) { } - Date(const Date & x) + LocalDate(const LocalDate & x) { operator=(x); } - Date & operator= (const Date & x) + LocalDate & operator= (const LocalDate & x) { m_year = x.m_year; m_month = x.m_month; @@ -105,7 +102,7 @@ public: return *this; } - Date & operator= (time_t time) + LocalDate & operator= (time_t time) { init(time); return *this; @@ -134,36 +131,37 @@ public: void month(unsigned char x) { m_month = x; } void day(unsigned char x) { m_day = x; } - bool operator< (const Date & other) const + bool operator< (const LocalDate & other) const { return 0 > memcmp(this, &other, sizeof(*this)); } - bool operator> (const Date & other) const + bool operator> (const LocalDate & other) const { return 0 < memcmp(this, &other, sizeof(*this)); } - bool operator<= (const Date & other) const + bool operator<= (const LocalDate & other) const { return 0 >= memcmp(this, &other, sizeof(*this)); } - bool operator>= (const Date & other) const + bool operator>= (const LocalDate & other) const { return 0 <= memcmp(this, &other, sizeof(*this)); } - bool operator== (const Date & other) const + bool operator== (const LocalDate & other) const { return 0 == memcmp(this, &other, sizeof(*this)); } - bool operator!= (const Date & other) const + bool operator!= (const LocalDate & other) const { return !(*this == other); } + /// NOTE Неэффективно. std::string toString(char separator = '-') const { std::stringstream ss; @@ -177,19 +175,17 @@ public: } }; -inline std::ostream & operator<< (std::ostream & ostr, const Date & date) +inline std::ostream & operator<< (std::ostream & ostr, const LocalDate & date) { return ostr << date.year() << '-' << (date.month() / 10) << (date.month() % 10) << '-' << (date.day() / 10) << (date.day() % 10); } -} - namespace std { -inline string to_string(const mysqlxx::Date & date) +inline string to_string(const LocalDate & date) { return date.toString(); } diff --git a/libs/libmysqlxx/include/mysqlxx/DateTime.h b/libs/libcommon/include/common/LocalDateTime.h similarity index 75% rename from libs/libmysqlxx/include/mysqlxx/DateTime.h rename to libs/libcommon/include/common/LocalDateTime.h index 83b843a543f..841915b584c 100644 --- a/libs/libmysqlxx/include/mysqlxx/DateTime.h +++ b/libs/libcommon/include/common/LocalDateTime.h @@ -1,15 +1,12 @@ #pragma once #include -#include - -#include #include +#include +#include +#include -namespace mysqlxx -{ - /** Хранит дату и время в broken-down виде. * Может быть инициализирован из даты и времени в текстовом виде '2011-01-01 00:00:00' и из time_t. * Неявно преобразуется в time_t. @@ -19,7 +16,7 @@ namespace mysqlxx * * packed - для memcmp (из-за того, что m_year - 2 байта, little endian, работает корректно только до 2047 года) */ -class __attribute__ ((__packed__)) DateTime +class __attribute__ ((__packed__)) LocalDateTime { private: unsigned short m_year; @@ -57,7 +54,7 @@ private: void init(const char * s, size_t length) { if (length < 19) - throw Exception("Cannot parse DateTime: " + std::string(s, length)); + throw std::runtime_error("Cannot parse LocalDateTime: " + std::string(s, length)); m_year = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0'); m_month = (s[5] - '0') * 10 + (s[6] - '0'); @@ -69,40 +66,40 @@ private: } public: - explicit DateTime(time_t time) + explicit LocalDateTime(time_t time) { init(time); } - DateTime(unsigned short year_, unsigned char month_, unsigned char day_, + LocalDateTime(unsigned short year_, unsigned char month_, unsigned char day_, unsigned char hour_, unsigned char minute_, unsigned char second_) : m_year(year_), m_month(month_), m_day(day_), m_hour(hour_), m_minute(minute_), m_second(second_) { } - explicit DateTime(const std::string & s) + explicit LocalDateTime(const std::string & s) { if (s.size() < 19) - throw Exception("Cannot parse DateTime: " + s); + throw std::runtime_error("Cannot parse LocalDateTime: " + s); init(s.data(), s.size()); } - DateTime() : m_year(0), m_month(0), m_day(0), m_hour(0), m_minute(0), m_second(0) + LocalDateTime() : m_year(0), m_month(0), m_day(0), m_hour(0), m_minute(0), m_second(0) { } - DateTime(const char * data, size_t length) + LocalDateTime(const char * data, size_t length) { init(data, length); } - DateTime(const DateTime & x) + LocalDateTime(const LocalDateTime & x) { operator=(x); } - DateTime & operator= (const DateTime & x) + LocalDateTime & operator= (const LocalDateTime & x) { m_year = x.m_year; m_month = x.m_month; @@ -114,7 +111,7 @@ public: return *this; } - DateTime & operator= (time_t time) + LocalDateTime & operator= (time_t time) { init(time); return *this; @@ -141,42 +138,42 @@ public: void minute(unsigned char x) { m_minute = x; } void second(unsigned char x) { m_second = x; } - Date toDate() const { return Date(m_year, m_month, m_day); } + LocalDate toDate() const { return LocalDate(m_year, m_month, m_day); } - DateTime toStartOfDate() { return DateTime(m_year, m_month, m_day, 0, 0, 0); } + LocalDateTime toStartOfDate() { return LocalDateTime(m_year, m_month, m_day, 0, 0, 0); } - bool operator< (const DateTime & other) const + bool operator< (const LocalDateTime & other) const { return 0 > memcmp(this, &other, sizeof(*this)); } - bool operator> (const DateTime & other) const + bool operator> (const LocalDateTime & other) const { return 0 < memcmp(this, &other, sizeof(*this)); } - bool operator<= (const DateTime & other) const + bool operator<= (const LocalDateTime & other) const { return 0 >= memcmp(this, &other, sizeof(*this)); } - bool operator>= (const DateTime & other) const + bool operator>= (const LocalDateTime & other) const { return 0 <= memcmp(this, &other, sizeof(*this)); } - bool operator== (const DateTime & other) const + bool operator== (const LocalDateTime & other) const { return 0 == memcmp(this, &other, sizeof(*this)); } - bool operator!= (const DateTime & other) const + bool operator!= (const LocalDateTime & other) const { return !(*this == other); } }; -inline std::ostream & operator<< (std::ostream & ostr, const DateTime & datetime) +inline std::ostream & operator<< (std::ostream & ostr, const LocalDateTime & datetime) { ostr << std::setfill('0') << std::setw(4) << datetime.year(); @@ -189,12 +186,10 @@ inline std::ostream & operator<< (std::ostream & ostr, const DateTime & datetime return ostr; } -} - namespace std { -inline string to_string(const mysqlxx::DateTime & datetime) +inline string to_string(const LocalDateTime & datetime) { stringstream str; str << datetime; diff --git a/libs/libmysqlxx/include/mysqlxx/Connection.h b/libs/libmysqlxx/include/mysqlxx/Connection.h index 54363ad43d5..408e6052600 100644 --- a/libs/libmysqlxx/include/mysqlxx/Connection.h +++ b/libs/libmysqlxx/include/mysqlxx/Connection.h @@ -7,6 +7,7 @@ #include #include +#include #define MYSQLXX_DEFAULT_TIMEOUT 60 #define MYSQLXX_DEFAULT_RW_TIMEOUT 1800 diff --git a/libs/libmysqlxx/include/mysqlxx/Manip.h b/libs/libmysqlxx/include/mysqlxx/Manip.h index 07542cc82fb..c93d91e2d4b 100644 --- a/libs/libmysqlxx/include/mysqlxx/Manip.h +++ b/libs/libmysqlxx/include/mysqlxx/Manip.h @@ -54,8 +54,8 @@ struct EscapeManipResult std::ostream & operator<< (double value) { return ostr << value; } std::ostream & operator<< (long long value) { return ostr << value; } std::ostream & operator<< (unsigned long long value) { return ostr << value; } - std::ostream & operator<< (Date value) { return ostr << value; } - std::ostream & operator<< (DateTime value) { return ostr << value; } + std::ostream & operator<< (LocalDate value) { return ostr << value; } + std::ostream & operator<< (LocalDateTime value) { return ostr << value; } std::ostream & operator<< (const std::string & value) { @@ -102,7 +102,7 @@ struct EscapeManipResult { if (i != 0) ostr << '\t'; - + if (row[i].isNull()) { ostr << "\\N"; @@ -115,7 +115,7 @@ struct EscapeManipResult return ostr; } - + template std::ostream & operator<< (const Null & value) { @@ -123,7 +123,7 @@ struct EscapeManipResult ostr << "\\N"; else *this << value.data; - + return ostr ; } @@ -181,8 +181,8 @@ public: std::ostream & operator<< (double value) { return ostr << value; } std::ostream & operator<< (long long value) { return ostr << value; } std::ostream & operator<< (unsigned long long value) { return ostr << value; } - std::ostream & operator<< (Date value) { return ostr << '\'' << value << '\''; } - std::ostream & operator<< (DateTime value) { return ostr << '\'' << value << '\''; } + std::ostream & operator<< (LocalDate value) { return ostr << '\'' << value << '\''; } + std::ostream & operator<< (LocalDateTime value) { return ostr << '\'' << value << '\''; } std::ostream & operator<< (const std::string & value) { @@ -201,7 +201,7 @@ public: ostr.put('\''); return ostr; } - + template std::ostream & operator<< (const Null & value) { @@ -395,19 +395,19 @@ struct UnEscapeManipResult return istr; } - std::istream & operator>> (Date & value) + std::istream & operator>> (LocalDate & value) { std::string s; (*this) >> s; - value = Date(s); + value = LocalDate(s); return istr; } - std::istream & operator>> (DateTime & value) + std::istream & operator>> (LocalDateTime & value) { std::string s; (*this) >> s; - value = DateTime(s); + value = LocalDateTime(s); return istr; } @@ -499,5 +499,5 @@ inline UnQuoteManipResult operator>> (std::istream & istr, unquote_enum manip) return UnQuoteManipResult(istr); } - + } diff --git a/libs/libmysqlxx/include/mysqlxx/Row.h b/libs/libmysqlxx/include/mysqlxx/Row.h index 5be53f0d0ee..c59de26594c 100644 --- a/libs/libmysqlxx/include/mysqlxx/Row.h +++ b/libs/libmysqlxx/include/mysqlxx/Row.h @@ -3,6 +3,7 @@ #include #include #include +#include namespace mysqlxx diff --git a/libs/libmysqlxx/include/mysqlxx/Types.h b/libs/libmysqlxx/include/mysqlxx/Types.h index db9c9daf40b..0aadc148df6 100644 --- a/libs/libmysqlxx/include/mysqlxx/Types.h +++ b/libs/libmysqlxx/include/mysqlxx/Types.h @@ -4,8 +4,8 @@ #include #include -#include -#include +#include +#include namespace mysqlxx diff --git a/libs/libmysqlxx/include/mysqlxx/Value.h b/libs/libmysqlxx/include/mysqlxx/Value.h index e89867c8490..c76e4af8def 100644 --- a/libs/libmysqlxx/include/mysqlxx/Value.h +++ b/libs/libmysqlxx/include/mysqlxx/Value.h @@ -60,7 +60,7 @@ public: { if (unlikely(isNull())) throwException("Value is NULL"); - + return m_length > 0 && m_data[0] != '0'; } @@ -69,7 +69,7 @@ public: { if (unlikely(isNull())) throwException("Value is NULL"); - + return readUIntText(m_data, m_length);; } @@ -84,20 +84,20 @@ public: { if (unlikely(isNull())) throwException("Value is NULL"); - + return readFloatText(m_data, m_length); } /// Получить дату-время (из значения вида '2011-01-01 00:00:00'). - DateTime getDateTime() const + LocalDateTime getDateTime() const { - return DateTime(data(), size()); + return LocalDateTime(data(), size()); } /// Получить дату (из значения вида '2011-01-01' или '2011-01-01 00:00:00'). - Date getDate() const + LocalDate getDate() const { - return Date(data(), size()); + return LocalDate(data(), size()); } /// Получить строку. @@ -105,7 +105,7 @@ public: { if (unlikely(isNull())) throwException("Value is NULL"); - + return std::string(m_data, m_length); } @@ -136,7 +136,7 @@ private: size_t m_length; const ResultBase * res; - + bool checkDateTime() const { return (m_length == 10 || m_length == 19) && m_data[4] == '-' && m_data[7] == '-'; @@ -392,8 +392,8 @@ template <> inline unsigned long long Value::get() const { template <> inline float Value::get() const { return getDouble(); } template <> inline double Value::get() const { return getDouble(); } template <> inline std::string Value::get() const { return getString(); } -template <> inline Date Value::get() const { return getDate(); } -template <> inline DateTime Value::get() const { return getDateTime(); } +template <> inline LocalDate Value::get() const { return getDate(); } +template <> inline LocalDateTime Value::get() const { return getDateTime(); } template <> inline VisitID_t Value::get() const { return VisitID_t(getUInt()); } diff --git a/libs/libmysqlxx/include/mysqlxx/mysqlxx.h b/libs/libmysqlxx/include/mysqlxx/mysqlxx.h index 2a75152cc39..615b23bc822 100644 --- a/libs/libmysqlxx/include/mysqlxx/mysqlxx.h +++ b/libs/libmysqlxx/include/mysqlxx/mysqlxx.h @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include +#include #include @@ -63,5 +63,5 @@ * из принципа "всё, что не используется сейчас - не реализовано", * а также зависит от небольшого количества кода из других мест репозитория Метрики * (при необходимости, зависимости можно убрать). - * Предполагается, что пользователь сам допишет недостающий функционал. + * Предполагается, что пользователь сам допишет недостающую функциональность. */ diff --git a/libs/libmysqlxx/src/tests/mysqlxx_test.cpp b/libs/libmysqlxx/src/tests/mysqlxx_test.cpp index ae4abb92c22..543a008781a 100644 --- a/libs/libmysqlxx/src/tests/mysqlxx_test.cpp +++ b/libs/libmysqlxx/src/tests/mysqlxx_test.cpp @@ -33,8 +33,8 @@ int main(int argc, char ** argv) time_t t1 = row[0]; time_t t2 = row[1]; - std::cerr << t1 << ", " << mysqlxx::DateTime(t1) << std::endl; - std::cerr << t2 << ", " << mysqlxx::DateTime(t2) << std::endl; + std::cerr << t1 << ", " << LocalDateTime(t1) << std::endl; + std::cerr << t2 << ", " << LocalDateTime(t2) << std::endl; } }