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 <drizzled/server_includes.h>
17
#include "rpl_utility.h"
19
#include <drizzled/drizzled_error_messages.h>
21
/*********************************************************************
22
* table_def member definitions *
23
*********************************************************************/
26
This function returns the field size in raw bytes based on the type
27
and the encoded field data from the master's raw data.
29
uint32_t table_def::calc_field_size(uint col, uchar *master_data) const
34
case DRIZZLE_TYPE_NEWDECIMAL:
35
length= my_decimal_get_binary_size(m_field_metadata[col] >> 8,
36
m_field_metadata[col] & 0xff);
38
case DRIZZLE_TYPE_DOUBLE:
39
length= m_field_metadata[col];
42
The cases for SET and ENUM are include for completeness, however
43
both are mapped to type DRIZZLE_TYPE_STRING and their real types
44
are encoded in the field metadata.
46
case DRIZZLE_TYPE_ENUM:
48
length= m_field_metadata[col] & 0x00ff;
51
case DRIZZLE_TYPE_TINY:
54
case DRIZZLE_TYPE_LONG:
57
case DRIZZLE_TYPE_LONGLONG:
60
case DRIZZLE_TYPE_NULL:
63
case DRIZZLE_TYPE_NEWDATE:
66
case DRIZZLE_TYPE_TIME:
69
case DRIZZLE_TYPE_TIMESTAMP:
72
case DRIZZLE_TYPE_DATETIME:
75
case DRIZZLE_TYPE_VARCHAR:
77
length= m_field_metadata[col] > 255 ? 2 : 1; // c&p of Field_varstring::data_length()
78
assert(uint2korr(master_data) > 0);
79
length+= length == 1 ? (uint32_t) *master_data : uint2korr(master_data);
82
case DRIZZLE_TYPE_BLOB:
84
length= uint4korr(master_data);
85
length+= m_field_metadata[col];
89
length= ~(uint32_t) 0;
95
Is the definition compatible with a table?
99
table_def::compatible_with(Relay_log_info const *rli_arg, Table *table)
103
We only check the initial columns for the tables.
105
uint const cols_to_check= cmin(table->s->fields, size());
107
Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg);
109
TABLE_SHARE const *const tsh= table->s;
111
for (uint col= 0 ; col < cols_to_check ; ++col)
113
if (table->field[col]->type() != type(col))
115
assert(col < size() && col < tsh->fields);
116
assert(tsh->db.str && tsh->table_name.str);
119
snprintf(buf, sizeof(buf), _("Column %d type mismatch - "
120
"received type %d, %s.%s has type %d"),
121
col, type(col), tsh->db.str, tsh->table_name.str,
122
table->field[col]->type());
123
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
124
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
127
Check the slave's field size against that of the master.
130
!table->field[col]->compatible_field_size(field_metadata(col)))
134
snprintf(buf, sizeof(buf), _("Column %d size mismatch - "
135
"master has size %d, %s.%s on slave has size %d."
136
" Master's column size should be <= the slave's "
137
"column size."), col,
138
table->field[col]->pack_length_from_metadata(
139
m_field_metadata[col]),
140
tsh->db.str, tsh->table_name.str,
141
table->field[col]->row_pack_length());
142
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
143
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);