1
/************************************************************************
2
SQL data field and tuple
4
(c) 1994-1996 Innobase Oy
6
Created 5/30/1994 Heikki Tuuri
7
*************************************************************************/
12
extern byte data_error;
14
/*************************************************************************
15
Gets pointer to the type struct of SQL data field. */
20
/* out: pointer to the type struct */
21
dfield_t* field) /* in: SQL data field */
25
return(&(field->type));
28
/*************************************************************************
29
Sets the type struct of SQL data field. */
34
dfield_t* field, /* in: SQL data field */
35
dtype_t* type) /* in: pointer to data type struct */
42
/*************************************************************************
43
Gets pointer to the data in a field. */
48
/* out: pointer to data */
49
dfield_t* field) /* in: field */
52
ut_ad((field->len == UNIV_SQL_NULL)
53
|| (field->data != &data_error));
58
/*************************************************************************
59
Gets length of field data. */
64
/* out: length of data; UNIV_SQL_NULL if
66
dfield_t* field) /* in: field */
69
ut_ad((field->len == UNIV_SQL_NULL)
70
|| (field->data != &data_error));
75
/*************************************************************************
76
Sets length in a field. */
81
dfield_t* field, /* in: field */
82
ulint len) /* in: length or UNIV_SQL_NULL */
89
/*************************************************************************
90
Sets pointer to the data and length in a field. */
95
dfield_t* field, /* in: field */
96
const void* data, /* in: data */
97
ulint len) /* in: length or UNIV_SQL_NULL */
101
field->data = (void*) data;
105
/*************************************************************************
106
Copies the data and len fields. */
111
dfield_t* field1, /* in: field to copy to */
112
dfield_t* field2) /* in: field to copy from */
114
ut_ad(field1 && field2);
116
field1->data = field2->data;
117
field1->len = field2->len;
120
/*************************************************************************
121
Copies a data field to another. */
126
dfield_t* field1, /* in: field to copy to */
127
dfield_t* field2) /* in: field to copy from */
132
/*************************************************************************
133
Tests if data length and content is equal for two dfields. */
136
dfield_datas_are_binary_equal(
137
/*==========================*/
138
/* out: TRUE if equal */
139
dfield_t* field1, /* in: field */
140
dfield_t* field2) /* in: field */
146
if ((len != field2->len)
147
|| ((len != UNIV_SQL_NULL)
148
&& (0 != ut_memcmp(field1->data, field2->data, len)))) {
156
/*************************************************************************
157
Gets info bits in a data tuple. */
160
dtuple_get_info_bits(
161
/*=================*/
163
dtuple_t* tuple) /* in: tuple */
167
return(tuple->info_bits);
170
/*************************************************************************
171
Sets info bits in a data tuple. */
174
dtuple_set_info_bits(
175
/*=================*/
176
dtuple_t* tuple, /* in: tuple */
177
ulint info_bits) /* in: info bits */
181
tuple->info_bits = info_bits;
184
/*************************************************************************
185
Gets number of fields used in record comparisons. */
188
dtuple_get_n_fields_cmp(
189
/*====================*/
190
/* out: number of fields used in comparisons
192
dtuple_t* tuple) /* in: tuple */
196
return(tuple->n_fields_cmp);
199
/*************************************************************************
200
Sets number of fields used in record comparisons. */
203
dtuple_set_n_fields_cmp(
204
/*====================*/
205
dtuple_t* tuple, /* in: tuple */
206
ulint n_fields_cmp) /* in: number of fields used in
207
comparisons in rem0cmp.* */
210
ut_ad(n_fields_cmp <= tuple->n_fields);
212
tuple->n_fields_cmp = n_fields_cmp;
215
/*************************************************************************
216
Gets number of fields in a data tuple. */
221
/* out: number of fields */
222
dtuple_t* tuple) /* in: tuple */
226
return(tuple->n_fields);
229
/*************************************************************************
230
Gets nth field of a tuple. */
233
dtuple_get_nth_field(
234
/*=================*/
236
dtuple_t* tuple, /* in: tuple */
237
ulint n) /* in: index of field */
240
ut_ad(n < tuple->n_fields);
242
return(tuple->fields + n);
245
/**************************************************************
246
Creates a data tuple to a memory heap. The default value for number
247
of fields used in record comparisons for this tuple is n_fields. */
252
/* out, own: created tuple */
253
mem_heap_t* heap, /* in: memory heap where the tuple
255
ulint n_fields) /* in: number of fields */
261
tuple = (dtuple_t*) mem_heap_alloc(heap, sizeof(dtuple_t)
262
+ n_fields * sizeof(dfield_t));
263
tuple->info_bits = 0;
264
tuple->n_fields = n_fields;
265
tuple->n_fields_cmp = n_fields;
266
tuple->fields = (dfield_t*)(((byte*)tuple) + sizeof(dtuple_t));
269
tuple->magic_n = DATA_TUPLE_MAGIC_N;
271
{ /* In the debug version, initialize fields to an error value */
274
for (i = 0; i < n_fields; i++) {
275
(tuple->fields + i)->data = &data_error;
276
dfield_get_type(tuple->fields + i)->mtype = DATA_ERROR;
283
/**************************************************************
284
The following function returns the sum of data lengths of a tuple. The space
285
occupied by the field structs or the tuple struct is not counted. Neither
286
is possible space in externally stored parts of the field. */
289
dtuple_get_data_size(
290
/*=================*/
291
/* out: sum of data lengths */
292
dtuple_t* tuple) /* in: typed data tuple */
301
ut_ad(dtuple_check_typed(tuple));
302
ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N);
304
n_fields = tuple->n_fields;
306
for (i = 0; i < n_fields; i++) {
307
field = dtuple_get_nth_field(tuple, i);
308
len = dfield_get_len(field);
310
if (len == UNIV_SQL_NULL) {
311
len = dtype_get_sql_null_size(dfield_get_type(field));
320
/***********************************************************************
321
Sets types of fields binary in a tuple. */
324
dtuple_set_types_binary(
325
/*====================*/
326
dtuple_t* tuple, /* in: data tuple */
327
ulint n) /* in: number of fields to set */
329
dtype_t* dfield_type;
332
for (i = 0; i < n; i++) {
333
dfield_type = dfield_get_type(dtuple_get_nth_field(tuple, i));
334
dtype_set(dfield_type, DATA_BINARY, 0, 0, 0);
338
/****************************************************************
339
Folds a prefix given as the number of fields of a tuple. */
344
/* out: the folded value */
345
dtuple_t* tuple, /* in: the tuple */
346
ulint n_fields,/* in: number of complete fields to fold */
347
ulint n_bytes,/* in: number of bytes to fold in an
348
incomplete last field */
349
dulint tree_id)/* in: index tree id */
358
ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N);
359
ut_ad(dtuple_check_typed(tuple));
361
fold = ut_fold_dulint(tree_id);
363
for (i = 0; i < n_fields; i++) {
364
field = dtuple_get_nth_field(tuple, i);
366
data = (byte*) dfield_get_data(field);
367
len = dfield_get_len(field);
369
if (len != UNIV_SQL_NULL) {
370
fold = ut_fold_ulint_pair(fold,
371
ut_fold_binary(data, len));
376
field = dtuple_get_nth_field(tuple, i);
378
data = (byte*) dfield_get_data(field);
379
len = dfield_get_len(field);
381
if (len != UNIV_SQL_NULL) {
386
fold = ut_fold_ulint_pair(fold,
387
ut_fold_binary(data, len));
394
/**************************************************************************
395
Writes an SQL null field full of zeros. */
400
byte* data, /* in: pointer to a buffer of size len */
401
ulint len) /* in: SQL null size in bytes */
405
for (j = 0; j < len; j++) {
410
/**************************************************************************
411
Checks if a dtuple contains an SQL null value. */
414
dtuple_contains_null(
415
/*=================*/
416
/* out: TRUE if some field is SQL null */
417
dtuple_t* tuple) /* in: dtuple */
422
n = dtuple_get_n_fields(tuple);
424
for (i = 0; i < n; i++) {
425
if (dfield_get_len(dtuple_get_nth_field(tuple, i))