~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/innodb_plugin/data/data0type.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
 
4
 
 
5
This program is free software; you can redistribute it and/or modify it under
 
6
the terms of the GNU General Public License as published by the Free Software
 
7
Foundation; version 2 of the License.
 
8
 
 
9
This program is distributed in the hope that it will be useful, but WITHOUT
 
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 
12
 
 
13
You should have received a copy of the GNU General Public License along with
 
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 USA
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
/**************************************************//**
 
20
@file data/data0type.c
 
21
Data types
 
22
 
 
23
Created 1/16/1996 Heikki Tuuri
 
24
*******************************************************/
 
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
 
36
this MySQL installation to this global variable. If we have < 4.1.2 format
 
37
column definitions, or records in the insert buffer, we use this
 
38
charset-collation code for them. */
 
39
 
 
40
UNIV_INTERN ulint       data_mysql_default_charset_coll;
 
41
 
 
42
/*********************************************************************//**
 
43
Determine how many bytes the first n characters of the given string occupy.
 
44
If the string is shorter than n characters, returns the number of bytes
 
45
the characters in the string occupy.
 
46
@return length of the prefix, in bytes */
 
47
UNIV_INTERN
 
48
ulint
 
49
dtype_get_at_most_n_mbchars(
 
50
/*========================*/
 
51
        ulint           prtype,         /*!< in: precise type */
 
52
        ulint           mbminlen,       /*!< in: minimum length of a
 
53
                                        multi-byte character */
 
54
        ulint           mbmaxlen,       /*!< in: maximum length of a
 
55
                                        multi-byte character */
 
56
        ulint           prefix_len,     /*!< in: length of the requested
 
57
                                        prefix, in characters, multiplied by
 
58
                                        dtype_get_mbmaxlen(dtype) */
 
59
        ulint           data_len,       /*!< in: length of str (in bytes) */
 
60
        const char*     str)            /*!< in: the string whose prefix
 
61
                                        length is being determined */
 
62
{
 
63
        ut_a(data_len != UNIV_SQL_NULL);
 
64
        ut_ad(!mbmaxlen || !(prefix_len % mbmaxlen));
 
65
 
 
66
        if (mbminlen != mbmaxlen) {
 
67
                ut_a(!(prefix_len % mbmaxlen));
 
68
                return(innobase_get_at_most_n_mbchars(
 
69
                        dtype_get_charset_coll(prtype),
 
70
                        prefix_len, data_len, str));
 
71
        }
 
72
 
 
73
        if (prefix_len < data_len) {
 
74
 
 
75
                return(prefix_len);
 
76
 
 
77
        }
 
78
 
 
79
        return(data_len);
 
80
}
 
81
#endif /* UNIV_HOTBACKUP */
 
82
 
 
83
/*********************************************************************//**
 
84
Checks if a data main type is a string type. Also a BLOB is considered a
 
85
string type.
 
86
@return TRUE if string type */
 
87
UNIV_INTERN
 
88
ibool
 
89
dtype_is_string_type(
 
90
/*=================*/
 
91
        ulint   mtype)  /*!< in: InnoDB main data type code: DATA_CHAR, ... */
 
92
{
 
93
        if (mtype <= DATA_BLOB
 
94
            || mtype == DATA_MYSQL
 
95
            || mtype == DATA_VARMYSQL) {
 
96
 
 
97
                return(TRUE);
 
98
        }
 
99
 
 
100
        return(FALSE);
 
101
}
 
102
 
 
103
/*********************************************************************//**
 
104
Checks if a type is a binary string type. Note that for tables created with
 
105
< 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column. For
 
106
those DATA_BLOB columns this function currently returns FALSE.
 
107
@return TRUE if binary string type */
 
108
UNIV_INTERN
 
109
ibool
 
110
dtype_is_binary_string_type(
 
111
/*========================*/
 
112
        ulint   mtype,  /*!< in: main data type */
 
113
        ulint   prtype) /*!< in: precise type */
 
114
{
 
115
        if ((mtype == DATA_FIXBINARY)
 
116
            || (mtype == DATA_BINARY)
 
117
            || (mtype == DATA_BLOB && (prtype & DATA_BINARY_TYPE))) {
 
118
 
 
119
                return(TRUE);
 
120
        }
 
121
 
 
122
        return(FALSE);
 
123
}
 
124
 
 
125
/*********************************************************************//**
 
126
Checks if a type is a non-binary string type. That is, dtype_is_string_type is
 
127
TRUE and dtype_is_binary_string_type is FALSE. Note that for tables created
 
128
with < 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column.
 
129
For those DATA_BLOB columns this function currently returns TRUE.
 
130
@return TRUE if non-binary string type */
 
131
UNIV_INTERN
 
132
ibool
 
133
dtype_is_non_binary_string_type(
 
134
/*============================*/
 
135
        ulint   mtype,  /*!< in: main data type */
 
136
        ulint   prtype) /*!< in: precise type */
 
137
{
 
138
        if (dtype_is_string_type(mtype) == TRUE
 
139
            && dtype_is_binary_string_type(mtype, prtype) == FALSE) {
 
140
 
 
141
                return(TRUE);
 
142
        }
 
143
 
 
144
        return(FALSE);
 
145
}
 
146
 
 
147
/*********************************************************************//**
 
148
Forms a precise type from the < 4.1.2 format precise type plus the
 
149
charset-collation code.
 
150
@return precise type, including the charset-collation code */
 
151
UNIV_INTERN
 
152
ulint
 
