~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/rpl_utility.cc

  • Committer: Brian Aker
  • Date: 2008-07-07 14:25:25 UTC
  • mto: (77.1.25 codestyle)
  • mto: This revision was merged to the branch mainline in revision 82.
  • Revision ID: brian@tangent.org-20080707142525-xzy2nl3ie2ebwfln
LL() cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
 
#include <drizzled/server_includes.h>
17
16
#include "rpl_utility.h"
18
17
#include "rpl_rli.h"
19
 
#include <drizzled/drizzled_error_messages.h>
20
18
 
21
19
/*********************************************************************
22
20
 *                   table_def member definitions                    *
26
24
  This function returns the field size in raw bytes based on the type
27
25
  and the encoded field data from the master's raw data.
28
26
*/
29
 
uint32_t table_def::calc_field_size(uint32_t col, unsigned char *master_data) const
 
27
uint32 table_def::calc_field_size(uint col, uchar *master_data) const
30
28
{
31
 
  uint32_t length= 0;
 
29
  uint32 length= 0;
32
30
 
33
31
  switch (type(col)) {
34
 
  case DRIZZLE_TYPE_NEWDECIMAL:
 
32
  case MYSQL_TYPE_NEWDECIMAL:
35
33
    length= my_decimal_get_binary_size(m_field_metadata[col] >> 8, 
36
34
                                       m_field_metadata[col] & 0xff);
37
35
    break;
38
 
  case DRIZZLE_TYPE_DOUBLE:
 
36
  case MYSQL_TYPE_FLOAT:
 
37
  case MYSQL_TYPE_DOUBLE:
39
38
    length= m_field_metadata[col];
40
39
    break;
41
40
  /*
42
41
    The cases for SET and ENUM are include for completeness, however
43
 
    both are mapped to type DRIZZLE_TYPE_STRING and their real types
 
42
    both are mapped to type MYSQL_TYPE_STRING and their real types
44
43
    are encoded in the field metadata.
45
44
  */
46
 
  case DRIZZLE_TYPE_ENUM:
 
45
  case MYSQL_TYPE_SET:
 
46
  case MYSQL_TYPE_ENUM:
 
47
  case MYSQL_TYPE_STRING:
47
48
  {
48
 
    length= m_field_metadata[col] & 0x00ff;
 
49
    uchar type= m_field_metadata[col] >> 8U;
 
50
    if ((type == MYSQL_TYPE_SET) || (type == MYSQL_TYPE_ENUM))
 
51
      length= m_field_metadata[col] & 0x00ff;
 
52
    else
 
53
    {
 
54
      /*
 
55
        We are reading the actual size from the master_data record
 
56
        because this field has the actual lengh stored in the first
 
57
        byte.
 
58
      */
 
59
      length= (uint) *master_data + 1;
 
60
      DBUG_ASSERT(length != 0);
 
61
    }
49
62
    break;
50
63
  }
51
 
  case DRIZZLE_TYPE_TINY:
 
64
  case MYSQL_TYPE_YEAR:
 
65
  case MYSQL_TYPE_TINY:
52
66
    length= 1;
53
67
    break;
54
 
  case DRIZZLE_TYPE_LONG:
 
68
  case MYSQL_TYPE_SHORT:
 
69
    length= 2;
 
70
    break;
 
71
  case MYSQL_TYPE_LONG:
55
72
    length= 4;
56
73
    break;
57
 
  case DRIZZLE_TYPE_LONGLONG:
 
74
  case MYSQL_TYPE_LONGLONG:
58
75
    length= 8;
59
76
    break;
60
 
  case DRIZZLE_TYPE_NULL:
 
77
  case MYSQL_TYPE_NULL:
61
78
    length= 0;
62
79
    break;
63
 
  case DRIZZLE_TYPE_NEWDATE:
64
 
    length= 3;
65
 
    break;
66
 
  case DRIZZLE_TYPE_TIME:
67
 
    length= 3;
68
 
    break;
69
 
  case DRIZZLE_TYPE_TIMESTAMP:
 
80
  case MYSQL_TYPE_NEWDATE:
 
81
    length= 3;
 
82
    break;
 
83
  case MYSQL_TYPE_DATE:
 
84
  case MYSQL_TYPE_TIME:
 
85
    length= 3;
 
86
    break;
 
87
  case MYSQL_TYPE_TIMESTAMP:
70
88
    length= 4;
71
89
    break;
72
 
  case DRIZZLE_TYPE_DATETIME:
 
90
  case MYSQL_TYPE_DATETIME:
73
91
    length= 8;
74
92
    break;
75
 
  case DRIZZLE_TYPE_VARCHAR:
 
93
  case MYSQL_TYPE_VARCHAR:
76
94
  {
77
95
    length= m_field_metadata[col] > 255 ? 2 : 1; // c&p of Field_varstring::data_length()
78
 
    assert(uint2korr(master_data) > 0);
79
 
    length+= length == 1 ? (uint32_t) *master_data : uint2korr(master_data);
 
96
    DBUG_ASSERT(uint2korr(master_data) > 0);
 
97
    length+= length == 1 ? (uint32) *master_data : uint2korr(master_data);
80
98
    break;
81
99
  }
82
 
  case DRIZZLE_TYPE_BLOB:
 
100
  case MYSQL_TYPE_TINY_BLOB:
 
101
  case MYSQL_TYPE_MEDIUM_BLOB:
 
102
  case MYSQL_TYPE_LONG_BLOB:
 
103
  case MYSQL_TYPE_BLOB:
83
104
  {
84
 
    length= uint4korr(master_data);
 
105
    /*
 
106
      Compute the length of the data. We cannot use get_length() here
 
107
      since it is dependent on the specific table (and also checks the
 
108
      packlength using the internal 'table' pointer) and replication
 
109
      is using a fixed format for storing data in the binlog.
 
110
    */
 
111
    switch (m_field_metadata[col]) {
 
112
    case 1:
 
113
      length= *master_data;
 
114
      break;
 
115
    case 2:
 
116
      length= uint2korr(master_data);
 
117
      break;
 
118
    case 3:
 
119
      length= uint3korr(master_data);
 
120
      break;
 
121
    case 4:
 
122
      length= uint4korr(master_data);
 
123
      break;
 
124
    default:
 
125
      DBUG_ASSERT(0);           // Should not come here
 
126
      break;
 
127
    }
 
128
 
85
129
    length+= m_field_metadata[col];
86
130
    break;
87
131
  }
88
132
  default:
89
 
    length= ~(uint32_t) 0;
 
133
    length= ~(uint32) 0;
90
134
  }
91
135
  return length;
92
136
}
96
140
 
