~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_binlog.cc

Removed SCCS references.

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>
 
16
#include "mysql_priv.h"
17
17
#include "rpl_rli.h"
18
 
#include <mysys/base64.h>
 
18
#include "base64.h"
19
19
 
20
20
/**
21
21
  Execute a BINLOG statement
30
30
 
31
31
void mysql_client_binlog_statement(THD* thd)
32
32
{
 
33
  DBUG_ENTER("mysql_client_binlog_statement");
 
34
  DBUG_PRINT("info",("binlog base64: '%*s'",
 
35
                     (int) (thd->lex->comment.length < 2048 ?
 
36
                            thd->lex->comment.length : 2048),
 
37
                     thd->lex->comment.str));
 
38
 
33
39
  size_t coded_len= thd->lex->comment.length + 1;
34
40
  size_t decoded_len= base64_needed_decoded_length(coded_len);
35
 
  assert(coded_len > 0);
 
41
  DBUG_ASSERT(coded_len > 0);
36
42
 
37
43
  /*
38
44
    Allocation
43
49
    one here.  In this case, the first event we read must be a
44
50
    Format_description_event.
45
51
  */
46
 
  bool have_fd_event= true;
 
52
  my_bool have_fd_event= TRUE;
47
53
  if (!thd->rli_fake)
48
54
  {
49
55
    thd->rli_fake= new Relay_log_info;
50
56
#ifdef HAVE_purify
51
 
    thd->rli_fake->is_fake= true;
 
57
    thd->rli_fake->is_fake= TRUE;
52
58
#endif
53
 
    have_fd_event= false;
 
59
    have_fd_event= FALSE;
54
60
  }
55
61
  if (thd->rli_fake && !thd->rli_fake->relay_log.description_event_for_exec)
56
62
  {
57
63
    thd->rli_fake->relay_log.description_event_for_exec=
58
64
      new Format_description_log_event(4);
59
 
    have_fd_event= false;
 
65
    have_fd_event= FALSE;
60
66
  }
61
67
 
62
68
  const char *error= 0;
75
81
  }
76
82
 
77
83
  thd->rli_fake->sql_thd= thd;
78
 
  thd->rli_fake->no_storage= true;
 
84
  thd->rli_fake->no_storage= TRUE;
79
85
 
80
86
  for (char const *strptr= thd->lex->comment.str ;
81
87
       strptr < thd->lex->comment.str + thd->lex->comment.length ; )
83
89
    char const *endptr= 0;
84
90
    int bytes_decoded= base64_decode(strptr, coded_len, buf, &endptr);
85
91
 
 
92
#ifndef HAVE_purify
 
93
      /*
 
94
        This debug printout should not be used for valgrind builds
 
95
        since it will read from unassigned memory.
 
96
      */
 
97
    DBUG_PRINT("info",
 
98
               ("bytes_decoded: %d  strptr: 0x%lx  endptr: 0x%lx ('%c':%d)",
 
99
                bytes_decoded, (long) strptr, (long) endptr, *endptr,
 
100
                *endptr));
 
101
#endif
 
102
 
86
103
    if (bytes_decoded < 0)
87
104
    {
88
105
      my_error(ER_BASE64_DECODE_ERROR, MYF(0));
91
108
    else if (bytes_decoded == 0)
92
109
      break; // If no bytes where read, the string contained only whitespace
93
110
 
94
 
    assert(bytes_decoded > 0);
95
 
    assert(endptr > strptr);
 
111
    DBUG_ASSERT(bytes_decoded > 0);
 
112
    DBUG_ASSERT(endptr > strptr);
96
113
    coded_len-= endptr - strptr;
97
114
    strptr= endptr;
98
115
 
107
124
      order to be able to read exactly what is necessary.
108
125
    */
109
126
 
 
127
    DBUG_PRINT("info",("binlog base64 decoded_len: %lu  bytes_decoded: %d",
 
128
                       (ulong) decoded_len, bytes_decoded));
 
129
 
110
130
    /*
111
131
      Now we start to read events of the buffer, until there are no
112
132
      more.
116
136
      /*
117
137
        Checking that the first event in the buffer is not truncated.
118
138
      */
119
 
      uint32_t event_len= uint4korr(bufptr + EVENT_LEN_OFFSET);
 
139
      ulong event_len= uint4korr(bufptr + EVENT_LEN_OFFSET);
 
140
      DBUG_PRINT("info", ("event_len=%lu, bytes_decoded=%d",
 
141
                          event_len, bytes_decoded));
120
142
      if (bytes_decoded < EVENT_LEN_OFFSET || (uint) bytes_decoded < event_len)
121
143
      {
122
144
        my_error(ER_SYNTAX_ERROR, MYF(0));
132
154
      {
133
155
        int type = bufptr[EVENT_TYPE_OFFSET];
134
156
        if (type == FORMAT_DESCRIPTION_EVENT || type == START_EVENT_V3)
135
 
          have_fd_event= true;
 
157
          have_fd_event= TRUE;
136
158
        else
137
159
        {
138
160
          my_error(ER_NO_FORMAT_DESCRIPTION_EVENT_BEFORE_BINLOG_STATEMENT,
145
167
                                    thd->rli_fake->relay_log.
146
168
                                      description_event_for_exec);
147
169
 
 
170
      DBUG_PRINT("info",("binlog base64 err=%s", error));
148
171
      if (!ev)
149
172
      {
150
173
        /*
158
181
      bytes_decoded -= event_len;
159
182
      bufptr += event_len;
160
183
 
 
184
      DBUG_PRINT("info",("ev->get_type_code()=%d", ev->get_type_code()));
 
185
#ifndef HAVE_purify
 
186
      /*
 
187
        This debug printout should not be used for valgrind builds
 
188
        since it will read from unassigned memory.
 
189
      */
 
190
      DBUG_PRINT("info",("bufptr+EVENT_TYPE_OFFSET: 0x%lx",
 
191
                         (long) (bufptr+EVENT_TYPE_OFFSET)));
 
192
      DBUG_PRINT("info", ("bytes_decoded: %d   bufptr: 0x%lx  buf[EVENT_LEN_OFFSET]: %lu",
 
193
                          bytes_decoded, (long) bufptr,
 
194
                          (ulong) uint4korr(bufptr+EVENT_LEN_OFFSET)));
 
195
#endif
161
196
      ev->thd= thd;
162
197
      /*
163
198
        We go directly to the application phase, since we don't need
167
202
        not used at all: the rli_fake instance is used only for error
168
203
        reporting.
169
204
      */
170
 
      if (apply_event_and_update_pos(ev, thd, thd->rli_fake, false))
 
205
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
 
206
      if (apply_event_and_update_pos(ev, thd, thd->rli_fake, FALSE))
171
207
      {
172
208
        /*
173
209
          TODO: Maybe a better error message since the BINLOG statement
176
212
        my_error(ER_UNKNOWN_ERROR, MYF(0), "Error executing BINLOG statement");
177
213
        goto end;
178
214
      }
 
215
#endif
179
216
 
180
217
      /*
181
218
        Format_description_log_event should not be deleted because it
189
226
    }
190
227
  }
191
228
 
 
229
 
 
230
  DBUG_PRINT("info",("binlog base64 execution finished successfully"));
192
231
  my_ok(thd);
193
232
 
194
233
end:
195
234
  thd->rli_fake->clear_tables_to_lock();
196
 
  free(buf);
197
 
  return;
 
235
  my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
 
236
  DBUG_VOID_RETURN;
198
237
}