153
dtype_form_prtype(
 
154
/*==============*/
 
155
        ulint   old_prtype,     /*!< in: the MySQL type code and the flags
 
156
                                DATA_BINARY_TYPE etc. */
 
157
        ulint   charset_coll)   /*!< in: MySQL charset-collation code */
 
158
{
 
159
        ut_a(old_prtype < 256 * 256);
 
160
        ut_a(charset_coll < 256);
 
161
 
 
162
        return(old_prtype + (charset_coll << 16));
 
163
}
 
164
 
 
165
/*********************************************************************//**
 
166
Validates a data type structure.
 
167
@return TRUE if ok */
 
168
UNIV_INTERN
 
169
ibool
 
170
dtype_validate(
 
171
/*===========*/
 
172
        const dtype_t*  type)   /*!< in: type struct to validate */
 
173
{
 
174
        ut_a(type);
 
175
        ut_a(type->mtype >= DATA_VARCHAR);
 
176
        ut_a(type->mtype <= DATA_MYSQL);
 
177
 
 
178
        if (type->mtype == DATA_SYS) {
 
179
                ut_a((type->prtype & DATA_MYSQL_TYPE_MASK) < DATA_N_SYS_COLS);
 
180
        }
 
181
 
 
182
#ifndef UNIV_HOTBACKUP
 
183
        ut_a(type->mbminlen <= type->mbmaxlen);
 
184
#endif /* !UNIV_HOTBACKUP */
 
185
 
 
186
        return(TRUE);
 
187
}
 
188
 
 
189
#ifndef UNIV_HOTBACKUP
 
190
/*********************************************************************//**
 
191
Prints a data type structure. */
 
192
UNIV_INTERN
 
193
void
 
194
dtype_print(
 
195
/*========*/
 
196
        const dtype_t*  type)   /*!< in: type */
 
197
{
 
198
        ulint   mtype;
 
199
        ulint   prtype;
 
200
        ulint   len;
 
201
 
 
202
        ut_a(type);
 
203
 
 
204
        mtype = type->mtype;
 
205
        prtype = type->prtype;
 
206
 
 
207
        switch (mtype) {
 
208
        case DATA_VARCHAR:
 
209
                fputs("DATA_VARCHAR", stderr);
 
210
                break;
 
211
 
 
212
        case DATA_CHAR:
 
213
                fputs("DATA_CHAR", stderr);
 
214
                break;
 
215
 
 
216
        case DATA_BINARY:
 
217
                fputs("DATA_BINARY", stderr);
 
218
                break;
 
219
 
 
220
        case DATA_FIXBINARY:
 
221
                fputs("DATA_FIXBINARY", stderr);
 
222
                break;
 
223
 
 
224
        case DATA_BLOB:
 
225
                fputs("DATA_BLOB", stderr);
 
226
                break;
 
227
 
 
228
        case DATA_INT:
 
229
                fputs("DATA_INT", stderr);
 
230
                break;
 
231
 
 
232
        case DATA_MYSQL:
 
233
                fputs("DATA_MYSQL", stderr);
 
234
                break;
 
235
 
 
236
        case DATA_SYS:
 
237
                fputs("DATA_SYS", stderr);
 
238
                break;
 
239
 
 
240
        case DATA_FLOAT:
 
241
                fputs("DATA_FLOAT", stderr);
 
242
                break;
 
243
 
 
244
        case DATA_DOUBLE:
 
245
                fputs("DATA_DOUBLE", stderr);
 
246
                break;
 
247
 
 
248
        case DATA_DECIMAL:
 
249
                fputs("DATA_DECIMAL", stderr);
 
250
                break;
 
251
 
 
252
        case DATA_VARMYSQL:
 
253
                fputs("DATA_VARMYSQL", stderr);
 
254
                break;
 
255
 
 
256
        default:
 
257
                fprintf(stderr, "type %lu", (ulong) mtype);
 
258
                break;
 
259
        }
 
260
 
 
261
        len = type->len;
 
262
 
 
263
        if ((type->mtype == DATA_SYS)
 
264
            || (type->mtype == DATA_VARCHAR)
 
265
            || (type->mtype == DATA_CHAR)) {
 
266
                putc(' ', stderr);
 
267
                if (prtype == DATA_ROW_ID) {
 
268
                        fputs("DATA_ROW_ID", stderr);
 
269
                        len = DATA_ROW_ID_LEN;
 
270
                } else if (prtype == DATA_ROLL_PTR) {
 
271
                        fputs("DATA_ROLL_PTR", stderr);
 
272
                        len = DATA_ROLL_PTR_LEN;
 
273
                } else if (prtype == DATA_TRX_ID) {
 
274
                        fputs("DATA_TRX_ID", stderr);
 
275
                        len = DATA_TRX_ID_LEN;
 
276
                } else if (prtype == DATA_ENGLISH) {
 
277
                        fputs("DATA_ENGLISH", stderr);
 
278
                } else {
 
279
                        fprintf(stderr, "prtype %lu", (ulong) prtype);
 
280
                }
 
281
        } else {
 
282
                if (prtype & DATA_UNSIGNED) {
 
283
                        fputs(" DATA_UNSIGNED", stderr);
 
284
                }
 
285
 
 
286
                if (prtype & DATA_BINARY_TYPE) {
 
287
                        fputs(" DATA_BINARY_TYPE", stderr);
 
288
                }
 
289
 
 
290
                if (prtype & DATA_NOT_NULL) {
 
291
                        fputs(" DATA_NOT_NULL", stderr);
 
292
                }
 
293
        }
 
294
 
 
295
        fprintf(stderr, " len %lu", (ulong) len);
 
296
}
 
297
#endif /* !UNIV_HOTBACKUP */