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 <drizzled/replication/utility.h>
18
#include <drizzled/replication/rli.h>
19
#include <drizzled/error.h>
20
#include <drizzled/gettext.h>
22
/*********************************************************************
23
* table_def member definitions *
24
*********************************************************************/
27
This function returns the field size in raw bytes based on the type
28
and the encoded field data from the master's raw data.
30
uint32_t table_def::calc_field_size(uint32_t col, unsigned char *master_data) const
35
case DRIZZLE_TYPE_NEWDECIMAL:
36
length= my_decimal_get_binary_size(m_field_metadata[col] >> 8,
37
m_field_metadata[col] & 0xff);
39
case DRIZZLE_TYPE_DOUBLE:
40
length= m_field_metadata[col];
43
The cases for SET and ENUM are include for completeness, however
44
both are mapped to type DRIZZLE_TYPE_STRING and their real types
45
are encoded in the field metadata.
47
case DRIZZLE_TYPE_ENUM:
49
length= m_field_metadata[col] & 0x00ff;
52
case DRIZZLE_TYPE_LONG:
55
case DRIZZLE_TYPE_LONGLONG:
58
case DRIZZLE_TYPE_NULL:
61
case DRIZZLE_TYPE_DATE:
64
case DRIZZLE_TYPE_TIME:
67
case DRIZZLE_TYPE_TIMESTAMP:
70
case DRIZZLE_TYPE_DATETIME:
73
case DRIZZLE_TYPE_VARCHAR:
75
length= m_field_metadata[col] > 255 ? 2 : 1; // c&p of Field_varstring::data_length()
76
assert(uint2korr(master_data) > 0);
77
length+= length == 1 ? (uint32_t) *master_data : uint2korr(master_data);
80
case DRIZZLE_TYPE_BLOB:
82
length= uint4korr(master_data);
83
length+= m_field_metadata[col];
87
length= ~(uint32_t) 0;
93
Is the definition compatible with a table?
97
table_def::compatible_with(Relay_log_info const *rli_arg, Table *table)
101
We only check the initial columns for the tables.
103
uint32_t const cols_to_check= cmin(table->s->fields, size());
105
Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg);
107
TABLE_SHARE const *const tsh= table->s;
109
for (uint32_t col= 0 ; col < cols_to_check ; ++col)
111
if (table->field[col]->type() != type(col))
113
assert(col < size() && col < tsh->fields);
114
assert(tsh->db.str && tsh->table_name.str);
117
snprintf(buf, sizeof(buf), _("Column %d type mismatch - "
118
"received type %d, %s.%s has type %d"),
119
col, type(col), tsh->db.str, tsh->table_name.str,
120
table->field[col]->type());
121
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
122
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
125
Check the slave's field size against that of the master.
128
!table->field[col]->compatible_field_size(field_metadata(col)))
132
snprintf(buf, sizeof(buf), _("Column %d size mismatch - "
133
"master has size %d, %s.%s on slave has size %d."
134
" Master's column size should be <= the slave's "
135
"column size."), col,
136
table->field[col]->pack_length_from_metadata(
137
m_field_metadata[col]),
138
tsh->db.str, tsh->table_name.str,
139
table->field[col]->row_pack_length());
140
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
141
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);