1
/******************************************************
6
Created 1/16/1996 Heikki Tuuri
7
*******************************************************/
12
#include "data0type.ic"
15
/**********************************************************************
16
This function is used to find the storage length in bytes of the first n
17
characters for prefix indexes using a multibyte character set. The function
18
finds charset information and returns length of prefix_len characters in the
21
NOTE: the prototype of this function is copied from ha_innodb.cc! If you change
22
this function, you MUST change also the prototype here! */
25
innobase_get_at_most_n_mbchars(
26
/*===========================*/
27
/* out: number of bytes occupied by the first
29
ulint charset_id, /* in: character set id */
30
ulint prefix_len, /* in: prefix length in bytes of the index
31
(this has to be divided by mbmaxlen to get the
32
number of CHARACTERS n in the prefix) */
33
ulint data_len, /* in: length of the string in bytes */
34
const char* str); /* in: character string */
36
/* At the database startup we store the default-charset collation number of
37
this MySQL installation to this global variable. If we have < 4.1.2 format
38
column definitions, or records in the insert buffer, we use this
39
charset-collation code for them. */
41
ulint data_mysql_default_charset_coll = 99999999;
43
/*************************************************************************
44
Determine how many bytes the first n characters of the given string occupy.
45
If the string is shorter than n characters, returns the number of bytes
46
the characters in the string occupy. */
49
dtype_get_at_most_n_mbchars(
50
/*========================*/
51
/* out: length of the prefix,
53
ulint prtype, /* in: precise type */
54
ulint mbminlen, /* in: minimum length of a
55
multi-byte character */
56
ulint mbmaxlen, /* in: maximum length of a
57
multi-byte character */
58
ulint prefix_len, /* in: length of the requested
59
prefix, in characters, multiplied by
60
dtype_get_mbmaxlen(dtype) */
61
ulint data_len, /* in: length of str (in bytes) */
62
const char* str) /* in: the string whose prefix
63
length is being determined */
65
#ifndef UNIV_HOTBACKUP
66
ut_a(data_len != UNIV_SQL_NULL);
67
ut_ad(!mbmaxlen || !(prefix_len % mbmaxlen));
69
if (mbminlen != mbmaxlen) {
70
ut_a(!(prefix_len % mbmaxlen));
71
return(innobase_get_at_most_n_mbchars(
72
dtype_get_charset_coll(prtype),
73
prefix_len, data_len, str));
76
if (prefix_len < data_len) {
83
#else /* UNIV_HOTBACKUP */
84
/* This function depends on MySQL code that is not included in
85
InnoDB Hot Backup builds. Besides, this function should never
86
be called in InnoDB Hot Backup. */
88
#endif /* UNIV_HOTBACKUP */
91
/*************************************************************************
92
Checks if a data main type is a string type. Also a BLOB is considered a
98
/* out: TRUE if string type */
99
ulint mtype) /* in: InnoDB main data type code: DATA_CHAR, ... */
101
if (mtype <= DATA_BLOB
102
|| mtype == DATA_MYSQL
103
|| mtype == DATA_VARMYSQL) {
111
/*************************************************************************
112
Checks if a type is a binary string type. Note that for tables created with
113
< 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column. For
114
those DATA_BLOB columns this function currently returns FALSE. */
117
dtype_is_binary_string_type(
118
/*========================*/
119
/* out: TRUE if binary string type */
120
ulint mtype, /* in: main data type */
121
ulint prtype) /* in: precise type */
123
if ((mtype == DATA_FIXBINARY)
124
|| (mtype == DATA_BINARY)
125
|| (mtype == DATA_BLOB && (prtype & DATA_BINARY_TYPE))) {
133
/*************************************************************************
134
Checks if a type is a non-binary string type. That is, dtype_is_string_type is
135
TRUE and dtype_is_binary_string_type is FALSE. Note that for tables created
136
with < 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column.
137
For those DATA_BLOB columns this function currently returns TRUE. */
140
dtype_is_non_binary_string_type(
141
/*============================*/
142
/* out: TRUE if non-binary string type */
143
ulint mtype, /* in: main data type */
144
ulint prtype) /* in: precise type */
146
if (dtype_is_string_type(mtype) == TRUE
147
&& dtype_is_binary_string_type(mtype, prtype) == FALSE) {
155
/*************************************************************************
156
Gets the MySQL charset-collation code for MySQL string types. */
159
dtype_get_charset_coll_noninline(
160
/*=============================*/
161
ulint prtype) /* in: precise data type */
163
return(dtype_get_charset_coll(prtype));
166
/*************************************************************************
167
Forms a precise type from the < 4.1.2 format precise type plus the
168
charset-collation code. */
173
ulint old_prtype, /* in: the MySQL type code and the flags
174
DATA_BINARY_TYPE etc. */
175
ulint charset_coll) /* in: MySQL charset-collation code */
177
ut_a(old_prtype < 256 * 256);
178
ut_a(charset_coll < 256);
180
return(old_prtype + (charset_coll << 16));
183
/*************************************************************************
184
Validates a data type structure. */
189
/* out: TRUE if ok */
190
dtype_t* type) /* in: type struct to validate */
193
ut_a(type->mtype >= DATA_VARCHAR);
194
ut_a(type->mtype <= DATA_MYSQL);
196
if (type->mtype == DATA_SYS) {
197
ut_a((type->prtype & DATA_MYSQL_TYPE_MASK) < DATA_N_SYS_COLS);
200
ut_a(type->mbminlen <= type->mbmaxlen);
205
/*************************************************************************
206
Prints a data type structure. */
211
dtype_t* type) /* in: type */
220
prtype = type->prtype;
224
fputs("DATA_VARCHAR", stderr);
228
fputs("DATA_CHAR", stderr);
232
fputs("DATA_BINARY", stderr);
236
fputs("DATA_FIXBINARY", stderr);
240
fputs("DATA_BLOB", stderr);
244
fputs("DATA_INT", stderr);
248
fputs("DATA_MYSQL", stderr);
252
fputs("DATA_SYS", stderr);
256
fprintf(stderr, "type %lu", (ulong) mtype);
262
if ((type->mtype == DATA_SYS)
263
|| (type->mtype == DATA_VARCHAR)
264
|| (type->mtype == DATA_CHAR)) {
266
if (prtype == DATA_ROW_ID) {
267
fputs("DATA_ROW_ID", stderr);
268
len = DATA_ROW_ID_LEN;
269
} else if (prtype == DATA_ROLL_PTR) {
270
fputs("DATA_ROLL_PTR", stderr);
271
len = DATA_ROLL_PTR_LEN;
272
} else if (prtype == DATA_TRX_ID) {
273
fputs("DATA_TRX_ID", stderr);
274
len = DATA_TRX_ID_LEN;
275
} else if (prtype == DATA_ENGLISH) {
276
fputs("DATA_ENGLISH", stderr);
278
fprintf(stderr, "prtype %lu", (ulong) prtype);
281
if (prtype & DATA_UNSIGNED) {
282
fputs(" DATA_UNSIGNED", stderr);
285
if (prtype & DATA_BINARY_TYPE) {
286
fputs(" DATA_BINARY_TYPE", stderr);
289
if (prtype & DATA_NOT_NULL) {
290
fputs(" DATA_NOT_NULL", stderr);
294
fprintf(stderr, " len %lu", (ulong) len);