2
#include "mysql_priv.h"
3
#include "rpl_record_old.h"
6
pack_row_old(TABLE *table, MY_BITMAP const* cols,
7
byte *row_data, const byte *record)
9
Field **p_field= table->field, *field;
10
int n_null_bytes= table->s->null_bytes;
13
my_ptrdiff_t const rec_offset= record - table->record[0];
14
my_ptrdiff_t const def_offset= table->s->default_values - table->record[0];
15
memcpy(row_data, record, n_null_bytes);
16
ptr= row_data+n_null_bytes;
18
for (i= 0 ; (field= *p_field) ; i++, p_field++)
20
if (bitmap_is_set(cols,i))
22
my_ptrdiff_t const offset=
23
field->is_null(rec_offset) ? def_offset : rec_offset;
24
field->move_field_offset(offset);
25
ptr= (byte*)field->pack((char *) ptr, field->ptr);
26
field->move_field_offset(-offset);
29
return (static_cast<my_size_t>(ptr - row_data));
34
Unpack a row into a record.
39
table Table to unpack into
40
colcnt Number of columns to read from record
41
record Record where the data should be unpacked
43
cols Pointer to columns data to fill in
44
row_end Pointer to variable that will hold the value of the
45
one-after-end position for the row
47
Pointer to variable that will be set to the length of the
48
record on the master side
49
rw_set Pointer to bitmap that holds either the read_set or the
50
write_set of the table
54
The row is assumed to only consist of the fields for which the
55
bitset represented by 'arr' and 'bits'; the other parts of the
56
record are left alone.
58
At most 'colcnt' columns are read: if the table is larger than
59
that, the remaining fields are not filled in.
63
Error code, or zero if no error. The following error codes can
66
ER_NO_DEFAULT_FOR_FIELD
67
Returned if one of the fields existing on the slave but not on
68
the master does not have a default value (and isn't nullable)
70
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
72
unpack_row_old(RELAY_LOG_INFO *rli,
73
TABLE *table, uint const colcnt, byte *record,
74
char const *row, MY_BITMAP const *cols,
75
char const **row_end, ulong *master_reclength,
76
MY_BITMAP* const rw_set, Log_event_type const event_type)
78
DBUG_ASSERT(record && row);
79
my_ptrdiff_t const offset= record - (byte*) table->record[0];
80
my_size_t master_null_bytes= table->s->null_bytes;
82
if (colcnt != table->s->fields)
84
Field **fptr= &table->field[colcnt-1];
86
master_null_bytes= (*fptr)->last_null_byte();
87
while (master_null_bytes == Field::LAST_NULL_BYTE_UNDEF &&
88
fptr-- > table->field);
91
If master_null_bytes is LAST_NULL_BYTE_UNDEF (0) at this time,
92
there were no nullable fields nor BIT fields at all in the
93
columns that are common to the master and the slave. In that
94
case, there is only one null byte holding the X bit.
96
OBSERVE! There might still be nullable columns following the
97
common columns, so table->s->null_bytes might be greater than 1.
99
if (master_null_bytes == Field::LAST_NULL_BYTE_UNDEF)
100
master_null_bytes= 1;
103
DBUG_ASSERT(master_null_bytes <= table->s->null_bytes);
104
memcpy(record, row, master_null_bytes); // [1]
107
bitmap_set_all(rw_set);
109
Field **const begin_ptr = table->field;
111
char const *ptr= row + master_null_bytes;
112
Field **const end_ptr= begin_ptr + colcnt;
113
for (field_ptr= begin_ptr ; field_ptr < end_ptr ; ++field_ptr)
115
Field *const f= *field_ptr;
117
if (bitmap_is_set(cols, field_ptr - begin_ptr))
119
f->move_field_offset(offset);
120
ptr= f->unpack(f->ptr, ptr);
121
f->move_field_offset(-offset);
122
/* Field...::unpack() cannot return 0 */
123
DBUG_ASSERT(ptr != NULL);
126
bitmap_clear_bit(rw_set, field_ptr - begin_ptr);
130
if (master_reclength)
133
*master_reclength = (*field_ptr)->ptr - (char*) table->record[0];
135
*master_reclength = table->s->reclength;
139
Set properties for remaining columns, if there are any. We let the
140
corresponding bit in the write_set be set, to write the value if
141
it was not there already. We iterate over all remaining columns,
142
even if there were an error, to get as many error messages as
143
possible. We are still able to return a pointer to the next row,
146
This generation of error messages is only relevant when inserting
149
for ( ; *field_ptr ; ++field_ptr)
151
uint32 const mask= NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG;
153
DBUG_PRINT("debug", ("flags = 0x%x, mask = 0x%x, flags & mask = 0x%x",
154
(*field_ptr)->flags, mask,
155
(*field_ptr)->flags & mask));
157
if (event_type == WRITE_ROWS_EVENT &&
158
((*field_ptr)->flags & mask) == mask)
160
slave_print_msg(ERROR_LEVEL, rli, ER_NO_DEFAULT_FOR_FIELD,
161
"Field `%s` of table `%s`.`%s` "
162
"has no default value and cannot be NULL",
163
(*field_ptr)->field_name, table->s->db.str,
164
table->s->table_name.str);
165
error = ER_NO_DEFAULT_FOR_FIELD;
168
(*field_ptr)->set_default();