~drizzle-developers/pkg-libinnodb/karmic

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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*****************************************************************************

Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.

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 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., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA

*****************************************************************************/

/******************************************************
Data types

Created 1/16/1996 Heikki Tuuri
*******************************************************/

#include "data0type.h"

#ifdef UNIV_NONINL
#include "data0type.ic"
#endif

#ifndef UNIV_HOTBACKUP

/* At the database startup we store the default-charset collation number of
this installation to this global variable. If we have < 4.1.2 format
column definitions, or records in the insert buffer, we use this
charset-collation code for them. */

UNIV_INTERN ulint	data_client_default_charset_coll;

/*************************************************************************
Reset dtype variables. */
UNIV_INTERN
void
dtype_var_init(void)
/*================*/
{
	data_client_default_charset_coll = 0;
}

/*************************************************************************
Determine how many bytes the first n characters of the given string occupy.
If the string is shorter than n characters, returns the number of bytes
the characters in the string occupy. */
UNIV_INTERN
ulint
dtype_get_at_most_n_mbchars(
/*========================*/
					/* out: length of the prefix,
					in bytes */
	ulint		prtype,		/* in: precise type */
	ulint		mbminlen,	/* in: minimum length of a
					multi-byte character */
	ulint		mbmaxlen,	/* in: maximum length of a
					multi-byte character */
	ulint		prefix_len,	/* in: length of the requested
					prefix, in characters, multiplied by
					dtype_get_mbmaxlen(dtype) */
	ulint		data_len,	/* in: length of str (in bytes) */
	const char*	str)		/* in: the string whose prefix
					length is being determined */
{
	ut_a(data_len != UNIV_SQL_NULL);
	ut_ad(!mbmaxlen || !(prefix_len % mbmaxlen));

	if (mbminlen != mbmaxlen) {
		const charset_t*cs;

		ut_a(!(prefix_len % mbmaxlen));

		cs = ib_ucode_get_charset(dtype_get_charset_coll(prtype));

		return(ib_ucode_get_storage_size(
			cs, prefix_len, data_len, str));
	}

	if (prefix_len < data_len) {

		return(prefix_len);

	}

	return(data_len);
}
#endif /* UNIV_HOTBACKUP */

/*************************************************************************
Checks if a data main type is a string type. Also a BLOB is considered a
string type. */
UNIV_INTERN
ibool
dtype_is_string_type(
/*=================*/
			/* out: TRUE if string type */
	ulint	mtype)	/* in: InnoDB main data type code: DATA_CHAR, ... */
{
	if (mtype <= DATA_BLOB
	    || mtype == DATA_CLIENT
	    || mtype == DATA_VARCLIENT) {

		return(TRUE);
	}

	return(FALSE);
}

/*************************************************************************
Checks if a type is a binary string type. Note that for tables created with
< 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column. For
those DATA_BLOB columns this function currently returns FALSE. */
UNIV_INTERN
ibool
dtype_is_binary_string_type(
/*========================*/
			/* out: TRUE if binary string type */
	ulint	mtype,	/* in: main data type */
	ulint	prtype)	/* in: precise type */
{
	if ((mtype == DATA_FIXBINARY)
	    || (mtype == DATA_BINARY)
	    || (mtype == DATA_BLOB && (prtype & DATA_BINARY_TYPE))) {

		return(TRUE);
	}

	return(FALSE);
}

/*************************************************************************
Checks if a type is a non-binary string type. That is, dtype_is_string_type is
TRUE and dtype_is_binary_string_type is FALSE. Note that for tables created
with < 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column.
For those DATA_BLOB columns this function currently returns TRUE. */
UNIV_INTERN
ibool
dtype_is_non_binary_string_type(
/*============================*/
			/* out: TRUE if non-binary string type */
	ulint	mtype,	/* in: main data type */
	ulint	prtype)	/* in: precise type */
{
	if (dtype_is_string_type(mtype) == TRUE
	    && dtype_is_binary_string_type(mtype, prtype) == FALSE) {

		return(TRUE);
	}

	return(FALSE);
}