97
141
*/
98
142
int
99
 
table_def::compatible_with(Relay_log_info const *rli_arg, Table *table)
 
143
table_def::compatible_with(Relay_log_info const *rli_arg, TABLE *table)
100
144
  const
101
145
{
102
146
  /*
103
147
    We only check the initial columns for the tables.
104
148
  */
105
 
  uint32_t const cols_to_check= cmin(table->s->fields, size());
 
149
  uint const cols_to_check= min(table->s->fields, size());
106
150
  int error= 0;
107
151
  Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg);
108
152
 
109
153
  TABLE_SHARE const *const tsh= table->s;
110
154
 
111
 
  for (uint32_t col= 0 ; col < cols_to_check ; ++col)
 
155
  for (uint col= 0 ; col < cols_to_check ; ++col)
112
156
  {
113
157
    if (table->field[col]->type() != type(col))
114
158
    {
115
 
      assert(col < size() && col < tsh->fields);
116
 
      assert(tsh->db.str && tsh->table_name.str);
 
159
      DBUG_ASSERT(col < size() && col < tsh->fields);
 
160
      DBUG_ASSERT(tsh->db.str && tsh->table_name.str);
117
161
      error= 1;
118
162
      char buf[256];
119
 
      snprintf(buf, sizeof(buf), _("Column %d type mismatch - "
120
 
                "received type %d, %s.%s has type %d"),
121
 
                col, type(col), tsh->db.str, tsh->table_name.str,
122
 
                table->field[col]->type());
 
163
      my_snprintf(buf, sizeof(buf), "Column %d type mismatch - "
 
164
                  "received type %d, %s.%s has type %d",
 
165
                  col, type(col), tsh->db.str, tsh->table_name.str,
 
166
                  table->field[col]->type());
123
167
      rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
124
168
                  ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
125
169
    }
131
175
    {
132
176
      error= 1;
133
177
      char buf[256];
134
 
      snprintf(buf, sizeof(buf), _("Column %d size mismatch - "
135
 
               "master has size %d, %s.%s on slave has size %d."
136
 
               " Master's column size should be <= the slave's "
137
 
               "column size."), col,
138
 
               table->field[col]->pack_length_from_metadata(
139
 
                                    m_field_metadata[col]),
140
 
               tsh->db.str, tsh->table_name.str, 
141
 
               table->field[col]->row_pack_length());
 
178
      my_snprintf(buf, sizeof(buf), "Column %d size mismatch - "
 
179
                  "master has size %d, %s.%s on slave has size %d."
 
180
                  " Master's column size should be <= the slave's "
 
181
                  "column size.", col,
 
182
                  table->field[col]->pack_length_from_metadata(
 
183
                                       m_field_metadata[col]),
 
184
                  tsh->db.str, tsh->table_name.str, 
 
185
                  table->field[col]->row_pack_length());
142
186
      rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
143
187
                  ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
144
188
    }