drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
data0type.cc
1/*****************************************************************************
2
3Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15St, Fifth Floor, Boston, MA 02110-1301 USA
16
17*****************************************************************************/
18
19/**************************************************/
25
26#include "data0type.h"
27
28#ifdef UNIV_NONINL
29#include "data0type.ic"
30#endif
31
32#ifndef UNIV_HOTBACKUP
33# include "ha_prototypes.h"
34
35/* At the database startup we store the default-charset collation number of
36this MySQL installation to this global variable. If we have < 4.1.2 format
37column definitions, or records in the insert buffer, we use this
38charset-collation code for them. */
39
40UNIV_INTERN ulint data_mysql_default_charset_coll;
41
42/*********************************************************************/
47UNIV_INTERN
48ulint
49dtype_get_at_most_n_mbchars(
50/*========================*/
51 ulint prtype,
52 ulint mbminmaxlen,
54 ulint prefix_len,
57 ulint data_len,
58 const char* str)
60{
61 ulint mbminlen = DATA_MBMINLEN(mbminmaxlen);
62 ulint mbmaxlen = DATA_MBMAXLEN(mbminmaxlen);
63
64 ut_a(data_len != UNIV_SQL_NULL);
65 ut_ad(!mbmaxlen || !(prefix_len % mbmaxlen));
66
67 if (mbminlen != mbmaxlen) {
68 ut_a(!(prefix_len % mbmaxlen));
71 prefix_len, data_len, str));
72 }
73
74 if (prefix_len < data_len) {
75
76 return(prefix_len);
77
78 }
79
80 return(data_len);
81}
82#endif /* UNIV_HOTBACKUP */
83
84/*********************************************************************/
88UNIV_INTERN
89ibool
90dtype_is_string_type(
91/*=================*/
92 ulint mtype)
93{
94 if (mtype <= DATA_BLOB
95 || mtype == DATA_MYSQL
96 || mtype == DATA_VARMYSQL) {
97
98 return(TRUE);
99 }
100
101 return(FALSE);
102}
103
104/*********************************************************************/
109UNIV_INTERN
110ibool
111dtype_is_binary_string_type(
112/*========================*/
113 ulint mtype,
114 ulint prtype)
115{
116 if ((mtype == DATA_FIXBINARY)
117 || (mtype == DATA_BINARY)
118 || (mtype == DATA_BLOB && (prtype & DATA_BINARY_TYPE))) {
119
120 return(TRUE);
121 }
122
123 return(FALSE);
124}
125
126/*********************************************************************/
132UNIV_INTERN
133ibool
134dtype_is_non_binary_string_type(
135/*============================*/
136 ulint mtype,
137 ulint prtype)
138{
139 if (dtype_is_string_type(mtype) == TRUE
140 && dtype_is_binary_string_type(mtype, prtype) == FALSE) {
141
142 return(TRUE);
143 }
144
145 return(FALSE);
146}
147
148/*********************************************************************/
152UNIV_INTERN
153ulint
154dtype_form_prtype(
155/*==============*/
156 ulint old_prtype,
158 ulint charset_coll)
159{
160 ut_a(old_prtype < 256 * 256);
161 ut_a(charset_coll < 256);
162
163 return(old_prtype + (charset_coll << 16));
164}
165
166/*********************************************************************/
169UNIV_INTERN
170ibool
171dtype_validate(
172/*===========*/
173 const dtype_t* type)
174{
175 ut_a(type);
176 ut_a(type->mtype >= DATA_VARCHAR);
177 ut_a(type->mtype <= DATA_MYSQL);
178
179 if (type->mtype == DATA_SYS) {
180 ut_a((type->prtype & DATA_MYSQL_TYPE_MASK) < DATA_N_SYS_COLS);
181 }
182
183#ifndef UNIV_HOTBACKUP
185#endif /* !UNIV_HOTBACKUP */
186
187 return(TRUE);
188}
189
190#ifndef UNIV_HOTBACKUP
191/*********************************************************************/
193UNIV_INTERN
194void
195dtype_print(
196/*========*/
197 const dtype_t* type)
198{
199 ulint mtype;
200 ulint prtype;
201 ulint len;
202
203 ut_a(type);
204
205 mtype = type->mtype;
206 prtype = type->prtype;
207
208 switch (mtype) {
209 case DATA_VARCHAR:
210 fputs("DATA_VARCHAR", stderr);
211 break;
212
213 case DATA_CHAR:
214 fputs("DATA_CHAR", stderr);
215 break;
216
217 case DATA_BINARY:
218 fputs("DATA_BINARY", stderr);
219 break;
220
221 case DATA_FIXBINARY:
222 fputs("DATA_FIXBINARY", stderr);
223 break;
224
225 case DATA_BLOB:
226 fputs("DATA_BLOB", stderr);
227 break;
228
229 case DATA_INT:
230 fputs("DATA_INT", stderr);
231 break;
232
233 case DATA_MYSQL:
234 fputs("DATA_MYSQL", stderr);
235 break;
236
237 case DATA_SYS:
238 fputs("DATA_SYS", stderr);
239 break;
240
241 case DATA_FLOAT:
242 fputs("DATA_FLOAT", stderr);
243 break;
244
245 case DATA_DOUBLE:
246 fputs("DATA_DOUBLE", stderr);
247 break;
248
249 case DATA_DECIMAL:
250 fputs("DATA_DECIMAL", stderr);
251 break;
252
253 case DATA_VARMYSQL:
254 fputs("DATA_VARMYSQL", stderr);
255 break;
256
257 default:
258 fprintf(stderr, "type %lu", (ulong) mtype);
259 break;
260 }
261
262 len = type->len;
263
264 if ((type->mtype == DATA_SYS)
265 || (type->mtype == DATA_VARCHAR)
266 || (type->mtype == DATA_CHAR)) {
267 putc(' ', stderr);
268 if (prtype == DATA_ROW_ID) {
269 fputs("DATA_ROW_ID", stderr);
270 len = DATA_ROW_ID_LEN;
271 } else if (prtype == DATA_ROLL_PTR) {
272 fputs("DATA_ROLL_PTR", stderr);
273 len = DATA_ROLL_PTR_LEN;
274 } else if (prtype == DATA_TRX_ID) {
275 fputs("DATA_TRX_ID", stderr);
276 len = DATA_TRX_ID_LEN;
277 } else if (prtype == DATA_ENGLISH) {
278 fputs("DATA_ENGLISH", stderr);
279 } else {
280 fprintf(stderr, "prtype %lu", (ulong) prtype);
281 }
282 } else {
283 if (prtype & DATA_UNSIGNED) {
284 fputs(" DATA_UNSIGNED", stderr);
285 }
286
287 if (prtype & DATA_BINARY_TYPE) {
288 fputs(" DATA_BINARY_TYPE", stderr);
289 }
290
291 if (prtype & DATA_NOT_NULL) {
292 fputs(" DATA_NOT_NULL", stderr);
293 }
294 }
295
296 fprintf(stderr, " len %lu", (ulong) len);
297}
298#endif /* !UNIV_HOTBACKUP */
UNIV_INLINE ulint dtype_get_charset_coll(ulint prtype)
UNIV_INLINE ulint dtype_get_mbminlen(const dtype_t *type)
UNIV_INLINE ulint dtype_get_mbmaxlen(const dtype_t *type)
ulint innobase_get_at_most_n_mbchars(ulint charset_id, ulint prefix_len, ulint data_len, const char *str)
#define ut_ad(EXPR)
Definition ut0dbg.h:127
#define ut_a(EXPR)
Definition ut0dbg.h:105