19 #include "rpl_record.h"
21 #include "rpl_utility.h"
60 #if !defined(MYSQL_CLIENT)
63 uchar *row_data,
const uchar *
record)
65 Field **p_field= table->field, *field;
66 int const null_byte_count= (bitmap_bits_set(cols) + 7) / 8;
67 uchar *pack_ptr = row_data + null_byte_count;
68 uchar *null_ptr = row_data;
69 my_ptrdiff_t
const rec_offset= record - table->record[0];
70 my_ptrdiff_t
const def_offset= table->s->default_values - table->record[0];
72 DBUG_ENTER(
"pack_row");
79 unsigned int null_bits= (1
U << 8) - 1;
81 unsigned int null_mask= 1
U;
82 DBUG_PRINT(
"debug", (
"null ptr: 0x%lx; row start: %p; null bytes: %d",
83 (ulong) null_ptr, row_data, null_byte_count));
84 DBUG_DUMP(
"cols", (uchar*) cols->bitmap, cols->last_word_ptr - cols->bitmap + 1);
85 for ( ; (field= *p_field) ; p_field++)
87 if (bitmap_is_set(cols, p_field - table->field))
90 if (field->is_null(rec_offset))
92 DBUG_PRINT(
"debug", (
"Is NULL; null_mask: 0x%x; null_bits: 0x%x",
93 null_mask, null_bits));
95 null_bits |= null_mask;
100 null_bits &= ~null_mask;
110 const uchar *old_pack_ptr= pack_ptr;
112 pack_ptr= field->pack(pack_ptr, field->ptr + offset,
113 field->max_data_length(), TRUE);
114 DBUG_PRINT(
"debug", (
"field: %s; real_type: %d, pack_ptr: 0x%lx;"
115 " pack_ptr':0x%lx; bytes: %d",
116 field->field_name, field->real_type(),
117 (ulong) old_pack_ptr, (ulong) pack_ptr,
118 (int) (pack_ptr - old_pack_ptr)));
119 DBUG_DUMP(
"packed_data", old_pack_ptr, pack_ptr - old_pack_ptr);
123 if ((null_mask & 0xFF) == 0)
125 DBUG_ASSERT(null_ptr < row_data + null_byte_count);
127 *null_ptr++ = null_bits;
128 null_bits= (1
U << 8) - 1;
134 DBUG_PRINT(
"debug", (
"Skipped"));
142 if ((null_mask & 0xFF) > 1)
144 DBUG_ASSERT(null_ptr < row_data + null_byte_count);
145 *null_ptr++ = null_bits;
152 DBUG_ASSERT(null_ptr == row_data + null_byte_count);
153 DBUG_DUMP(
"row_data", row_data, pack_ptr - row_data);
154 DBUG_RETURN(static_cast<size_t>(pack_ptr - row_data));
197 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
200 TABLE *table, uint
const colcnt,
201 uchar
const *
const row_data,
MY_BITMAP const *cols,
202 uchar
const **
const row_end, ulong *
const master_reclength)
204 DBUG_ENTER(
"unpack_row");
205 DBUG_ASSERT(row_data);
207 size_t const master_null_byte_count= (bitmap_bits_set(cols) + 7) / 8;
210 uchar
const *null_ptr= row_data;
211 uchar
const *pack_ptr= row_data + master_null_byte_count;
213 if (bitmap_is_clear_all(cols))
220 *master_reclength= 0;
225 Field **
const begin_ptr = table->field;
227 Field **
const end_ptr= begin_ptr + colcnt;
229 DBUG_ASSERT(null_ptr < row_data + master_null_byte_count);
232 unsigned int null_mask= 1
U;
234 unsigned int null_bits= *null_ptr++;
237 TABLE *conv_table= NULL;
238 bool table_found= rli && rli->get_table_data(table, &tabledef, &conv_table);
239 DBUG_PRINT(
"debug", (
"Table data: table_found: %d, tabldef: %p, conv_table: %p",
240 table_found, tabledef, conv_table));
241 DBUG_ASSERT(table_found);
249 if (rli && !table_found)
250 DBUG_RETURN(HA_ERR_GENERIC);
252 for (field_ptr= begin_ptr ; field_ptr < end_ptr && *field_ptr ; ++field_ptr)
260 conv_table ? conv_table->field[field_ptr - begin_ptr] : NULL;
262 conv_field ? conv_field : *field_ptr;
263 DBUG_PRINT(
"debug", (
"Conversion %srequired for field '%s' (#%ld)",
264 conv_field ?
"" :
"not ",
265 (*field_ptr)->field_name,
266 (
long) (field_ptr - begin_ptr)));
267 DBUG_ASSERT(f != NULL);
269 DBUG_PRINT(
"debug", (
"field: %s; null mask: 0x%x; null bits: 0x%lx;"
270 " row start: %p; null bytes: %ld",
271 f->field_name, null_mask, (ulong) null_bits,
272 pack_ptr, (ulong) master_null_byte_count));
278 if (bitmap_is_set(cols, field_ptr - begin_ptr))
280 if ((null_mask & 0xFF) == 0)
282 DBUG_ASSERT(null_ptr < row_data + master_null_byte_count);
284 null_bits= *null_ptr++;
287 DBUG_ASSERT(null_mask & 0xFF);
290 DBUG_ASSERT(pack_ptr != NULL);
292 if (null_bits & null_mask)
296 DBUG_PRINT(
"debug", (
"Was NULL; null mask: 0x%x; null bits: 0x%x",
297 null_mask, null_bits));
319 push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
320 ER_BAD_NULL_ERROR, ER(ER_BAD_NULL_ERROR),
333 uint16
const metadata= tabledef->field_metadata(i);
335 uchar
const *
const old_pack_ptr= pack_ptr;
337 pack_ptr= f->
unpack(f->ptr, pack_ptr, metadata, TRUE);
338 DBUG_PRINT(
"debug", (
"Unpacked; metadata: 0x%x;"
339 " pack_ptr: 0x%lx; pack_ptr': 0x%lx; bytes: %d",
340 metadata, (ulong) old_pack_ptr, (ulong) pack_ptr,
341 (
int) (pack_ptr - old_pack_ptr)));
349 DBUG_ASSERT(tabledef->type(i) == MYSQL_TYPE_DECIMAL ||
350 tabledef->calc_field_size(i, (uchar *) old_pack_ptr) ==
351 (uint32) (pack_ptr - old_pack_ptr));
364 char source_buf[MAX_FIELD_WIDTH];
365 char value_buf[MAX_FIELD_WIDTH];
366 String source_type(source_buf,
sizeof(source_buf), system_charset_info);
367 String value_string(value_buf,
sizeof(value_buf), system_charset_info);
368 conv_field->sql_type(source_type);
369 conv_field->val_str(&value_string);
370 DBUG_PRINT(
"debug", (
"Copying field '%s' of type '%s' with value '%s'",
371 (*field_ptr)->field_name,
372 source_type.c_ptr_safe(), value_string.c_ptr_safe()));
374 copy.set(*field_ptr, f, TRUE);
375 (*copy.do_copy)(©);
377 char target_buf[MAX_FIELD_WIDTH];
378 String target_type(target_buf,
sizeof(target_buf), system_charset_info);
379 (*field_ptr)->sql_type(target_type);
380 (*field_ptr)->val_str(&value_string);
381 DBUG_PRINT(
"debug", (
"Value of field '%s' of type '%s' is now '%s'",
382 (*field_ptr)->field_name,
383 target_type.c_ptr_safe(), value_string.c_ptr_safe()));
392 DBUG_PRINT(
"debug", (
"Non-existent: skipped"));
401 uint max_cols= min<ulong>(tabledef->
size(), cols->n_bits);
402 for (; i < max_cols; i++)
404 if (bitmap_is_set(cols, i))
406 if ((null_mask & 0xFF) == 0)
408 DBUG_ASSERT(null_ptr < row_data + master_null_byte_count);
410 null_bits= *null_ptr++;
412 DBUG_ASSERT(null_mask & 0xFF);
414 if (!((null_bits & null_mask) && tabledef->maybe_null(i))) {
415 uint32 len= tabledef->calc_field_size(i, (uchar *) pack_ptr);
416 DBUG_DUMP(
"field_data", pack_ptr, len);
427 DBUG_ASSERT(null_ptr == row_data + master_null_byte_count);
429 DBUG_DUMP(
"row_data", row_data, pack_ptr - row_data);
432 if (master_reclength)
435 *master_reclength = (*field_ptr)->ptr - table->record[0];
437 *master_reclength = table->s->reclength;
456 int prepare_record(
TABLE *
const table,
const MY_BITMAP *cols,
const bool check)
458 DBUG_ENTER(
"prepare_record");
460 restore_record(table, s->default_values);
472 DBUG_PRINT_BITSET(
"debug",
"cols: %s", cols);
473 for (
Field **field_ptr= table->field; *field_ptr; ++field_ptr)
475 if ((uint) (field_ptr - table->field) >= cols->n_bits ||
476 !bitmap_is_set(cols, field_ptr - table->field))
478 Field *
const f= *field_ptr;
479 if ((f->flags & NO_DEFAULT_VALUE_FLAG) &&
480 (f->real_type() != MYSQL_TYPE_ENUM))
483 push_warning_printf(current_thd,
484 Sql_condition::WARN_LEVEL_WARN,
485 ER_NO_DEFAULT_FOR_FIELD,
486 ER(ER_NO_DEFAULT_FOR_FIELD),
495 #endif // HAVE_REPLICATION