diff --git a/clickhouse/types/types.cpp b/clickhouse/types/types.cpp index 591c07b..ccf9e8a 100644 --- a/clickhouse/types/types.cpp +++ b/clickhouse/types/types.cpp @@ -123,17 +123,14 @@ std::string Type::GetName() const { } else { result = "Enum16("; } - for (auto ei = enum_->value_to_name.begin(); ; ) { + for (auto ei = enum_->value_to_name.begin(); ei != enum_->value_to_name.end(); ++ei) { + if (ei != enum_->value_to_name.begin()) { + result += ", "; + } result += "'"; result += ei->second; result += "' = "; result += std::to_string(ei->first); - - if (++ei != enum_->value_to_name.end()) { - result += ", "; - } else { - break; - } } result += ")"; return result; diff --git a/ut/types_ut.cpp b/ut/types_ut.cpp index 22529fb..67a155a 100644 --- a/ut/types_ut.cpp +++ b/ut/types_ut.cpp @@ -30,6 +30,15 @@ TEST(TypesCase, TypeName) { Type::CreateString()})->GetName(), "Tuple(Int32, String)" ); + + ASSERT_EQ( + Type::CreateEnum8({{"One", 1}})->GetName(), + "Enum8('One' = 1)" + ); + ASSERT_EQ( + Type::CreateEnum8({})->GetName(), + "Enum8()" + ); } TEST(TypesCase, NullableType) {