~mdcallag/+junk/5.1-map

« back to all changes in this revision

Viewing changes to sql/rpl_record_old.cc

  • Committer: msvensson at pilot
  • Date: 2007-04-24 09:11:45 UTC
  • mfrom: (2469.1.106)
  • Revision ID: sp1r-msvensson@pilot.blaudden-20070424091145-10463
Merge pilot.blaudden:/home/msvensson/mysql/my51-m-mysql_upgrade
into  pilot.blaudden:/home/msvensson/mysql/mysql-5.1-maint

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "mysql_priv.h"
 
3
#include "rpl_record_old.h"
 
4
 
 
5
my_size_t
 
6
pack_row_old(TABLE *table, MY_BITMAP const* cols,
 
7
             byte *row_data, const byte *record)
 
8
{
 
9
  Field **p_field= table->field, *field;
 
10
  int n_null_bytes= table->s->null_bytes;
 
11
  byte *ptr;
 
12
  uint i;
 
13
  my_ptrdiff_t const rec_offset= record - table->record[0];
 
14
  my_ptrdiff_t const def_offset= table->s->default_values - table->record[0];
 
15
  memcpy(row_data, record, n_null_bytes);
 
16
  ptr= row_data+n_null_bytes;
 
17
 
 
18
  for (i= 0 ; (field= *p_field) ; i++, p_field++)
 
19
  {
 
20
    if (bitmap_is_set(cols,i))
 
21
    {
 
22
      my_ptrdiff_t const offset=
 
23
        field->is_null(rec_offset) ? def_offset : rec_offset;
 
24
      field->move_field_offset(offset);
 
25
      ptr= (byte*)field->pack((char *) ptr, field->ptr);
 
26
      field->move_field_offset(-offset);
 
27
    }
 
28
  }
 
29
  return (static_cast<my_size_t>(ptr - row_data));
 
30
}
 
31
 
 
32
 
 
33
/*
 
34
  Unpack a row into a record.
 
35
 
 
36
  SYNOPSIS
 
37
    unpack_row()
 
38
    rli     Relay log info
 
39
    table   Table to unpack into
 
40
    colcnt  Number of columns to read from record
 
41
    record  Record where the data should be unpacked
 
42
    row     Packed row data
 
43
    cols    Pointer to columns data to fill in
 
44
    row_end Pointer to variable that will hold the value of the
 
45
            one-after-end position for the row
 
46
    master_reclength
 
47
            Pointer to variable that will be set to the length of the
 
48
            record on the master side
 
49
    rw_set  Pointer to bitmap that holds either the read_set or the
 
50
            write_set of the table
 
51
 
 
52
  DESCRIPTION
 
53
 
 
54
      The row is assumed to only consist of the fields for which the
 
55
      bitset represented by 'arr' and 'bits'; the other parts of the
 
56
      record are left alone.
 
57
 
 
58
      At most 'colcnt' columns are read: if the table is larger than
 
59
      that, the remaining fields are not filled in.
 
60
 
 
61
  RETURN VALUE
 
62
 
 
63
      Error code, or zero if no error. The following error codes can
 
64
      be returned:
 
65
 
 
66
      ER_NO_DEFAULT_FOR_FIELD
 
67
        Returned if one of the fields existing on the slave but not on
 
68
        the master does not have a default value (and isn't nullable)
 
69
 */
 
70
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
 
71
int
 
72
unpack_row_old(RELAY_LOG_INFO *rli,
 
73
               TABLE *table, uint const colcnt, byte *record,
 
74
               char const *row, MY_BITMAP const *cols,
 
75
               char const **row_end, ulong *master_reclength,
 
76
               MY_BITMAP* const rw_set, Log_event_type const event_type)
 
