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 */
16
#include <drizzled/server_includes.h>
17
#include <drizzled/replication/rli.h>
18
#include <drizzled/replication/binlog.h>
16
#include "mysql_priv.h"
19
18
#include <mysys/base64.h>
20
#include <drizzled/error.h>
21
#include <drizzled/slave.h>
22
#include <drizzled/session.h>
25
21
Execute a BINLOG statement
32
28
rli->description_event_for_exec.
35
void mysql_client_binlog_statement(Session* session)
31
void mysql_client_binlog_statement(THD* thd)
37
size_t coded_len= session->lex->comment.length + 1;
33
size_t coded_len= thd->lex->comment.length + 1;
38
34
size_t decoded_len= base64_needed_decoded_length(coded_len);
39
35
assert(coded_len > 0);
48
44
Format_description_event.
50
46
bool have_fd_event= true;
51
if (!session->rli_fake)
53
session->rli_fake= new Relay_log_info;
49
thd->rli_fake= new Relay_log_info;
55
session->rli_fake->is_fake= true;
51
thd->rli_fake->is_fake= true;
57
53
have_fd_event= false;
59
if (session->rli_fake && !session->rli_fake->relay_log.description_event_for_exec)
55
if (thd->rli_fake && !thd->rli_fake->relay_log.description_event_for_exec)
61
session->rli_fake->relay_log.description_event_for_exec=
57
thd->rli_fake->relay_log.description_event_for_exec=
62
58
new Format_description_log_event(4);
63
59
have_fd_event= false;
66
62
const char *error= 0;
67
char *buf= (char *) malloc(decoded_len);
63
char *buf= (char *) my_malloc(decoded_len, MYF(MY_WME));
71
67
Out of memory check
73
if (!(session->rli_fake &&
74
session->rli_fake->relay_log.description_event_for_exec &&
69
if (!(thd->rli_fake &&
70
thd->rli_fake->relay_log.description_event_for_exec &&
77
73
my_error(ER_OUTOFMEMORY, MYF(0), 1); /* needed 1 bytes */
81
session->rli_fake->sql_session= session;
82
session->rli_fake->no_storage= true;
77
thd->rli_fake->sql_thd= thd;
78
thd->rli_fake->no_storage= true;
84
for (char const *strptr= session->lex->comment.str ;
85
strptr < session->lex->comment.str + session->lex->comment.length ; )
80
for (char const *strptr= thd->lex->comment.str ;
81
strptr < thd->lex->comment.str + thd->lex->comment.length ; )
87
83
char const *endptr= 0;
88
84
int bytes_decoded= base64_decode(strptr, coded_len, buf, &endptr);
121
117
Checking that the first event in the buffer is not truncated.
123
uint32_t event_len= uint4korr(bufptr + EVENT_LEN_OFFSET);
119
ulong event_len= uint4korr(bufptr + EVENT_LEN_OFFSET);
124
120
if (bytes_decoded < EVENT_LEN_OFFSET || (uint) bytes_decoded < event_len)
126
122
my_error(ER_SYNTAX_ERROR, MYF(0));
148
144
ev= Log_event::read_log_event(bufptr, event_len, &error,
149
session->rli_fake->relay_log.
145
thd->rli_fake->relay_log.
150
146
description_event_for_exec);
171
167
not used at all: the rli_fake instance is used only for error
174
if (apply_event_and_update_pos(ev, session, session->rli_fake, false))
170
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
171
if (apply_event_and_update_pos(ev, thd, thd->rli_fake, false))
177
174
TODO: Maybe a better error message since the BINLOG statement