diff --git a/datatypes/mcs_datatype.h b/datatypes/mcs_datatype.h index 93b673070..7ab9e5fac 100644 --- a/datatypes/mcs_datatype.h +++ b/datatypes/mcs_datatype.h @@ -490,7 +490,7 @@ inline bool isUnsignedInteger(const datatypes::SystemCatalog::ColDataType type) */ inline bool isUnsigned(const datatypes::SystemCatalog::ColDataType type) { - if (isUnsignedInteger(type)) + if (isUnsignedInteger(type)) return true; switch (type) @@ -518,14 +518,18 @@ inline bool isSignedInteger(const datatypes::SystemCatalog::ColDataType type) } } -inline bool sameSignednessInteger(const datatypes::SystemCatalog::ColDataType type1, const datatypes::SystemCatalog::ColDataType type2) +inline bool sameSignednessInteger(const datatypes::SystemCatalog::ColDataType type1, + const datatypes::SystemCatalog::ColDataType type2) { - return (isSignedInteger(type1) && isSignedInteger(type2)) || (isUnsignedInteger(type1) && isUnsignedInteger(type2)); + return (isSignedInteger(type1) && isSignedInteger(type2)) || + (isUnsignedInteger(type1) && isUnsignedInteger(type2)); } -inline bool differentSignednessInteger(const datatypes::SystemCatalog::ColDataType type1, const datatypes::SystemCatalog::ColDataType type2) +inline bool differentSignednessInteger(const datatypes::SystemCatalog::ColDataType type1, + const datatypes::SystemCatalog::ColDataType type2) { - return (isSignedInteger(type1) && isUnsignedInteger(type2)) || (isUnsignedInteger(type1) && isSignedInteger(type2)); + return (isSignedInteger(type1) && isUnsignedInteger(type2)) || + (isUnsignedInteger(type1) && isSignedInteger(type2)); } inline void promoteSignedInteger(datatypes::SystemCatalog::TypeHolderStd& unionedType) @@ -568,7 +572,7 @@ inline void promoteSignedInteger(datatypes::SystemCatalog::TypeHolderStd& unione unionedType.precision = datatypes::INT128MAXPRECISION; unionedType.scale = 0; return; - } + } default: idbassert(0); throw std::logic_error("datatypes::upcastSignedInteger: bad data type"); } @@ -590,40 +594,6 @@ namespace datatypes static constexpr int128_t minInt128 = int128_t(0x8000000000000000LL) << 64; static constexpr int128_t maxInt128 = (int128_t(0x7FFFFFFFFFFFFFFFLL) << 64) + 0xFFFFFFFFFFFFFFFFLL; -class ConstString -{ - const char* m_str; - size_t m_length; - - public: - ConstString(const char* str, size_t length) : m_str(str), m_length(length) - { - } - const char* str() const - { - return m_str; - } - const char* end() const - { - return m_str + m_length; - } - size_t length() const - { - return m_length; - } - void bin2hex(char* o) - { - static const char hexdig[] = {'0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - const char* e = end(); - for (const char* s = m_str; s < e; s++) - { - *o++ = hexdig[*s >> 4]; - *o++ = hexdig[*s & 0xf]; - } - } -}; - enum class round_style_t : uint8_t { NONE = 0, diff --git a/dbcon/mysql/ha_mcs_datatype.h b/dbcon/mysql/ha_mcs_datatype.h index 1ffafc38d..dbbbbe1d5 100644 --- a/dbcon/mysql/ha_mcs_datatype.h +++ b/dbcon/mysql/ha_mcs_datatype.h @@ -92,7 +92,7 @@ class StoreFieldMariaDB : public StoreField { size_t ll = length * 2; boost::scoped_array sca(new char[ll]); - ConstString(str, length).bin2hex(sca.get()); + utils::ConstString(str, length).bin2hex(sca.get()); return m_field->store_binary(sca.get(), ll); } return m_field->store_binary(str, length); @@ -103,7 +103,7 @@ class StoreFieldMariaDB : public StoreField return m_field->store(val, 0); } - int store_ulonglong(uint64_t val)override + int store_ulonglong(uint64_t val) override { return m_field->store(static_cast(val), 1); } @@ -844,4 +844,3 @@ class WriteBatchFieldMariaDB : public WriteBatchField }; } // end of namespace datatypes - diff --git a/utils/common/conststring.h b/utils/common/conststring.h index c1024c0a7..d29ac76b0 100644 --- a/utils/common/conststring.h +++ b/utils/common/conststring.h @@ -19,18 +19,21 @@ #include #include +#include +#include "exceptclasses.h" namespace utils { class ConstString { protected: - const char* mStr; + const char* mStr; // it can be NULL now. size_t mLength; public: ConstString(const char* str, size_t length) : mStr(str), mLength(length) { + idbassert(mStr || mLength == 0); // nullptr mStr should have zero length. } explicit ConstString(const std::string& str) : mStr(str.data()), mLength(str.length()) { @@ -49,6 +52,7 @@ class ConstString } std::string toString() const { + idbassert(mStr); return std::string(mStr, mLength); } bool eq(char ch) const @@ -73,6 +77,21 @@ class ConstString } return *this; } + void bin2hex(char* o) + { + static const char hexdig[] = {'0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + const char* e = end(); + for (const char* s = mStr; s < e; s++) + { + *o++ = hexdig[*s >> 4]; + *o++ = hexdig[*s & 0xf]; + } + } + bool isNull() const + { + return mStr == nullptr; + } }; } // namespace utils