77
{
 
78
  DBUG_ASSERT(record && row);
 
79
  my_ptrdiff_t const offset= record - (byte*) table->record[0];
 
80
  my_size_t master_null_bytes= table->s->null_bytes;
 
81
 
 
82
  if (colcnt != table->s->fields)
 
83
  {
 
84
    Field **fptr= &table->field[colcnt-1];
 
85
    do
 
86
      master_null_bytes= (*fptr)->last_null_byte();
 
87
    while (master_null_bytes == Field::LAST_NULL_BYTE_UNDEF &&
 
88
           fptr-- > table->field);
 
89
 
 
90
    /*
 
91
      If master_null_bytes is LAST_NULL_BYTE_UNDEF (0) at this time,
 
92
      there were no nullable fields nor BIT fields at all in the
 
93
      columns that are common to the master and the slave. In that
 
94
      case, there is only one null byte holding the X bit.
 
95
 
 
96
      OBSERVE! There might still be nullable columns following the
 
97
      common columns, so table->s->null_bytes might be greater than 1.
 
98
     */
 
99
    if (master_null_bytes == Field::LAST_NULL_BYTE_UNDEF)
 
100
      master_null_bytes= 1;
 
101
  }
 
102
 
 
103
  DBUG_ASSERT(master_null_bytes <= table->s->null_bytes);
 
104
  memcpy(record, row, master_null_bytes);            // [1]
 
105
  int error= 0;
 
106
 
 
107
  bitmap_set_all(rw_set);
 
108
 
 
109
  Field **const begin_ptr = table->field;
 
110
  Field **field_ptr;
 
111
  char const *ptr= row + master_null_bytes;
 
112
  Field **const end_ptr= begin_ptr + colcnt;
 
113
  for (field_ptr= begin_ptr ; field_ptr < end_ptr ; ++field_ptr)
 
114
  {
 
115
    Field *const f= *field_ptr;
 
116
 
 
117
    if (bitmap_is_set(cols, field_ptr -  begin_ptr))
 
118
    {
 
119
      f->move_field_offset(offset);
 
120
      ptr= f->unpack(f->ptr, ptr);
 
121
      f->move_field_offset(-offset);
 
122
      /* Field...::unpack() cannot return 0 */
 
123
      DBUG_ASSERT(ptr != NULL);
 
124
    }
 
125
    else
 
126
      bitmap_clear_bit(rw_set, field_ptr - begin_ptr);
 
127
  }
 
128
 
 
129
  *row_end = ptr;
 
130
  if (master_reclength)
 
131
  {
 
132
    if (*field_ptr)
 
133
      *master_reclength = (*field_ptr)->ptr - (char*) table->record[0];
 
134
    else
 
135
      *master_reclength = table->s->reclength;
 
136
  }
 
137
 
 
138
  /*
 
139
    Set properties for remaining columns, if there are any. We let the
 
140
    corresponding bit in the write_set be set, to write the value if
 
141
    it was not there already. We iterate over all remaining columns,
 
142
    even if there were an error, to get as many error messages as
 
143
    possible.  We are still able to return a pointer to the next row,
 
144
    so redo that.
 
145
 
 
146
    This generation of error messages is only relevant when inserting
 
147
    new rows.
 
148
   */
 
149
  for ( ; *field_ptr ; ++field_ptr)
 
150
  {
 
151
    uint32 const mask= NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG;
 
152
 
 
153
    DBUG_PRINT("debug", ("flags = 0x%x, mask = 0x%x, flags & mask = 0x%x",
 
154
                         (*field_ptr)->flags, mask,
 
155
                         (*field_ptr)->flags & mask));
 
156
 
 
157
    if (event_type == WRITE_ROWS_EVENT &&
 
158
        ((*field_ptr)->flags & mask) == mask)
 
159
    {
 
160
      slave_print_msg(ERROR_LEVEL, rli, ER_NO_DEFAULT_FOR_FIELD,
 
161
                      "Field `%s` of table `%s`.`%s` "
 
162
                      "has no default value and cannot be NULL",
 
163
                      (*field_ptr)->field_name, table->s->db.str,
 
164
                      table->s->table_name.str);
 
165
      error = ER_NO_DEFAULT_FOR_FIELD;
 
166
    }
 
167
    else
 
168
      (*field_ptr)->set_default();
 
169
  }
 
170
 
 
171
  return error;
 
172
}
 
173
#endif