/*************************************************************************
Forms a precise type from the < 4.1.2 format precise type plus the
charset-collation code. */
UNIV_INTERN
ulint
dtype_form_prtype(
/*==============*/
	ulint	old_prtype,	/* in: the user type code and the flags
				DATA_BINARY_TYPE etc. */
	ulint	charset_coll)	/* in: user charset-collation code */
{
	ut_a(old_prtype < 256 * 256);
	ut_a(charset_coll < 256);

	return(old_prtype + (charset_coll << 16));
}

/*************************************************************************
Validates a data type structure. */
UNIV_INTERN
ibool
dtype_validate(
/*===========*/
				/* out: TRUE if ok */
	const dtype_t*	type)	/* in: type struct to validate */
{
	ut_a(type);
	ut_a(type->mtype >= DATA_VARCHAR);
	ut_a(type->mtype <= DATA_CLIENT);

	if (type->mtype == DATA_SYS) {
		ut_a((type->prtype & DATA_CLIENT_TYPE_MASK) < DATA_N_SYS_COLS);
	}

#ifndef UNIV_HOTBACKUP
	ut_a(type->mbminlen <= type->mbmaxlen);
#endif /* !UNIV_HOTBACKUP */

	return(TRUE);
}

#ifndef UNIV_HOTBACKUP
/*************************************************************************
Prints a data type structure. */
UNIV_INTERN
void
dtype_print(
/*========*/
	const dtype_t*	type)	/* in: type */
{
	ulint	mtype;
	ulint	prtype;
	ulint	len;

	ut_a(type);

	mtype = type->mtype;
	prtype = type->prtype;

	switch (mtype) {
	case DATA_VARCHAR:
		ib_logger(ib_stream, "DATA_VARCHAR");
		break;

	case DATA_CHAR:
		ib_logger(ib_stream, "DATA_CHAR");
		break;

	case DATA_BINARY:
		ib_logger(ib_stream, "DATA_BINARY");
		break;

	case DATA_FIXBINARY:
		ib_logger(ib_stream, "DATA_FIXBINARY");
		break;

	case DATA_BLOB:
		ib_logger(ib_stream, "DATA_BLOB");
		break;

	case DATA_INT:
		ib_logger(ib_stream, "DATA_INT");
		break;

	case DATA_CLIENT:
		ib_logger(ib_stream, "DATA_CLIENT");
		break;

	case DATA_SYS:
		ib_logger(ib_stream, "DATA_SYS");
		break;

	default:
		ib_logger(ib_stream, "type %lu", (ulong) mtype);
		break;
	}

	len = type->len;

	if ((type->mtype == DATA_SYS)
	    || (type->mtype == DATA_VARCHAR)
	    || (type->mtype == DATA_CHAR)) {
		ib_logger(ib_stream, " ");
		if (prtype == DATA_ROW_ID) {
			ib_logger(ib_stream, "DATA_ROW_ID");
			len = DATA_ROW_ID_LEN;
		} else if (prtype == DATA_ROLL_PTR) {
			ib_logger(ib_stream, "DATA_ROLL_PTR");
			len = DATA_ROLL_PTR_LEN;
		} else if (prtype == DATA_TRX_ID) {
			ib_logger(ib_stream, "DATA_TRX_ID");
			len = DATA_TRX_ID_LEN;
		} else if (prtype == DATA_ENGLISH) {
			ib_logger(ib_stream, "DATA_ENGLISH");
		} else {
			ib_logger(ib_stream, "prtype %lu", (ulong) prtype);
		}
	} else {
		if (prtype & DATA_UNSIGNED) {
			ib_logger(ib_stream, " DATA_UNSIGNED");
		}

		if (prtype & DATA_BINARY_TYPE) {
			ib_logger(ib_stream, " DATA_BINARY_TYPE");
		}

		if (prtype & DATA_NOT_NULL) {
			ib_logger(ib_stream, " DATA_NOT_NULL");
		}
	}

	ib_logger(ib_stream, " len %lu", (ulong) len);
}
#endif /* !UNIV_HOTBACKUP */