Skip to content

Commit 04679fc

Browse files
committed
WL#13094 Support new utf8mb4 collations
Also added unit test that checks if all collations reported by server are covered by our logic.
1 parent 397cbc8 commit 04679fc

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-6
lines changed

cdk/include/mysql/cdk/protocol/mysqlx/collations.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@
302302
X(utf8mb4,247,vietnamese,ci) \
303303
X(utf8mb4,277,vi_0900,ai_ci) \
304304
X(utf8mb4,300,vi_0900,as_cs) \
305+
X(utf8mb4,304,ja_0900,as_cs_ks) \
306+
X(utf8mb4,305,uca0900,as_ci) \
307+
X(utf8mb4,306,ru_0900,ai_ci) \
308+
X(utf8mb4,307,ru_0900,as_cs) \
309+
X(utf8mb4,308,zh_0900,as_cs) \
310+
X(utf8mb4,309,uca0900,bin) \
305311
COLLATIONS_utf8mb4_EXTRA
306312

307313
#define COLLATIONS_utf8mb4_EXTRA

devapi/result.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ struct CollationInfo::Access
281281
enum coll_case {
282282
case_ci = CollationInfo::case_ci,
283283
case_ai_ci = case_ci,
284+
case_as_ci = case_ci,
284285
case_cs = CollationInfo::case_cs,
285286
case_as_cs = case_cs,
287+
case_as_cs_ks = case_cs,
286288
case_bin = CollationInfo::case_bin
287289
};
288290

@@ -317,11 +319,6 @@ coll_name(
317319
{
318320
static std::vector<std::string> special;
319321

320-
// Note: special exception for "binary" collation (no _bin suffix)
321-
322-
if (sensitivity == "bin")
323-
return cs == "binary" ? "binary" : name_bin;
324-
325322
/*
326323
For generic UCA collations, such as uca0900, the "uca" prefix is
327324
not present in the MySQL collation name. For example, for the uca0900
@@ -335,7 +332,14 @@ coll_name(
335332
special.push_back(cs + "_" + coll.substr(3) + "_" + sensitivity);
336333
return special.back().c_str();
337334
}
338-
return name;
335+
336+
if (sensitivity == "bin")
337+
{
338+
// Note: special exception for "binary" collation (no _bin suffix)
339+
return cs == "binary" ? "binary" : name_bin;
340+
}
341+
else
342+
return name;
339343
}
340344

341345

devapi/tests/types-t.cc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,56 @@ TEST_F(Types, string)
497497
}
498498

499499

500+
inline
501+
const CollationInfo* get_collation(unsigned id)
502+
{
503+
#define COLL_FIND(COL) COLLATIONS_##COL(COLL_FIND1)
504+
#define COLL_FIND1(CS,ID,COLL,CASE) \
505+
case ID: return &Collation<CharacterSet::CS>::COLL_CONST_NAME(COLL,CASE);
506+
507+
switch (id)
508+
{
509+
CDK_CS_LIST(COLL_FIND)
510+
default:
511+
return nullptr;
512+
}
513+
}
514+
515+
516+
TEST_F(Types, collations)
517+
{
518+
using col_data = std::pair<unsigned, string>;
519+
std::vector<col_data> unknown;
520+
521+
Table t = getSchema("information_schema").getTable("collations");
522+
523+
for (Row r : t.select("id", "collation_name").execute())
524+
{
525+
col_data col = { r[0], r[1] };
526+
527+
const CollationInfo *info = get_collation(col.first);
528+
529+
if (!info)
530+
unknown.push_back(col);
531+
else
532+
{
533+
EXPECT_EQ(std::string{ col.second }, std::string{ info->getName() })
534+
<< "bad collation name";
535+
}
536+
}
537+
538+
if (!unknown.empty())
539+
{
540+
cout << "Unknown collations:" << endl;
541+
for (col_data col : unknown)
542+
{
543+
cout << " -" << col.first << ": " << col.second << endl;
544+
}
545+
FAIL() << "There are unknown collations";
546+
}
547+
}
548+
549+
500550
TEST_F(Types, blob)
501551
{
502552
SKIP_IF_NO_XPLUGIN;

include/mysqlx/devapi/collations.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ static PUBLIC_API const CollationInfo COLL_CONST_NAME(COLL,CASE);
187187
#define COLL_CONST_NAME_ai_ci(COLL) COLL##_ai_ci
188188
#define COLL_CONST_NAME_cs(COLL) COLL##_cs
189189
#define COLL_CONST_NAME_as_cs(COLL) COLL##_as_cs
190+
#define COLL_CONST_NAME_as_ci(COLL) COLL##_as_ci
191+
#define COLL_CONST_NAME_as_cs_ks(COLL) COLL##_as_cs_ks
190192

191193
// Add utf8mb4 alias for bin collation for compatibility
192194

include/mysqlx/devapi/mysql_collations.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@
302302
X(utf8mb4,247,vietnamese,ci) \
303303
X(utf8mb4,277,vi_0900,ai_ci) \
304304
X(utf8mb4,300,vi_0900,as_cs) \
305+
X(utf8mb4,304,ja_0900,as_cs_ks) \
306+
X(utf8mb4,305,uca0900,as_ci) \
307+
X(utf8mb4,306,ru_0900,ai_ci) \
308+
X(utf8mb4,307,ru_0900,as_cs) \
309+
X(utf8mb4,308,zh_0900,as_cs) \
310+
X(utf8mb4,309,uca0900,bin) \
305311
COLLATIONS_utf8mb4_EXTRA
306312

307313
#define COLLATIONS_utf8mb4_EXTRA

0 commit comments

Comments
 (0)