~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/rpl_utility.cc

  • Committer: Monty Taylor
  • Date: 2009-01-29 19:04:39 UTC
  • mto: (779.3.29 devel)
  • mto: This revision was merged to the branch mainline in revision 823.
  • Revision ID: mordred@inaugust.com-20090129190439-vfr95s6gaudjacm7
Add timegm which is missing on Solaris.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
16
 
#include <drizzled/server_includes.h>
17
 
#include "rpl_utility.h"
18
 
#include "rpl_rli.h"
19
 
#include <drizzled/drizzled_error_messages.h>
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
 
*/
29
 
uint32_t table_def::calc_field_size(uint col, uchar *master_data) const
30
 
{
31
 
  uint32_t length= 0;
32
 
 
33
 
  switch (type(col)) {
34
 
  case DRIZZLE_TYPE_NEWDECIMAL:
35
 
    length= my_decimal_get_binary_size(m_field_metadata[col] >> 8, 
36
 
                                       m_field_metadata[col] & 0xff);
37
 
    break;
38
 
  case DRIZZLE_TYPE_DOUBLE:
39
 
    length= m_field_metadata[col];
40
 
    break;
41
 
  /*
42
 
    The cases for SET and ENUM are include for completeness, however
43
 
    both are mapped to type DRIZZLE_TYPE_STRING and their real types
44
 
    are encoded in the field metadata.
45
 
  */
46
 
  case DRIZZLE_TYPE_ENUM:
47
 
  {
48
 
    length= m_field_metadata[col] & 0x00ff;
49
 
    break;
50
 
  }
51
 
  case DRIZZLE_TYPE_TINY:
52
 
    length= 1;
53
 
    break;
54
 
  case DRIZZLE_TYPE_LONG:
55
 
    length= 4;
56
 
    break;
57
 
  case DRIZZLE_TYPE_LONGLONG:
58
 
    length= 8;
59
 
    break;
60
 
  case DRIZZLE_TYPE_NULL:
61
 
    length= 0;
62
 
    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:
70
 
    length= 4;
71
 
    break;
72
 
  case DRIZZLE_TYPE_DATETIME:
73
 
    length= 8;
74
 
    break;
75
 
  case DRIZZLE_TYPE_VARCHAR:
76
 
  {
77
 
    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);
80
 
    break;
81
 
  }
82
 
  case DRIZZLE_TYPE_BLOB:
83
 
  {
84
 
    length= uint4korr(master_data);
85
 
    length+= m_field_metadata[col];
86
 
    break;
87
 
  }
88
 
  default:
89
 
    length= ~(uint32_t) 0;
90
 
  }
91
 
  return length;
92
 
}
93
 
 
94
 
/*
95
 
  Is the definition compatible with a table?
96
 
 
97
 
*/
98
 
int
99
 
table_def::compatible_with(Relay_log_info const *rli_arg, Table *table)
100
 
  const
101
 
{
102
 
  /*
103
 
    We only check the initial columns for the tables.
104
 
  */
105
 
  uint const cols_to_check= cmin(table->s->fields, size());
106
 
  int error= 0;
107
 
  Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg);
108
 
 
109
 
  TABLE_SHARE const *const tsh= table->s;
110
 
 
111
 
  for (uint col= 0 ; col < cols_to_check ; ++col)
112
 
  {
113
 
    if (table->field[col]->type() != type(col))
114
 
    {
115
 
      assert(col < size() && col < tsh->fields);
116
 
      assert(tsh->db.str && tsh->table_name.str);
117
 
      error= 1;
118
 
      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());
123
 
      rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
124
 
                  ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
125
 
    }
126
 
    /*
127
 
      Check the slave's field size against that of the master.
128
 
    */
129
 
    if (!error && 
130
 
        !table->field[col]->compatible_field_size(field_metadata(col)))
131
 
    {
132
 
      error= 1;
133
 
      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());
142
 
      rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
143
 
                  ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
144
 
    }
145
 
  }
146
 
 
147
 
  return error;
148
 
}