1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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 */
20
16
#ifndef RPL_UTILITY_H
21
17
#define RPL_UTILITY_H
23
#include <drizzled/server_includes.h>
20
#error "Don't include this C++ header file from a non-C++ file!"
23
#include "mysql_priv.h"
25
25
class Relay_log_info;
58
58
@param metadata_size Size of the field_metadata array
59
59
@param null_bitmap The bitmap of fields that can be null
61
table_def(field_type *types, uint32_t size, unsigned char *field_metadata,
62
int metadata_size, unsigned char *null_bitmap)
61
table_def(field_type *types, ulong size, uchar *field_metadata,
62
int metadata_size, uchar *null_bitmap)
63
63
: m_size(size), m_type(0), m_field_metadata_size(metadata_size),
64
64
m_field_metadata(0), m_null_bits(0), m_memory(NULL)
66
m_memory= (unsigned char *)my_multi_malloc(MYF(MY_WME),
66
m_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
69
size * sizeof(uint16_t),
69
size * sizeof(uint16),
70
70
&m_null_bits, (size + 7) / 8,
73
memset(m_field_metadata, 0, size * sizeof(uint16_t));
73
bzero(m_field_metadata, size * sizeof(uint16));
76
76
memcpy(m_type, types, size);
89
89
for (unsigned int i= 0; i < m_size; i++)
91
91
switch (m_type[i]) {
92
case DRIZZLE_TYPE_BLOB:
93
case DRIZZLE_TYPE_DOUBLE:
92
case MYSQL_TYPE_TINY_BLOB:
94
case MYSQL_TYPE_MEDIUM_BLOB:
95
case MYSQL_TYPE_LONG_BLOB:
96
case MYSQL_TYPE_DOUBLE:
97
case MYSQL_TYPE_FLOAT:
96
100
These types store a single byte.
102
case DRIZZLE_TYPE_ENUM:
107
case MYSQL_TYPE_ENUM:
108
case MYSQL_TYPE_STRING:
104
uint16_t x= field_metadata[index++] << 8U; // real_type
110
uint16 x= field_metadata[index++] << 8U; // real_type
105
111
x+= field_metadata[index++]; // pack or field length
106
112
m_field_metadata[i]= x;
109
case DRIZZLE_TYPE_VARCHAR:
117
uint16 x= field_metadata[index++];
118
x = x + (field_metadata[index++] << 8U);
119
m_field_metadata[i]= x;
122
case MYSQL_TYPE_VARCHAR:
112
125
These types store two bytes.
116
129
index= index + 2;
119
case DRIZZLE_TYPE_NEWDECIMAL:
132
case MYSQL_TYPE_NEWDECIMAL:
121
uint16_t x= field_metadata[index++] << 8U; // precision
134
uint16 x= field_metadata[index++] << 8U; // precision
122
135
x+= field_metadata[index++]; // decimals
123
136
m_field_metadata[i]= x;
156
171
<code>index</code>. Currently, only the type identifier is
159
field_type type(uint32_t index) const
174
field_type type(ulong index) const
161
assert(index < m_size);
176
DBUG_ASSERT(index < m_size);
162
177
return m_type[index];
175
190
corresponding fields to properly extract the data from the binary log
176
191
in the event that the master's field is smaller than the slave.
178
uint16_t field_metadata(uint32_t index) const
193
uint16 field_metadata(uint index) const
180
assert(index < m_size);
195
DBUG_ASSERT(index < m_size);
181
196
if (m_field_metadata_size)
182
197
return m_field_metadata[index];
188
203
This function returns whether the field on the master can be null.
189
204
This value is derived from field->maybe_null().
191
bool maybe_null(uint32_t index) const
206
my_bool maybe_null(uint index) const
193
assert(index < m_size);
208
DBUG_ASSERT(index < m_size);
194
209
return ((m_null_bits[(index / 8)] &
195
210
(1 << (index % 8))) == (1 << (index %8)));
202
217
WL#3915) or needs to advance the pointer for the fields in the raw
203
218
data from the master to a specific column.
205
uint32_t calc_field_size(uint32_t col, unsigned char *master_data) const;
220
uint32 calc_field_size(uint col, uchar *master_data) const;
208
223
Decide if the table definition is compatible with a table.
221
236
@retval 1 if the table definition is not compatible with @c table
222
237
@retval 0 if the table definition is compatible with @c table
224
int compatible_with(Relay_log_info const *rli, Table *table) const;
239
int compatible_with(Relay_log_info const *rli, TABLE *table) const;
227
uint32_t m_size; // Number of elements in the types array
242
ulong m_size; // Number of elements in the types array
228
243
field_type *m_type; // Array of type descriptors
229
uint32_t m_field_metadata_size;
230
uint16_t *m_field_metadata;
231
unsigned char *m_null_bits;
232
unsigned char *m_memory;
244
uint m_field_metadata_size;
245
uint16 *m_field_metadata;
236
251
Extend the normal table list with a few new fields needed by the
237
252
slave thread, but nowhere else.
254
struct RPL_TABLE_LIST
242
257
bool m_tabledef_valid;
243
258
table_def m_tabledef;
293
One test in mysqldump.test has 330 columns!
294
So have a sufficient buffer and check its limit anyway.
296
#define DBUG_PRINT_BITSET(N,FRM,BS) \
298
char buf[MAX_FIELDS+1]; \
300
for (i = 0 ; i < (BS)->n_bits && i < MAX_FIELDS ; ++i) \
301
buf[i] = bitmap_is_set((BS), i) ? '1' : '0'; \
303
DBUG_PRINT((N), ((FRM), buf)); \
277
306
#endif /* RPL_UTILITY_H */