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" |
|
549
by Monty Taylor
Took gettext.h out of header files. |
19 |
#include <drizzled/error.h> |
20 |
#include <drizzled/gettext.h> |
|
1
by brian
clean slate |
21 |
|
22 |
/*********************************************************************
|
|
23 |
* table_def member definitions *
|
|
24 |
*********************************************************************/
|
|
25 |
||
26 |
/*
|
|
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.
|
|
29 |
*/
|
|
482
by Brian Aker
Remove uint. |
30 |
uint32_t table_def::calc_field_size(uint32_t col, unsigned char *master_data) const |
1
by brian
clean slate |
31 |
{
|
205
by Brian Aker
uint32 -> uin32_t |
32 |
uint32_t length= 0; |
1
by brian
clean slate |
33 |
|
34 |
switch (type(col)) { |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
35 |
case DRIZZLE_TYPE_NEWDECIMAL: |
1
by brian
clean slate |
36 |
length= my_decimal_get_binary_size(m_field_metadata[col] >> 8, |
37 |
m_field_metadata[col] & 0xff); |
|
38 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
39 |
case DRIZZLE_TYPE_DOUBLE: |
1
by brian
clean slate |
40 |
length= m_field_metadata[col]; |
41 |
break; |
|
42 |
/*
|
|
43 |
The cases for SET and ENUM are include for completeness, however
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
44 |
both are mapped to type DRIZZLE_TYPE_STRING and their real types
|
1
by brian
clean slate |
45 |
are encoded in the field metadata.
|
46 |
*/
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
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_LONG: |
1
by brian
clean slate |
53 |
length= 4; |
54 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
55 |
case DRIZZLE_TYPE_LONGLONG: |
1
by brian
clean slate |
56 |
length= 8; |
57 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
58 |
case DRIZZLE_TYPE_NULL: |
1
by brian
clean slate |
59 |
length= 0; |
60 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
61 |
case DRIZZLE_TYPE_NEWDATE: |
62 |
length= 3; |
|
63 |
break; |
|
64 |
case DRIZZLE_TYPE_TIME: |
|
65 |
length= 3; |
|
66 |
break; |
|
67 |
case DRIZZLE_TYPE_TIMESTAMP: |
|
1
by brian
clean slate |
68 |
length= 4; |
69 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
70 |
case DRIZZLE_TYPE_DATETIME: |
1
by brian
clean slate |
71 |
length= 8; |
72 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
73 |
case DRIZZLE_TYPE_VARCHAR: |
1
by brian
clean slate |
74 |
{
|
75 |
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 |
76 |
assert(uint2korr(master_data) > 0); |
205
by Brian Aker
uint32 -> uin32_t |
77 |
length+= length == 1 ? (uint32_t) *master_data : uint2korr(master_data); |
1
by brian
clean slate |
78 |
break; |
79 |
}
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
80 |
case DRIZZLE_TYPE_BLOB: |
1
by brian
clean slate |
81 |
{
|
113
by Brian Aker
First pass on removing blob internals. |
82 |
length= uint4korr(master_data); |
1
by brian
clean slate |
83 |
length+= m_field_metadata[col]; |
84 |
break; |
|
85 |
}
|
|
86 |
default: |
|
205
by Brian Aker
uint32 -> uin32_t |
87 |
length= ~(uint32_t) 0; |
1
by brian
clean slate |
88 |
}
|
89 |
return length; |
|
90 |
}
|
|
91 |
||
92 |
/*
|
|
93 |
Is the definition compatible with a table?
|
|
94 |
||
95 |
*/
|
|
96 |
int
|
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
97 |
table_def::compatible_with(Relay_log_info const *rli_arg, Table *table) |
1
by brian
clean slate |
98 |
const
|
99 |
{
|
|
100 |
/*
|
|
101 |
We only check the initial columns for the tables.
|
|
102 |
*/
|
|
482
by Brian Aker
Remove uint. |
103 |
uint32_t const cols_to_check= cmin(table->s->fields, size()); |
1
by brian
clean slate |
104 |
int error= 0; |
105 |
Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg); |
|
106 |
||
107 |
TABLE_SHARE const *const tsh= table->s; |
|
108 |
||
482
by Brian Aker
Remove uint. |
109 |
for (uint32_t col= 0 ; col < cols_to_check ; ++col) |
1
by brian
clean slate |
110 |
{
|
111 |
if (table->field[col]->type() != type(col)) |
|
112 |
{
|
|
51.1.44
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
113 |
assert(col < size() && col < tsh->fields); |
114 |
assert(tsh->db.str && tsh->table_name.str); |
|
1
by brian
clean slate |
115 |
error= 1; |
116 |
char buf[256]; |
|
261.3.4
by Monty Taylor
Added three more files worth of stuff. |
117 |
snprintf(buf, sizeof(buf), _("Column %d type mismatch - " |
118 |
"received type %d, %s.%s has type %d"), |
|
77.1.18
by Monty Taylor
Removed my_vsnprintf and my_snprintf. |
119 |
col, type(col), tsh->db.str, tsh->table_name.str, |
120 |
table->field[col]->type()); |
|
1
by brian
clean slate |
121 |
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF, |
122 |
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf); |
|
123 |
}
|
|
124 |
/*
|
|
125 |
Check the slave's field size against that of the master.
|
|
126 |
*/
|
|
127 |
if (!error && |
|
128 |
!table->field[col]->compatible_field_size(field_metadata(col))) |
|
129 |
{
|
|
130 |
error= 1; |
|
131 |
char buf[256]; |
|
261.3.4
by Monty Taylor
Added three more files worth of stuff. |
132 |
snprintf(buf, sizeof(buf), _("Column %d size mismatch - " |
77.1.18
by Monty Taylor
Removed my_vsnprintf and my_snprintf. |
133 |
"master has size %d, %s.%s on slave has size %d."
|
134 |
" Master's column size should be <= the slave's "
|
|
261.3.4
by Monty Taylor
Added three more files worth of stuff. |
135 |
"column size."), col, |
77.1.18
by Monty Taylor
Removed my_vsnprintf and my_snprintf. |
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()); |
|
1
by brian
clean slate |
140 |
rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF, |
141 |
ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf); |
|
142 |
}
|
|
143 |
}
|
|
144 |
||
145 |
return error; |
|
146 |
}
|