- Notifications
You must be signed in to change notification settings - Fork 255
/
Copy pathcollations.h
208 lines (154 loc) · 5.77 KB
/
collations.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* Copyright (c) 2016, 2024, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is designed to work with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms, as
* designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an additional
* permission to link the program and your derivative works with the
* separately licensed software that they have either included with
* the program or referenced in the documentation.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* https://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MYSQLX_COLLATIONS_H
#defineMYSQLX_COLLATIONS_H
#include"common.h"
/*
Import Lists of built-in character sets and collations supported by MySQL
Server.
*/
#include"mysql_charsets.h"
#include"mysql_collations.h"
namespacemysqlx {
MYSQLX_ABI_BEGIN(2,0)
/*
Enumeration of known character sets. For each character set CS listed
in CDK_CS_LIST() macro, there is CharacterSet::CS constant in this
enumeration.
*/
enumclassCharacterSet : unsignedshort
{
#undef CS
#defineCS_ENUM(CS) CS,
CDK_CS_LIST(CS_ENUM)
};
#defineCS_NAME_SWITCH(CS) case CharacterSet::CS: return #CS;
/**
Returns name of a character set given by its id.
@ingroup devapi_res
*/
inline
constchar* characterSetName(CharacterSet id)
{
switch (id)
{
CDK_CS_LIST(CS_NAME_SWITCH)
default:
THROW("Unknown character set id");
}
}
/**
Structure that provides information about character set collation.
For each known collation COLL over character set CS, there is static object
`Collation<CS>::%COLL` of type `CollationInfo` which describes
collation COLL. For example `Collation<CharacterSet::latin1>::%swedish_ci` is
an `CollationInfo` object which describes the `swedish_ci` collation over
`latin1` character set.
@ingroup devapi_res
*/
structCollationInfo
{
/// Numeric collation id, as used by MySQL server.
unsignedid() const { return m_id; }
/// String name of a collation, such as "latin1_generic_ci".
constchar *getName() const { return m_name; }
/// Id of the character set of this collation.
CharacterSet getCharacterSet() const { return m_cs; }
/**
Returns true if given collation is case sensitive. Binary
collations are assumed to be case sensitive.
*/
boolisCaseSensitive() const { return m_case != case_ci; }
/// Returns true if this is binary collation.
boolisBinary() const { return m_case == case_bin; }
booloperator==(const CollationInfo &other) const
{
return m_id == other.m_id;
}
booloperator!=(const CollationInfo &other) const
{
return !operator==(other);
}
private:
enum coll_case { case_bin, case_ci, case_cs };
CharacterSet m_cs;
unsigned m_id;
coll_case m_case;
constchar *m_name;
public:
structAccess;
friend Access;
};
template <CharacterSet CS> structCollation;
/*
The Collation<CS>::COLL constants are generated from information provided by
COLLATION_XXX() macros.Each line X(CS, ID, COLL, CASE) in the expansion of
a COLLATION_XXX() macro declares collation with name COLL for character set
CS. ID is the MySQL id number for the collation. CASE is one of ci, cs or bin
and indicates whether it is case insensitive, sensitive or binary collation,
respectively.
*/
/*
Generate declarations of Collation<CS>::COLL constants using
COLLATINS_XXX() macros. The list CS_LIST() is processed using
COLL_DECL() macro, which for each character set CS declares
specialization Collation<CS> of the Collation<> template and
declares collation constants within this specialization.
The collation constant declarations are generated by processing
COLLATIONS_CS() list with COLL_CONST() macro. The name of each
constant is generated by COLL_CONST_NAME() macro. The convention
used is that case insensitive and case sensitive collations get
a _ci or _cs suffix, respectively, while binary collation constant
have no suffix to the collation name.
Collation constants declared here are defined in file result.cc.
*/
#defineCOLL_DECL(CS) \
template<> structCollation<CharacterSet::CS> \
{ COLLATIONS_##CS(COLL_CONST) }; \
#defineCOLL_CONST(CS,ID,COLL,CASE) \
static PUBLIC_API const CollationInfo COLL_CONST_NAME(COLL,CASE);
#defineCOLL_CONST_NAME(COLL,CASE) COLL_CONST_NAME_##CASE(COLL)
#defineCOLL_CONST_NAME_bin(COLL) COLL
#defineCOLL_CONST_NAME_ci(COLL) COLL##_ci
#defineCOLL_CONST_NAME_ai_ci(COLL) COLL##_ai_ci
#defineCOLL_CONST_NAME_cs(COLL) COLL##_cs
#defineCOLL_CONST_NAME_as_cs(COLL) COLL##_as_cs
#defineCOLL_CONST_NAME_as_ci(COLL) COLL##_as_ci
#defineCOLL_CONST_NAME_as_cs_ks(COLL) COLL##_as_cs_ks
// Add utf8mb4 alias for bin collation for compatibility
#undef COLLATIONS_utf8mb4_EXTRA
#defineCOLLATIONS_utf8mb4_EXTRA \
static PUBLIC_API const CollationInfo utf8mb4;
CDK_CS_LIST(COLL_DECL)
#undef COLLATIONS_utf8mb4_EXTRA
#defineCOLLATIONS_utf8mb4_EXTRA
MYSQLX_ABI_END(2,0)
} // mysqlx
#endif