1
by brian
clean slate |
1 |
/* Copyright (C) 2006 MySQL AB
|
2 |
||
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.
|
|
6 |
||
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.
|
|
11 |
||
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 */
|
|
15 |
||
243.1.17
by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.) |
16 |
#include <drizzled/server_includes.h> |
1
by brian
clean slate |
17 |
#include "rpl_utility.h" |
18 |
#include "rpl_rli.h" |
|
202.3.6
by Monty Taylor
First pass at gettexizing the error messages. |
19 |
#include <drizzled/drizzled_error_messages.h> |
1
by brian
clean slate |
20 |
|
21 |
/*********************************************************************
|
|
22 |
* table_def member definitions *
|
|
23 |
*********************************************************************/
|
|
24 |
||
25 |
/*
|
|
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.
|
|
28 |
*/
|
|
205
by Brian Aker
uint32 -> uin32_t |
29 |
uint32_t table_def::calc_field_size(uint col, uchar *master_data) const |
1
by brian
clean slate |
30 |
{
|
205
by Brian Aker
uint32 -> uin32_t |
31 |
uint32_t length= 0; |
1
by brian
clean slate |
32 |
|
33 |
switch (type(col)) { |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
34 |
case DRIZZLE_TYPE_NEWDECIMAL: |
1
by brian
clean slate |
35 |
length= my_decimal_get_binary_size(m_field_metadata[col] >> 8, |
36 |
m_field_metadata[col] & 0xff); |
|
37 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
38 |
case DRIZZLE_TYPE_DOUBLE: |
1
by brian
clean slate |
39 |
length= m_field_metadata[col]; |
40 |
break; |
|
41 |
/*
|
|
42 |
The cases for SET and ENUM are include for completeness, however
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
43 |
both are mapped to type DRIZZLE_TYPE_STRING and their real types
|
1
by brian
clean slate |
44 |
are encoded in the field metadata.
|
45 |
*/
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
46 |
case DRIZZLE_TYPE_SET: |
47 |
case DRIZZLE_TYPE_ENUM: |
|
1
by brian
clean slate |
48 |
{
|
241
by Brian Aker
First pass of CHAR removal. |
49 |
length= m_field_metadata[col] & 0x00ff; |
1
by brian
clean slate |
50 |
break; |
51 |
}
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
52 |
case DRIZZLE_TYPE_TINY: |
1
by brian
clean slate |
53 |
length= 1; |
54 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
55 |
case DRIZZLE_TYPE_SHORT: |
1
by brian
clean slate |
56 |
length= 2; |
57 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
58 |
case DRIZZLE_TYPE_LONG: |
1
by brian
clean slate |
59 |
length= 4; |
60 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
61 |
case DRIZZLE_TYPE_LONGLONG: |
1
by brian
clean slate |
62 |
length= 8; |
63 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
64 |
case DRIZZLE_TYPE_NULL: |
1
by brian
clean slate |
65 |
length= 0; |
66 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
67 |
case DRIZZLE_TYPE_NEWDATE: |
68 |
length= 3; |
|
69 |
break; |
|
70 |
case DRIZZLE_TYPE_TIME: |
|
71 |
length= 3; |
|
72 |
break; |
|
73 |
case DRIZZLE_TYPE_TIMESTAMP: |
|
1
by brian
clean slate |
74 |
length= 4; |
75 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
76 |
case DRIZZLE_TYPE_DATETIME: |
1
by brian
clean slate |
77 |
length= 8; |
78 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
79 |
case DRIZZLE_TYPE_VARCHAR: |
1
by brian
clean slate |
80 |
{
|
81 |
length= m_field_metadata[col] > 255 ? 2 : 1; // c&p of Field_varstring::data_length() |
|
51.1.44
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
82 |
assert(uint2korr(master_data) > 0); |
205
by Brian Aker
uint32 -> uin32_t |
83 |
length+= length == 1 ? (uint32_t) *master_data : uint2korr(master_data); |
1
by brian
clean slate |
84 |
break; |
85 |
}
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
86 |
case DRIZZLE_TYPE_BLOB: |
1
by brian
clean slate |
87 |
{
|
113
by Brian Aker
First pass on removing blob internals. |
88 |
length= uint4korr(master_data); |
1
by brian
clean slate |
89 |
length+= m_field_metadata[col]; |
90 |
break; |
|
91 |
}
|
|
92 |
default: |
|
205
by Brian Aker
uint32 -> uin32_t |
93 |
length= ~(uint32_t) 0; |
1
by brian
clean slate |
94 |
}
|
95 |
return length; |
|
96 |
}
|
|
97 |
||
98 |
/*
|
|
99 |
Is the definition compatible with a table?
|
|
100 |
||
101 |
*/
|
|
102 |
int
|
|
103 |
table_def::compatible_with(Relay_log_info const *rli_arg, TABLE *table) |
|
104 |
const
|
|
105 |
{
|
|
106 |
/*
|
|
107 |
We only check the initial columns for the tables.
|
|
108 |
*/
|
|
109 |
uint const cols_to_check= min(table->s->fields, size()); |
|
110 |
int error= 0; |
|
111 |
Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg); |
|
112 |
||
113 |
TABLE_SHARE const *const tsh= table->s; |
|
114 |
||
115 |
for (uint col= 0 ; col < cols_to_check ; ++col) |
|
116 |
{
|
|
117 |
if (table->field[col]->type() != type(col)) |
|
118 |
{
|
|
51.1.44
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
119 |
assert(col < size() && col < tsh->fields); |
120 |
assert(tsh->db.str && tsh->table_name.str); |
|
1
by brian
clean slate |
121 |
error= 1; |
122 |
char buf[256]; |
|
261.3.4
by Monty Taylor
Added three more files worth of stuff. |
123 |
snprintf(buf, sizeof(buf), _("Column %d type mismatch - " |
124 |
"received type %d, %s.%s has type %d"), |
|
77.1.18
by Monty Taylor
Removed my_vsnprintf and my_snprintf. |
125 |
col, type(col), tsh->db.str, tsh->table_name.str, |
126 |
table->field[col]->type()); |
|
1
by brian
clean slate |
127 |
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF, |
128 |
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf); |
|
129 |
}
|
|
130 |
/*
|
|
131 |
Check the slave's field size against that of the master.
|
|
132 |
*/
|
|
133 |
if (!error && |
|
134 |
!table->field[col]->compatible_field_size(field_metadata(col))) |
|
135 |
{
|
|
136 |
error= 1; |
|
137 |
char buf[256]; |
|
261.3.4
by Monty Taylor
Added three more files worth of stuff. |
138 |
snprintf(buf, sizeof(buf), _("Column %d size mismatch - " |
77.1.18
by Monty Taylor
Removed my_vsnprintf and my_snprintf. |
139 |
"master has size %d, %s.%s on slave has size %d."
|
140 |
" Master's column size should be <= the slave's "
|
|
261.3.4
by Monty Taylor
Added three more files worth of stuff. |
141 |
"column size."), col, |
77.1.18
by Monty Taylor
Removed my_vsnprintf and my_snprintf. |
142 |
table->field[col]->pack_length_from_metadata( |
143 |
m_field_metadata[col]), |
|
144 |
tsh->db.str, tsh->table_name.str, |
|
145 |
table->field[col]->row_pack_length()); |
|
1
by brian
clean slate |
146 |
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF, |
147 |
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf); |
|
148 |
}
|
|
149 |
}
|
|
150 |
||
151 |
return error; |
|
152 |
}
|