1
/* Copyright (C) 2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
#include "rpl_utility.h"
19
/*********************************************************************
20
* table_def member definitions *
21
*********************************************************************/
24
This function returns the field size in raw bytes based on the type
25
and the encoded field data from the master's raw data.
27
uint32 table_def::calc_field_size(uint col, uchar *master_data) const
32
case MYSQL_TYPE_NEWDECIMAL:
33
length= my_decimal_get_binary_size(m_field_metadata[col] >> 8,
34
m_field_metadata[col] & 0xff);
36
case MYSQL_TYPE_DOUBLE:
37
length= m_field_metadata[col];
40
The cases for SET and ENUM are include for completeness, however
41
both are mapped to type MYSQL_TYPE_STRING and their real types
42
are encoded in the field metadata.
46
case MYSQL_TYPE_STRING:
48
uchar type= m_field_metadata[col] >> 8U;
49
if ((type == MYSQL_TYPE_SET) || (type == MYSQL_TYPE_ENUM))
50
length= m_field_metadata[col] & 0x00ff;
54
We are reading the actual size from the master_data record
55
because this field has the actual lengh stored in the first
58
length= (uint) *master_data + 1;
67
case MYSQL_TYPE_SHORT:
73
case MYSQL_TYPE_LONGLONG:
79
case MYSQL_TYPE_NEWDATE:
85
case MYSQL_TYPE_TIMESTAMP:
88
case MYSQL_TYPE_DATETIME:
91
case MYSQL_TYPE_VARCHAR:
93
length= m_field_metadata[col] > 255 ? 2 : 1; // c&p of Field_varstring::data_length()
94
assert(uint2korr(master_data) > 0);
95
length+= length == 1 ? (uint32) *master_data : uint2korr(master_data);
100
length= uint4korr(master_data);
101
length+= m_field_metadata[col];
111
Is the definition compatible with a table?
115
table_def::compatible_with(Relay_log_info const *rli_arg, TABLE *table)
119
We only check the initial columns for the tables.
121
uint const cols_to_check= min(table->s->fields, size());
123
Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg);
125
TABLE_SHARE const *const tsh= table->s;
127
for (uint col= 0 ; col < cols_to_check ; ++col)
129
if (table->field[col]->type() != type(col))
131
assert(col < size() && col < tsh->fields);
132
assert(tsh->db.str && tsh->table_name.str);
135
snprintf(buf, sizeof(buf), "Column %d type mismatch - "
136
"received type %d, %s.%s has type %d",
137
col, type(col), tsh->db.str, tsh->table_name.str,
138
table->field[col]->type());
139
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
140
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
143
Check the slave's field size against that of the master.
146
!table->field[col]->compatible_field_size(field_metadata(col)))
150
snprintf(buf, sizeof(buf), "Column %d size mismatch - "
151
"master has size %d, %s.%s on slave has size %d."
152
" Master's column size should be <= the slave's "
154
table->field[col]->pack_length_from_metadata(
155
m_field_metadata[col]),
156
tsh->db.str, tsh->table_name.str,
157
table->field[col]->row_pack_length());
158
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
159
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);