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(uint32_t col, unsigned char *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_LONG:
54
case DRIZZLE_TYPE_LONGLONG:
57
case DRIZZLE_TYPE_NULL:
60
case DRIZZLE_TYPE_NEWDATE:
63
case DRIZZLE_TYPE_TIME:
66
case DRIZZLE_TYPE_TIMESTAMP:
69
case DRIZZLE_TYPE_DATETIME:
72
case DRIZZLE_TYPE_VARCHAR:
74
length= m_field_metadata[col] > 255 ? 2 : 1; // c&p of Field_varstring::data_length()
75
assert(uint2korr(master_data) > 0);
76
length+= length == 1 ? (uint32_t) *master_data : uint2korr(master_data);
79
case DRIZZLE_TYPE_BLOB:
81
length= uint4korr(master_data);
82
length+= m_field_metadata[col];
86
length= ~(uint32_t) 0;
92
Is the definition compatible with a table?
96
table_def::compatible_with(Relay_log_info const *rli_arg, Table *table)
100
We only check the initial columns for the tables.
102
uint32_t const cols_to_check= cmin(table->s->fields, size());
104
Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg);
106
TABLE_SHARE const *const tsh= table->s;
108
for (uint32_t col= 0 ; col < cols_to_check ; ++col)
110
if (table->field[col]->type() != type(col))
112
assert(col < size() && col < tsh->fields);
113
assert(tsh->db.str && tsh->table_name.str);
116
snprintf(buf, sizeof(buf), _("Column %d type mismatch - "
117
"received type %d, %s.%s has type %d"),
118
col, type(col), tsh->db.str, tsh->table_name.str,
119
table->field[col]->type());
120
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
121
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
124
Check the slave's field size against that of the master.
127
!table->field[col]->compatible_field_size(field_metadata(col)))
131
snprintf(buf, sizeof(buf), _("Column %d size mismatch - "
132
"master has size %d, %s.%s on slave has size %d."
133
" Master's column size should be <= the slave's "
134
"column size."), col,
135
table->field[col]->pack_length_from_metadata(
136
m_field_metadata[col]),
137
tsh->db.str, tsh->table_name.str,
138
table->field[col]->row_pack_length());
139
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
140
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);