~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/log_event.cc

  • Committer: Monty Taylor
  • Date: 2008-08-09 02:24:34 UTC
  • mto: (266.1.8 codestyle)
  • mto: This revision was merged to the branch mainline in revision 279.
  • Revision ID: monty@inaugust.com-20080809022434-97na8pnugghskxip
Removed mystringslt conv lib and replaced it with a noinst lib.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
 
 
17
#ifndef MYSQL_CLIENT
 
18
 
17
19
#include <drizzled/server_includes.h>
18
20
#include "rpl_rli.h"
19
21
#include "rpl_mi.h"
23
25
#include <mysys/my_dir.h>
24
26
#include <drizzled/drizzled_error_messages.h>
25
27
 
26
 
#include <algorithm>
 
28
#endif /* !MYSQL_CLIENT */
27
29
 
28
30
#include <mysys/base64.h>
29
31
#include <mysys/my_bitmap.h>
30
32
 
31
 
#include <libdrizzle/gettext.h>
32
 
#include <libdrizzle/libdrizzle.h>
33
 
 
34
 
#define log_cs  &my_charset_utf8_general_ci
 
33
#define log_cs  &my_charset_latin1
35
34
 
36
35
#define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
37
36
 
45
44
#define FMT_G_BUFSIZE(PREC) (3 + (PREC) + 5 + 1)
46
45
 
47
46
 
 
47
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
48
48
static const char *HA_ERR(int i)
49
49
{
50
50
  switch (i) {
117
117
*/
118
118
static void inline slave_rows_error_report(enum loglevel level, int ha_error,
119
119
                                           Relay_log_info const *rli, THD *thd,
120
 
                                           Table *table, const char * type,
 
120
                                           TABLE *table, const char * type,
121
121
                                           const char *log_name, ulong pos)
122
122
{
123
123
  const char *handler_error= HA_ERR(ha_error);
124
124
  char buff[MAX_SLAVE_ERRMSG], *slider;
125
125
  const char *buff_end= buff + sizeof(buff);
126
 
  uint32_t len;
 
126
  uint len;
127
127
  List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
128
128
  DRIZZLE_ERROR *err;
129
129
  buff[0]= 0;
132
132
       slider += len, err= it++)
133
133
  {
134
134
    len= snprintf(slider, buff_end - slider,
135
 
                  _(" %s, Error_code: %d;"), err->msg, err->code);
 
135
                  " %s, Error_code: %d;", err->msg, err->code);
136
136
  }
137
137
  
138
138
  rli->report(level, thd->is_error()? thd->main_da.sql_errno() : 0,
139
 
              _("Could not execute %s event on table %s.%s;"
140
 
                "%s handler error %s; "
141
 
                "the event's master log %s, end_log_pos %lu"),
 
139
              "Could not execute %s event on table %s.%s;"
 
140
              "%s handler error %s; "
 
141
              "the event's master log %s, end_log_pos %lu",
142
142
              type, table->s->db.str,
143
143
              table->s->table_name.str,
144
144
              buff,
145
 
              handler_error == NULL? _("<unknown>") : handler_error,
 
145
              handler_error == NULL? "<unknown>" : handler_error,
146
146
              log_name, pos);
147
147
}
148
 
 
 
148
#endif
149
149
 
150
150
/*
151
151
  Cache that will automatically be written to a dedicated file on
225
225
  flag_set m_flags;
226
226
};
227
227
 
228
 
uint32_t debug_not_change_ts_if_art_event= 1; // bug#29309 simulation
 
228
uint debug_not_change_ts_if_art_event= 1; // bug#29309 simulation
229
229
 
230
230
/*
231
231
  pretty_print_str()
232
232
*/
233
233
 
 
234
#ifdef MYSQL_CLIENT
 
235
static void pretty_print_str(IO_CACHE* cache, const char* str, int len)
 
236
{
 
237
  const char* end = str + len;
 
238
  my_b_printf(cache, "\'");
 
239
  while (str < end)
 
240
  {
 
241
    char c;
 
242
    switch ((c=*str++)) {
 
243
    case '\n': my_b_printf(cache, "\\n"); break;
 
244
    case '\r': my_b_printf(cache, "\\r"); break;
 
245
    case '\\': my_b_printf(cache, "\\\\"); break;
 
246
    case '\b': my_b_printf(cache, "\\b"); break;
 
247
    case '\t': my_b_printf(cache, "\\t"); break;
 
248
    case '\'': my_b_printf(cache, "\\'"); break;
 
249
    case 0   : my_b_printf(cache, "\\0"); break;
 
250
    default:
 
251
      my_b_printf(cache, "%c", c);
 
252
      break;
 
253
    }
 
254
  }
 
255
  my_b_printf(cache, "\'");
 
256
}
 
257
#endif /* MYSQL_CLIENT */
 
258
 
 
259
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 
260
 
234
261
static void clear_all_errors(THD *thd, Relay_log_info *rli)
235
262
{
236
263
  thd->is_slave_error = 0;
248
275
  return ((err_code == ER_SLAVE_IGNORED_TABLE) ||
249
276
          (use_slave_mask && bitmap_is_set(&slave_error_mask, err_code)));
250
277
}
 
278
#endif
251
279
 
252
280
 
253
281
/*
254
282
  pretty_print_str()
255
283
*/
256
284
 
 
285
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
257
286
static char *pretty_print_str(char *packet, const char *str, int len)
258
287
{
259
288
  const char *end= str + len;
278
307
  *pos++= '\'';
279
308
  return pos;
280
309
}
281
 
 
 
310
#endif /* !MYSQL_CLIENT */
 
311
 
 
312
 
 
313
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
282
314
 
283
315
/**
284
316
  Creates a temporary name for load data infile:.
292
324
    Pointer to start of extension
293
325
*/
294
326
 
295
 
static char *slave_load_file_stem(char *buf, uint32_t file_id,
 
327
static char *slave_load_file_stem(char *buf, uint file_id,
296
328
                                  int event_server_id, const char *ext)
297
329
{
298
330
  char *res;
299
331
  fn_format(buf,"SQL_LOAD-",slave_load_tmpdir, "", MY_UNPACK_FILENAME);
300
332
  to_unix_path(buf);
301
333
 
302
 
  buf= strchr(buf, '\0');
303
 
  buf= int10_to_str(::server_id, buf, 10);
 
334
  buf = strend(buf);
 
335
  buf = int10_to_str(::server_id, buf, 10);
304
336
  *buf++ = '-';
305
 
  buf= int10_to_str(event_server_id, buf, 10);
 
337
  buf = int10_to_str(event_server_id, buf, 10);
306
338
  *buf++ = '-';
307
339
  res= int10_to_str(file_id, buf, 10);
308
 
  my_stpcpy(res, ext);                             // Add extension last
 
340
  strmov(res, ext);                             // Add extension last
309
341
  return res;                                   // Pointer to extension
310
342
}
311
 
 
 
343
#endif
 
344
 
 
345
 
 
346
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
312
347
 
313
348
/**
314
349
  Delete all temporary files used for SQL_LOAD.
318
353
{
319
354
  MY_DIR *dirp;
320
355
  FILEINFO *file;
321
 
  uint32_t i;
 
356
  uint i;
322
357
  char fname[FN_REFLEN], prefbuf[31], *p;
323
358
 
324
359
  if (!(dirp=my_dir(slave_load_tmpdir,MYF(MY_WME))))
349
384
 
350
385
  my_dirend(dirp);
351
386
}
 
387
#endif
352
388
 
353
389
 
354
390
/*
355
391
  write_str()
356
392
*/
357
393
 
358
 
static bool write_str(IO_CACHE *file, const char *str, uint32_t length)
 
394
static bool write_str(IO_CACHE *file, const char *str, uint length)
359
395
{
360
 
  unsigned char tmp[1];
361
 
  tmp[0]= (unsigned char) length;
 
396
  uchar tmp[1];
 
397
  tmp[0]= (uchar) length;
362
398
  return (my_b_safe_write(file, tmp, sizeof(tmp)) ||
363
 
          my_b_safe_write(file, (unsigned char*) str, length));
 
399
          my_b_safe_write(file, (uchar*) str, length));
364
400
}
365
401
 
366
402
 
371
407
static inline int read_str(const char **buf, const char *buf_end,
372
408
                           const char **str, uint8_t *len)
373
409
{
374
 
  if (*buf + ((uint) (unsigned char) **buf) >= buf_end)
 
410
  if (*buf + ((uint) (uchar) **buf) >= buf_end)
375
411
    return 1;
376
412
  *len= (uint8_t) **buf;
377
413
  *str= (*buf)+1;
384
420
  Transforms a string into "" or its expression in 0x... form.
385
421
*/
386
422
 
387
 
char *str_to_hex(char *to, const char *from, uint32_t len)
 
423
char *str_to_hex(char *to, const char *from, uint len)
388
424
{
389
425
  if (len)
390
426
  {
393
429
    to= octet2hex(to, from, len);
394
430
  }
395
431
  else
396
 
    to= my_stpcpy(to, "\"\"");
 
432
    to= strmov(to, "\"\"");
397
433
  return to;                               // pointer to end 0 of 'to'
398
434
}
399
435
 
 
436
#ifndef MYSQL_CLIENT
400
437
 
401
438
/**
402
439
  Append a version of the 'from' string suitable for use in a query to
420
457
  else
421
458
  {
422
459
    *ptr++= '\'';
423
 
    ptr+= drizzle_escape_string(ptr, from->ptr(), from->length());
 
460
    ptr+= escape_string_for_drizzle(csinfo, ptr, 0,
 
461
                                    from->ptr(), from->length());
424
462
    *ptr++='\'';
425
463
  }
426
464
  to->length(orig_len + ptr - beg);
427
465
  return 0;
428
466
}
429
 
 
 
467
#endif
 
468
 
 
469
 
 
470
/**
 
471
  Prints a "session_var=value" string. Used by mysqlbinlog to print some SET
 
472
  commands just before it prints a query.
 
473
*/
 
474
 
 
475
#ifdef MYSQL_CLIENT
 
476
 
 
477
static void print_set_option(IO_CACHE* file, uint32_t bits_changed,
 
478
                             uint32_t option, uint32_t flags, const char* name,
 
479
                             bool* need_comma)
 
480
{
 
481
  if (bits_changed & option)
 
482
  {
 
483
    if (*need_comma)
 
484
      my_b_printf(file,", ");
 
485
    my_b_printf(file,"%s=%d", name, test(flags & option));
 
486
    *need_comma= 1;
 
487
  }
 
488
}
 
489
#endif
430
490
 
431
491
/**************************************************************************
432
492
        Log_event methods (= the parent class of all events)
480
540
  Log_event::Log_event()
481
541
*/
482
542
 
 
543
#ifndef MYSQL_CLIENT
483
544
Log_event::Log_event(THD* thd_arg, uint16_t flags_arg, bool using_trans)
484
545
  :log_pos(0), temp_buf(0), exec_time(0), flags(flags_arg), thd(thd_arg)
485
546
{
508
569
  when=         0;
509
570
  log_pos=      0;
510
571
}
 
572
#endif /* !MYSQL_CLIENT */
511
573
 
512
574
 
513
575
/*
518
580
                     const Format_description_log_event* description_event)
519
581
  :temp_buf(0), cache_stmt(0)
520
582
{
521
 
  thd= 0;
522
 
  when= uint4korr(buf);
523
 
  server_id= uint4korr(buf + SERVER_ID_OFFSET);
 
583
#ifndef MYSQL_CLIENT
 
584
  thd = 0;
 
585
#endif
 
586
  when = uint4korr(buf);
 
587
  server_id = uint4korr(buf + SERVER_ID_OFFSET);
524
588
  data_written= uint4korr(buf + EVENT_LEN_OFFSET);
525
589
  if (description_event->binlog_version==1)
526
590
  {
579
643
  /* otherwise, go on with reading the header from buf (nothing now) */
580
644
}
581
645
 
 
646
#ifndef MYSQL_CLIENT
 
647
#ifdef HAVE_REPLICATION
582
648
 
583
649
int Log_event::do_update_pos(Relay_log_info *rli)
584
650
{
657
723
  pack_info(protocol);
658
724
  return protocol->write();
659
725
}
 
726
#endif /* HAVE_REPLICATION */
660
727
 
661
728
 
662
729
/**
685
752
 
686
753
bool Log_event::write_header(IO_CACHE* file, ulong event_data_length)
687
754
{
688
 
  unsigned char header[LOG_EVENT_HEADER_LEN];
 
755
  uchar header[LOG_EVENT_HEADER_LEN];
689
756
  ulong now;
690
757
 
691
758
  /* Store number of bytes that will be written by this event */
770
837
 
771
838
  if (log_lock)
772
839
    pthread_mutex_lock(log_lock);
773
 
  if (my_b_read(file, (unsigned char*) buf, sizeof(buf)))
 
840
  if (my_b_read(file, (uchar*) buf, sizeof(buf)))
774
841
  {
775
842
    /*
776
843
      If the read hits eof, we must report it as eof so the caller
828
895
    pthread_mutex_unlock(log_lock);
829
896
  return(result);
830
897
}
 
898
#endif /* !MYSQL_CLIENT */
831
899
 
 
900
#ifndef MYSQL_CLIENT
832
901
#define UNLOCK_MUTEX if (log_lock) pthread_mutex_unlock(log_lock);
833
902
#define LOCK_MUTEX if (log_lock) pthread_mutex_lock(log_lock);
 
903
#else
 
904
#define UNLOCK_MUTEX
 
905
#define LOCK_MUTEX
 
906
#endif
834
907
 
 
908
#ifndef MYSQL_CLIENT
835
909
/**
836
910
  @note
837
911
    Allocates memory;  The caller is responsible for clean-up.
840
914
                                     pthread_mutex_t* log_lock,
841
915
                                     const Format_description_log_event
842
916
                                     *description_event)
 
917
#else
 
918
Log_event* Log_event::read_log_event(IO_CACHE* file,
 
919
                                     const Format_description_log_event
 
920
                                     *description_event)
 
921
#endif
843
922
{
844
923
  assert(description_event != 0);
845
924
  char head[LOG_EVENT_MINIMAL_HEADER_LEN];
850
929
    of 13 bytes, whereas LOG_EVENT_MINIMAL_HEADER_LEN is 19 bytes (it's
851
930
    "minimal" over the set {MySQL >=4.0}).
852
931
  */
853
 
  uint32_t header_size= cmin(description_event->common_header_len,
 
932
  uint header_size= min(description_event->common_header_len,
854
933
                        LOG_EVENT_MINIMAL_HEADER_LEN);
855
934
 
856
935
  LOCK_MUTEX;
857
 
  if (my_b_read(file, (unsigned char *) head, header_size))
 
936
  if (my_b_read(file, (uchar *) head, header_size))
858
937
  {
859
938
    UNLOCK_MUTEX;
860
939
    /*
864
943
    */
865
944
    return(0);
866
945
  }
867
 
  uint32_t data_len = uint4korr(head + EVENT_LEN_OFFSET);
 
946
  uint data_len = uint4korr(head + EVENT_LEN_OFFSET);
868
947
  char *buf= 0;
869
948
  const char *error= 0;
870
949
  Log_event *res=  0;
871
950
#ifndef max_allowed_packet
872
951
  THD *thd=current_thd;
873
 
  uint32_t max_allowed_packet= thd ? thd->variables.max_allowed_packet : ~(ulong)0;
 
952
  uint max_allowed_packet= thd ? thd->variables.max_allowed_packet : ~(ulong)0;
874
953
#endif
875
954
 
876
955
  if (data_len > max_allowed_packet)
893
972
  }
894
973
  buf[data_len] = 0;
895
974
  memcpy(buf, head, header_size);
896
 
  if (my_b_read(file, (unsigned char*) buf + header_size, data_len - header_size))
 
975
  if (my_b_read(file, (uchar*) buf + header_size, data_len - header_size))
897
976
  {
898
977
    error = "read error";
899
978
    goto err;
906
985
  if (!res)
907
986
  {
908
987
    assert(error != 0);
909
 
    sql_print_error(_("Error in Log_event::read_log_event(): "
910
 
                    "'%s', data_len: %d, event_type: %d"),
 
988
    sql_print_error("Error in Log_event::read_log_event(): "
 
989
                    "'%s', data_len: %d, event_type: %d",
911
990
                    error,data_len,head[EVENT_TYPE_OFFSET]);
912
 
    free(buf);
 
991
    my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
913
992
    /*
914
993
      The SQL slave thread will check if file->error<0 to know
915
994
      if there was an I/O error. Even if there is no "low-level" I/O errors
929
1008
  constructors.
930
1009
*/
931
1010
 
932
 
Log_event* Log_event::read_log_event(const char* buf, uint32_t event_len,
 
1011
Log_event* Log_event::read_log_event(const char* buf, uint event_len,
933
1012
                                     const char **error,
934
1013
                                     const Format_description_log_event *description_event)
935
1014
{
945
1024
    return(NULL); // general sanity check - will fail on a partial read
946
1025
  }
947
1026
 
948
 
  uint32_t event_type= buf[EVENT_TYPE_OFFSET];
 
1027
  uint event_type= buf[EVENT_TYPE_OFFSET];
949
1028
  if (event_type > description_event->number_of_event_types &&
950
1029
      event_type != FORMAT_DESCRIPTION_EVENT)
951
1030
  {
1019
1098
    case FORMAT_DESCRIPTION_EVENT:
1020
1099
      ev = new Format_description_log_event(buf, event_len, description_event);
1021
1100
      break;
 
1101
#if defined(HAVE_REPLICATION) 
1022
1102
    case WRITE_ROWS_EVENT:
1023
1103
      ev = new Write_rows_log_event(buf, event_len, description_event);
1024
1104
      break;
1031
1111
    case TABLE_MAP_EVENT:
1032
1112
      ev = new Table_map_log_event(buf, event_len, description_event);
1033
1113
      break;
 
1114
#endif
1034
1115
    case BEGIN_LOAD_QUERY_EVENT:
1035
1116
      ev = new Begin_load_query_log_event(buf, event_len, description_event);
1036
1117
      break;
1058
1139
  if (!ev || !ev->is_valid())
1059
1140
  {
1060
1141
    delete ev;
 
1142
#ifdef MYSQL_CLIENT
 
1143
    if (!force_opt) /* then mysqlbinlog dies */
 
1144
    {
 
1145
      *error= "Found invalid event in binary log";
 
1146
      return(0);
 
1147
    }
 
1148
    ev= new Unknown_log_event(buf, description_event);
 
1149
#else
1061
1150
    *error= "Found invalid event in binary log";
1062
1151
    return(0);
 
1152
#endif
1063
1153
  }
1064
1154
  return(ev);  
1065
1155
}
1066
1156
 
 
1157
#ifdef MYSQL_CLIENT
 
1158
 
 
1159
/*
 
1160
  Log_event::print_header()
 
1161
*/
 
1162
 
 
1163
void Log_event::print_header(IO_CACHE* file,
 
1164
                             PRINT_EVENT_INFO* print_event_info,
 
1165
                             bool is_more __attribute__((unused)))
 
1166
{
 
1167
  char llbuff[22];
 
1168
  my_off_t hexdump_from= print_event_info->hexdump_from;
 
1169
 
 
1170
  my_b_printf(file, "#");
 
1171
  print_timestamp(file);
 
1172
  my_b_printf(file, " server id %d  end_log_pos %s ", server_id,
 
1173
              llstr(log_pos,llbuff));
 
1174
 
 
1175
  /* mysqlbinlog --hexdump */
 
1176
  if (print_event_info->hexdump_from)
 
1177
  {
 
1178
    my_b_printf(file, "\n");
 
1179
    uchar *ptr= (uchar*)temp_buf;
 
1180
    my_off_t size=
 
1181
      uint4korr(ptr + EVENT_LEN_OFFSET) - LOG_EVENT_MINIMAL_HEADER_LEN;
 
1182
    my_off_t i;
 
1183
 
 
1184
    /* Header len * 4 >= header len * (2 chars + space + extra space) */
 
1185
    char *h, hex_string[LOG_EVENT_MINIMAL_HEADER_LEN*4]= {0};
 
1186
    char *c, char_string[16+1]= {0};
 
1187
 
 
1188
    /* Pretty-print event common header if header is exactly 19 bytes */
 
1189
    if (print_event_info->common_header_len == LOG_EVENT_MINIMAL_HEADER_LEN)
 
1190
    {
 
1191
      char emit_buf[256];               // Enough for storing one line
 
1192
      my_b_printf(file, "# Position  Timestamp   Type   Master ID        "
 
1193
                  "Size      Master Pos    Flags \n");
 
1194
      int const bytes_written=
 
1195
        snprintf(emit_buf, sizeof(emit_buf),
 
1196
                 "# %8.8lx %02x %02x %02x %02x   %02x   "
 
1197
                 "%02x %02x %02x %02x   %02x %02x %02x %02x   "
 
1198
                 "%02x %02x %02x %02x   %02x %02x\n",
 
1199
                 (unsigned long) hexdump_from,
 
1200
                 ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6],
 
1201
                 ptr[7], ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13],
 
1202
                 ptr[14], ptr[15], ptr[16], ptr[17], ptr[18]);
 
1203
      assert(bytes_written >= 0);
 
1204
      assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
 
1205
      my_b_write(file, (uchar*) emit_buf, bytes_written);
 
1206
      ptr += LOG_EVENT_MINIMAL_HEADER_LEN;
 
1207
      hexdump_from += LOG_EVENT_MINIMAL_HEADER_LEN;
 
1208
    }
 
1209
 
 
1210
    /* Rest of event (without common header) */
 
1211
    for (i= 0, c= char_string, h=hex_string;
 
1212
         i < size;
 
1213
         i++, ptr++)
 
1214
    {
 
1215
      snprintf(h, 4, "%02x ", *ptr);
 
1216
      h += 3;
 
1217
 
 
1218
      *c++= my_isalnum(&my_charset_bin, *ptr) ? *ptr : '.';
 
1219
 
 
1220
      if (i % 16 == 15)
 
1221
      {
 
1222
        /*
 
1223
          my_b_printf() does not support full printf() formats, so we
 
1224
          have to do it this way.
 
1225
 
 
1226
          TODO: Rewrite my_b_printf() to support full printf() syntax.
 
1227
         */
 
1228
        char emit_buf[256];
 
1229
        int const bytes_written=
 
1230
          snprintf(emit_buf, sizeof(emit_buf),
 
1231
                   "# %8.8lx %-48.48s |%16s|\n",
 
1232
                   (unsigned long) (hexdump_from + (i & 0xfffffff0)),
 
1233
                   hex_string, char_string);
 
1234
        assert(bytes_written >= 0);
 
1235
        assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
 
1236
        my_b_write(file, (uchar*) emit_buf, bytes_written);
 
1237
        hex_string[0]= 0;
 
1238
        char_string[0]= 0;
 
1239
        c= char_string;
 
1240
        h= hex_string;
 
1241
      }
 
1242
      else if (i % 8 == 7) *h++ = ' ';
 
1243
    }
 
1244
    *c= '\0';
 
1245
 
 
1246
    if (hex_string[0])
 
1247
    {
 
1248
      char emit_buf[256];
 
1249
      int const bytes_written=
 
1250
        snprintf(emit_buf, sizeof(emit_buf),
 
1251
                    "# %8.8lx %-48.48s |%s|\n",
 
1252
                    (unsigned long) (hexdump_from + (i & 0xfffffff0)),
 
1253
                    hex_string, char_string);
 
1254
      assert(bytes_written >= 0);
 
1255
      assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
 
1256
      my_b_write(file, (uchar*) emit_buf, bytes_written);
 
1257
    }
 
1258
    /*
 
1259
      need a # to prefix the rest of printouts for example those of
 
1260
      Rows_log_event::print_helper().
 
1261
    */
 
1262
    my_b_write(file, reinterpret_cast<const uchar*>("# "), 2);
 
1263
  }
 
1264
  return;
 
1265
}
 
1266
 
 
1267
 
 
1268
void Log_event::print_base64(IO_CACHE* file,
 
1269
                             PRINT_EVENT_INFO* print_event_info,
 
1270
                             bool more)
 
1271
{
 
1272
  const uchar *ptr= (const uchar *)temp_buf;
 
1273
  uint32_t size= uint4korr(ptr + EVENT_LEN_OFFSET);
 
1274
 
 
1275
  size_t const tmp_str_sz= base64_needed_encoded_length((int) size);
 
1276
  char *const tmp_str= (char *) my_malloc(tmp_str_sz, MYF(MY_WME));
 
1277
  if (!tmp_str) {
 
1278
    fprintf(stderr, "\nError: Out of memory. "
 
1279
            "Could not print correct binlog event.\n");
 
1280
    return;
 
1281
  }
 
1282
 
 
1283
  if (base64_encode(ptr, (size_t) size, tmp_str))
 
1284
  {
 
1285
    assert(0);
 
1286
  }
 
1287
 
 
1288
  if (my_b_tell(file) == 0)
 
1289
    my_b_printf(file, "\nBINLOG '\n");
 
1290
 
 
1291
  my_b_printf(file, "%s\n", tmp_str);
 
1292
 
 
1293
  if (!more)
 
1294
    my_b_printf(file, "'%s\n", print_event_info->delimiter);
 
1295
 
 
1296
  my_free(tmp_str, MYF(0));
 
1297
  return;
 
1298
}
 
1299
 
 
1300
 
 
1301
/*
 
1302
  Log_event::print_timestamp()
 
1303
*/
 
1304
 
 
1305
void Log_event::print_timestamp(IO_CACHE* file, time_t* ts)
 
1306
{
 
1307
  struct tm *res;
 
1308
  if (!ts)
 
1309
    ts = &when;
 
1310
#ifdef MYSQL_SERVER                             // This is always false
 
1311
  struct tm tm_tmp;
 
1312
  localtime_r(ts,(res= &tm_tmp));
 
1313
#else
 
1314
  res=localtime(ts);
 
1315
#endif
 
1316
 
 
1317
  my_b_printf(file,"%02d%02d%02d %2d:%02d:%02d",
 
1318
              res->tm_year % 100,
 
1319
              res->tm_mon+1,
 
1320
              res->tm_mday,
 
1321
              res->tm_hour,
 
1322
              res->tm_min,
 
1323
              res->tm_sec);
 
1324
  return;
 
1325
}
 
1326
 
 
1327
#endif /* MYSQL_CLIENT */
 
1328
 
 
1329
 
 
1330
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1067
1331
inline Log_event::enum_skip_reason
1068
1332
Log_event::continue_group(Relay_log_info *rli)
1069
1333
{
1071
1335
    return Log_event::EVENT_SKIP_IGNORE;
1072
1336
  return Log_event::do_shall_skip(rli);
1073
1337
}
 
1338
#endif
1074
1339
 
1075
1340
/**************************************************************************
1076
1341
        Query_log_event methods
1077
1342
**************************************************************************/
1078
1343
 
 
1344
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 
1345
 
1079
1346
/**
1080
1347
  This (which is used only for SHOW BINLOG EVENTS) could be updated to
1081
1348
  print SET @@session_var=. But this is not urgent, as SHOW BINLOG EVENTS is
1095
1362
  if (!(flags & LOG_EVENT_SUPPRESS_USE_F)
1096
1363
      && db && db_len)
1097
1364
  {
1098
 
    pos= my_stpcpy(buf, "use `");
 
1365
    pos= strmov(buf, "use `");
1099
1366
    memcpy(pos, db, db_len);
1100
 
    pos= my_stpcpy(pos+db_len, "`; ");
 
1367
    pos= strmov(pos+db_len, "`; ");
1101
1368
  }
1102
1369
  if (query && q_len)
1103
1370
  {
1105
1372
    pos+= q_len;
1106
1373
  }
1107
1374
  protocol->store(buf, pos-buf, &my_charset_bin);
1108
 
  free(buf);
 
1375
  my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
1109
1376
}
 
1377
#endif
1110
1378
 
 
1379
#ifndef MYSQL_CLIENT
1111
1380
 
1112
1381
/**
1113
1382
  Utility function for the next method (Query_log_event::write()) .
1114
1383
*/
1115
1384
static void write_str_with_code_and_len(char **dst, const char *src,
1116
 
                                        int len, uint32_t code)
 
1385
                                        int len, uint code)
1117
1386
{
1118
1387
  assert(src);
1119
1388
  *((*dst)++)= code;
1120
 
  *((*dst)++)= (unsigned char) len;
 
1389
  *((*dst)++)= (uchar) len;
1121
1390
  memcpy(*dst, src, len);
1122
1391
  (*dst)+= len;
1123
1392
}
1139
1408
    replicating it correctly, since the length is stored in a byte
1140
1409
    /sven
1141
1410
  */
1142
 
  unsigned char buf[QUERY_HEADER_LEN+
 
1411
  uchar buf[QUERY_HEADER_LEN+
1143
1412
            1+4+           // code of flags2 and flags2
1144
1413
            1+8+           // code of sql_mode and sql_mode
1145
1414
            1+1+FN_REFLEN+ // code of catalog and catalog length and catalog
1295
1564
  event_length= (uint) (start-buf) + get_post_header_size_for_derived() + db_len + 1 + q_len;
1296
1565
 
1297
1566
  return (write_header(file, event_length) ||
1298
 
          my_b_safe_write(file, (unsigned char*) buf, QUERY_HEADER_LEN) ||
 
1567
          my_b_safe_write(file, (uchar*) buf, QUERY_HEADER_LEN) ||
1299
1568
          write_post_header_for_derived(file) ||
1300
 
          my_b_safe_write(file, (unsigned char*) start_of_status,
 
1569
          my_b_safe_write(file, (uchar*) start_of_status,
1301
1570
                          (uint) (start-start_of_status)) ||
1302
 
          my_b_safe_write(file, (db) ? (unsigned char*) db : (unsigned char*)"", db_len + 1) ||
1303
 
          my_b_safe_write(file, (unsigned char*) query, q_len)) ? 1 : 0;
 
1571
          my_b_safe_write(file, (db) ? (uchar*) db : (uchar*)"", db_len + 1) ||
 
1572
          my_b_safe_write(file, (uchar*) query, q_len)) ? 1 : 0;
1304
1573
}
1305
1574
 
1306
1575
/**
1402
1671
  else
1403
1672
    time_zone_len= 0;
1404
1673
}
 
1674
#endif /* MYSQL_CLIENT */
1405
1675
 
1406
1676
 
1407
1677
/* 2 utility functions for the next method */
1433
1703
static int
1434
1704
get_str_len_and_pointer(const Log_event::Byte **src,
1435
1705
                        const char **dst,
1436
 
                        uint32_t *len,
 
1706
                        uint *len,
1437
1707
                        const Log_event::Byte *end)
1438
1708
{
1439
1709
  if (*src >= end)
1440
1710
    return -1;       // Will be UINT_MAX in two-complement arithmetics
1441
 
  uint32_t length= **src;
 
1711
  uint length= **src;
1442
1712
  if (length > 0)
1443
1713
  {
1444
1714
    if (*src + length >= end)
1452
1722
 
1453
1723
static void copy_str_and_move(const char **src, 
1454
1724
                              Log_event::Byte **dst, 
1455
 
                              uint32_t len)
 
1725
                              uint len)
1456
1726
{
1457
1727
  memcpy(*dst, *src, len);
1458
1728
  *src= (const char *)*dst;
1470
1740
 */
1471
1741
#define CHECK_SPACE(PTR,END,CNT)                      \
1472
1742
  do {                                                \
1473
 
    assert((PTR) + (CNT) <= (END));                   \
 
1743
    assert((PTR) + (CNT) <= (END));              \
1474
1744
    if ((PTR) + (CNT) > (END)) {                      \
1475
1745
      query= 0;                                       \
1476
 
      return;                                         \
 
1746
      return;                               \
1477
1747
    }                                                 \
1478
1748
  } while (0)
1479
1749
 
1481
1751
/**
1482
1752
  This is used by the SQL slave thread to prepare the event before execution.
1483
1753
*/
1484
 
Query_log_event::Query_log_event(const char* buf, uint32_t event_len,
 
1754
Query_log_event::Query_log_event(const char* buf, uint event_len,
1485
1755
                                 const Format_description_log_event
1486
1756
                                 *description_event,
1487
1757
                                 Log_event_type event_type)
1488
 
  :Log_event(buf, description_event), data_buf(0), query(NULL),
1489
 
   db(NULL), catalog_len(0), status_vars_len(0),
 
1758
  :Log_event(buf, description_event), data_buf(0), query(NullS),
 
1759
   db(NullS), catalog_len(0), status_vars_len(0),
1490
1760
   flags2_inited(0), sql_mode_inited(0), charset_inited(0),
1491
1761
   auto_increment_increment(1), auto_increment_offset(1),
1492
1762
   time_zone_len(0), lc_time_names_number(0), charset_database_number(0)
1493
1763
{
1494
 
  uint32_t data_len;
 
1764
  ulong data_len;
1495
1765
  uint32_t tmp;
1496
1766
  uint8_t common_header_len, post_header_len;
1497
1767
  Log_event::Byte *start;
1531
1801
      be even bigger, but this will suffice to catch most corruption
1532
1802
      errors that can lead to a crash.
1533
1803
    */
1534
 
    if (status_vars_len > cmin(data_len, (uint32_t)MAX_SIZE_LOG_EVENT_STATUS))
 
1804
    if (status_vars_len > min(data_len, MAX_SIZE_LOG_EVENT_STATUS))
1535
1805
    {
1536
1806
      query= 0;
1537
1807
      return;
1616
1886
      break;
1617
1887
    default:
1618
1888
      /* That's why you must write status vars in growing order of code */
1619
 
      pos= (const unsigned char*) end;                         // Break loop
 
1889
      pos= (const uchar*) end;                         // Break loop
1620
1890
    }
1621
1891
  }
1622
1892
  
1661
1931
}
1662
1932
 
1663
1933
 
 
1934
#ifdef MYSQL_CLIENT
 
1935
/**
 
1936
  Query_log_event::print().
 
1937
 
 
1938
  @todo
 
1939
    print the catalog ??
 
1940
*/
 
1941
void Query_log_event::print_query_header(IO_CACHE* file,
 
1942
                                         PRINT_EVENT_INFO* print_event_info)
 
1943
{
 
1944
  // TODO: print the catalog ??
 
1945
  char buff[40],*end;                           // Enough for SET TIMESTAMP
 
1946
  bool different_db= 1;
 
1947
  uint32_t tmp;
 
1948
 
 
1949
  if (!print_event_info->short_form)
 
1950
  {
 
1951
    print_header(file, print_event_info, false);
 
1952
    my_b_printf(file, "\t%s\tthread_id=%lu\texec_time=%lu\terror_code=%d\n",
 
1953
                get_type_str(), (ulong) thread_id, (ulong) exec_time,
 
1954
                error_code);
 
1955
  }
 
1956
 
 
1957
  if (!(flags & LOG_EVENT_SUPPRESS_USE_F) && db)
 
1958
  {
 
1959
    if ((different_db= memcmp(print_event_info->db, db, db_len + 1)))
 
1960
      memcpy(print_event_info->db, db, db_len + 1);
 
1961
    if (db[0] && different_db) 
 
1962
      my_b_printf(file, "use %s%s\n", db, print_event_info->delimiter);
 
1963
  }
 
1964
 
 
1965
  end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10);
 
1966
  end= strmov(end, print_event_info->delimiter);
 
1967
  *end++='\n';
 
1968
  my_b_write(file, (uchar*) buff, (uint) (end-buff));
 
1969
  if ((!print_event_info->thread_id_printed ||
 
1970
       ((flags & LOG_EVENT_THREAD_SPECIFIC_F) &&
 
1971
        thread_id != print_event_info->thread_id)))
 
1972
  {
 
1973
    // If --short-form, print deterministic value instead of pseudo_thread_id.
 
1974
    my_b_printf(file,"SET @@session.pseudo_thread_id=%lu%s\n",
 
1975
                short_form ? 999999999 : (ulong)thread_id,
 
1976
                print_event_info->delimiter);
 
1977
    print_event_info->thread_id= thread_id;
 
1978
    print_event_info->thread_id_printed= 1;
 
1979
  }
 
1980
 
 
1981
  /*
 
1982
    If flags2_inited==0, this is an event from 3.23 or 4.0; nothing to
 
1983
    print (remember we don't produce mixed relay logs so there cannot be
 
1984
    5.0 events before that one so there is nothing to reset).
 
1985
  */
 
1986
  if (likely(flags2_inited)) /* likely as this will mainly read 5.0 logs */
 
1987
  {
 
1988
    /* tmp is a bitmask of bits which have changed. */
 
1989
    if (likely(print_event_info->flags2_inited)) 
 
1990
      /* All bits which have changed */
 
1991
      tmp= (print_event_info->flags2) ^ flags2;
 
1992
    else /* that's the first Query event we read */
 
1993
    {
 
1994
      print_event_info->flags2_inited= 1;
 
1995
      tmp= ~((uint32_t)0); /* all bits have changed */
 
1996
    }
 
1997
 
 
1998
    if (unlikely(tmp)) /* some bits have changed */
 
1999
    {
 
2000
      bool need_comma= 0;
 
2001
      my_b_printf(file, "SET ");
 
2002
      print_set_option(file, tmp, OPTION_NO_FOREIGN_KEY_CHECKS, ~flags2,
 
2003
                   "@@session.foreign_key_checks", &need_comma);
 
2004
      print_set_option(file, tmp, OPTION_AUTO_IS_NULL, flags2,
 
2005
                   "@@session.sql_auto_is_null", &need_comma);
 
2006
      print_set_option(file, tmp, OPTION_RELAXED_UNIQUE_CHECKS, ~flags2,
 
2007
                   "@@session.unique_checks", &need_comma);
 
2008
      my_b_printf(file,"%s\n", print_event_info->delimiter);
 
2009
      print_event_info->flags2= flags2;
 
2010
    }
 
2011
  }
 
2012
 
 
2013
  /*
 
2014
    Now the session variables;
 
2015
    it's more efficient to pass SQL_MODE as a number instead of a
 
2016
    comma-separated list.
 
2017
    FOREIGN_KEY_CHECKS, SQL_AUTO_IS_NULL, UNIQUE_CHECKS are session-only
 
2018
    variables (they have no global version; they're not listed in
 
2019
    sql_class.h), The tests below work for pure binlogs or pure relay
 
2020
    logs. Won't work for mixed relay logs but we don't create mixed
 
2021
    relay logs (that is, there is no relay log with a format change
 
2022
    except within the 3 first events, which mysqlbinlog handles
 
2023
    gracefully). So this code should always be good.
 
2024
  */
 
2025
 
 
2026
  if (print_event_info->auto_increment_increment != auto_increment_increment ||
 
2027
      print_event_info->auto_increment_offset != auto_increment_offset)
 
2028
  {
 
2029
    my_b_printf(file,"SET @@session.auto_increment_increment=%lu, @@session.auto_increment_offset=%lu%s\n",
 
2030
                auto_increment_increment,auto_increment_offset,
 
2031
                print_event_info->delimiter);
 
2032
    print_event_info->auto_increment_increment= auto_increment_increment;
 
2033
    print_event_info->auto_increment_offset=    auto_increment_offset;
 
2034
  }
 
2035
 
 
2036
  /* TODO: print the catalog when we feature SET CATALOG */
 
2037
 
 
2038
  if (likely(charset_inited) &&
 
2039
      (unlikely(!print_event_info->charset_inited ||
 
2040
                memcmp(print_event_info->charset, charset, 6))))
 
2041
  {
 
2042
    const CHARSET_INFO * const cs_info= get_charset(uint2korr(charset), MYF(MY_WME));
 
2043
    if (cs_info)
 
2044
    {
 
2045
      /* for mysql client */
 
2046
      my_b_printf(file, "/*!\\C %s */%s\n",
 
2047
                  cs_info->csname, print_event_info->delimiter);
 
2048
    }
 
2049
    my_b_printf(file,"SET "
 
2050
                "@@session.character_set_client=%d,"
 
2051
                "@@session.collation_connection=%d,"
 
2052
                "@@session.collation_server=%d"
 
2053
                "%s\n",
 
2054
                uint2korr(charset),
 
2055
                uint2korr(charset+2),
 
2056
                uint2korr(charset+4),
 
2057
                print_event_info->delimiter);
 
2058
    memcpy(print_event_info->charset, charset, 6);
 
2059
    print_event_info->charset_inited= 1;
 
2060
  }
 
2061
  if (time_zone_len)
 
2062
  {
 
2063
    if (memcmp(print_event_info->time_zone_str, time_zone_str, time_zone_len+1))
 
2064
    {
 
2065
      my_b_printf(file,"SET @@session.time_zone='%s'%s\n",
 
2066
                  time_zone_str, print_event_info->delimiter);
 
2067
      memcpy(print_event_info->time_zone_str, time_zone_str, time_zone_len+1);
 
2068
    }
 
2069
  }
 
2070
  if (lc_time_names_number != print_event_info->lc_time_names_number)
 
2071
  {
 
2072
    my_b_printf(file, "SET @@session.lc_time_names=%d%s\n",
 
2073
                lc_time_names_number, print_event_info->delimiter);
 
2074
    print_event_info->lc_time_names_number= lc_time_names_number;
 
2075
  }
 
2076
  if (charset_database_number != print_event_info->charset_database_number)
 
2077
  {
 
2078
    if (charset_database_number)
 
2079
      my_b_printf(file, "SET @@session.collation_database=%d%s\n",
 
2080
                  charset_database_number, print_event_info->delimiter);
 
2081
    else
 
2082
      my_b_printf(file, "SET @@session.collation_database=DEFAULT%s\n",
 
2083
                  print_event_info->delimiter);
 
2084
    print_event_info->charset_database_number= charset_database_number;
 
2085
  }
 
2086
}
 
2087
 
 
2088
 
 
2089
void Query_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
2090
{
 
2091
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
2092
 
 
2093
  print_query_header(&cache, print_event_info);
 
2094
  my_b_write(&cache, (uchar*) query, q_len);
 
2095
  my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
 
2096
}
 
2097
#endif /* MYSQL_CLIENT */
 
2098
 
 
2099
 
1664
2100
/*
1665
2101
  Query_log_event::do_apply_event()
1666
2102
*/
 
2103
 
 
2104
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 
2105
 
1667
2106
int Query_log_event::do_apply_event(Relay_log_info const *rli)
1668
2107
{
1669
2108
  return do_apply_event(rli, query, q_len);
1736
2175
    thd->set_time((time_t)when);
1737
2176
    thd->query_length= q_len_arg;
1738
2177
    thd->query= (char*)query_arg;
1739
 
    pthread_mutex_lock(&LOCK_thread_count);
 
2178
    VOID(pthread_mutex_lock(&LOCK_thread_count));
1740
2179
    thd->query_id = next_query_id();
1741
 
    pthread_mutex_unlock(&LOCK_thread_count);
 
2180
    VOID(pthread_mutex_unlock(&LOCK_thread_count));
1742
2181
    thd->variables.pseudo_thread_id= thread_id;         // for temp tables
1743
2182
 
1744
2183
    if (ignored_error_code((expected_error= error_code)) ||
1835
2274
        clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); /* Can ignore query */
1836
2275
      else
1837
2276
      {
1838
 
        rli->report(ERROR_LEVEL, expected_error,
1839
 
                    _("Query partially completed on the master "
1840
 
                      "(error on master: %d) and was aborted. There is a "
1841
 
                      "chance that your master is inconsistent at this "
1842
 
                      "point. If you are sure that your master is ok, run "
1843
 
                      "this query manually on the slave and then restart the "
1844
 
                      "slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; "
1845
 
                      "START SLAVE; . Query: '%s'"),
1846
 
                    expected_error, thd->query);
 
2277
        rli->report(ERROR_LEVEL, expected_error, 
 
2278
                          "\
 
2279
Query partially completed on the master (error on master: %d) \
 
2280
and was aborted. There is a chance that your master is inconsistent at this \
 
2281
point. If you are sure that your master is ok, run this query manually on the \
 
2282
slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; \
 
2283
START SLAVE; . Query: '%s'", expected_error, thd->query);
1847
2284
        thd->is_slave_error= 1;
1848
2285
      }
1849
2286
      goto end;
1850
2287
    }
1851
2288
 
 
2289
    /* If the query was not ignored, it is printed to the general log */
 
2290
    if (!thd->is_error() || thd->main_da.sql_errno() != ER_SLAVE_IGNORED_TABLE)
 
2291
      general_log_write(thd, COM_QUERY, thd->query, thd->query_length);
 
2292
 
1852
2293
compare_errors:
1853
2294
 
1854
2295
     /*
1857
2298
    */
1858
2299
    actual_error= thd->is_error() ? thd->main_da.sql_errno() : 0;
1859
2300
    if ((expected_error != actual_error) &&
1860
 
        expected_error &&
1861
 
        !ignored_error_code(actual_error) &&
1862
 
        !ignored_error_code(expected_error))
 
2301
        expected_error &&
 
2302
        !ignored_error_code(actual_error) &&
 
2303
        !ignored_error_code(expected_error))
1863
2304
    {
1864
2305
      rli->report(ERROR_LEVEL, 0,
1865
 
                  _("Query caused differenxt errors on master and slave.\n"
1866
 
                    "Error on master: '%s' (%d), Error on slave: '%s' (%d).\n"
1867
 
                    "Default database: '%s'. Query: '%s'"),
1868
 
                  ER_SAFE(expected_error),
1869
 
                  expected_error,
1870
 
                  actual_error ? thd->main_da.message() : _("no error"),
1871
 
                  actual_error,
1872
 
                  print_slave_db_safe(db), query_arg);
 
2306
                      "\
 
2307
Query caused different errors on master and slave.     \
 
2308
Error on master: '%s' (%d), Error on slave: '%s' (%d). \
 
2309
Default database: '%s'. Query: '%s'",
 
2310
                      ER_SAFE(expected_error),
 
2311
                      expected_error,
 
2312
                      actual_error ? thd->main_da.message() : "no error",
 
2313
                      actual_error,
 
2314
                      print_slave_db_safe(db), query_arg);
1873
2315
      thd->is_slave_error= 1;
1874
2316
    }
1875
2317
    /*
1887
2329
    else if (thd->is_slave_error || thd->is_fatal_error)
1888
2330
    {
1889
2331
      rli->report(ERROR_LEVEL, actual_error,
1890
 
                  _("Error '%s' on query. Default database: '%s'. Query: '%s'"),
1891
 
                  (actual_error ? thd->main_da.message() :
1892
 
                   _("unexpected success or fatal error")),
 
2332
                      "Error '%s' on query. Default database: '%s'. Query: '%s'",
 
2333
                      (actual_error ? thd->main_da.message() :
 
2334
                       "unexpected success or fatal error"),
1893
2335
                      print_slave_db_safe(thd->db), query_arg);
1894
2336
      thd->is_slave_error= 1;
1895
2337
    }
1918
2360
  } /* End of if (db_ok(... */
1919
2361
 
1920
2362
end:
1921
 
  pthread_mutex_lock(&LOCK_thread_count);
 
2363
  VOID(pthread_mutex_lock(&LOCK_thread_count));
1922
2364
  /*
1923
2365
    Probably we have set thd->query, thd->db, thd->catalog to point to places
1924
2366
    in the data_buf of this event. Now the event is going to be deleted
1925
2367
    probably, so data_buf will be freed, so the thd->... listed above will be
1926
2368
    pointers to freed memory. 
1927
2369
    So we must set them to 0, so that those bad pointers values are not later
1928
 
    used. Note that "cleanup" queries like automatic DROP TEMPORARY Table
 
2370
    used. Note that "cleanup" queries like automatic DROP TEMPORARY TABLE
1929
2371
    don't suffer from these assignments to 0 as DROP TEMPORARY
1930
 
    Table uses the db.table syntax.
 
2372
    TABLE uses the db.table syntax.
1931
2373
  */
1932
2374
  thd->catalog= 0;
1933
2375
  thd->set_db(NULL, 0);                 /* will free the current database */
1934
2376
  thd->query= 0;                        // just to be sure
1935
2377
  thd->query_length= 0;
1936
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
2378
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1937
2379
  close_thread_tables(thd);      
1938
2380
  /*
1939
2381
    As a disk space optimization, future masters will not log an event for
1988
2430
  return(Log_event::do_shall_skip(rli));
1989
2431
}
1990
2432
 
 
2433
#endif
 
2434
 
1991
2435
 
1992
2436
/**************************************************************************
1993
2437
        Start_log_event_v3 methods
1994
2438
**************************************************************************/
1995
2439
 
 
2440
#ifndef MYSQL_CLIENT
1996
2441
Start_log_event_v3::Start_log_event_v3()
1997
2442
  :Log_event(), created(0), binlog_version(BINLOG_VERSION),
1998
2443
   artificial_event(0), dont_set_created(0)
1999
2444
{
2000
2445
  memcpy(server_version, ::server_version, ST_SERVER_VER_LEN);
2001
2446
}
 
2447
#endif
2002
2448
 
2003
2449
/*
2004
2450
  Start_log_event_v3::pack_info()
2005
2451
*/
2006
2452
 
 
2453
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2007
2454
void Start_log_event_v3::pack_info(Protocol *protocol)
2008
2455
{
2009
2456
  char buf[12 + ST_SERVER_VER_LEN + 14 + 22], *pos;
2010
 
  pos= my_stpcpy(buf, "Server ver: ");
2011
 
  pos= my_stpcpy(pos, server_version);
2012
 
  pos= my_stpcpy(pos, ", Binlog ver: ");
 
2457
  pos= strmov(buf, "Server ver: ");
 
2458
  pos= strmov(pos, server_version);
 
2459
  pos= strmov(pos, ", Binlog ver: ");
2013
2460
  pos= int10_to_str(binlog_version, pos, 10);
2014
2461
  protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
2015
2462
}
2016
 
 
 
2463
#endif
 
2464
 
 
2465
 
 
2466
/*
 
2467
  Start_log_event_v3::print()
 
2468
*/
 
2469
 
 
2470
#ifdef MYSQL_CLIENT
 
2471
void Start_log_event_v3::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
2472
{
 
2473
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
2474
                               Write_on_release_cache::FLUSH_F);
 
2475
 
 
2476
  if (!print_event_info->short_form)
 
2477
  {
 
2478
    print_header(&cache, print_event_info, false);
 
2479
    my_b_printf(&cache, "\tStart: binlog v %d, server v %s created ",
 
2480
                binlog_version, server_version);
 
2481
    print_timestamp(&cache);
 
2482
    if (created)
 
2483
      my_b_printf(&cache," at startup");
 
2484
    my_b_printf(&cache, "\n");
 
2485
    if (flags & LOG_EVENT_BINLOG_IN_USE_F)
 
2486
      my_b_printf(&cache, "# Warning: this binlog was not closed properly. "
 
2487
                  "Most probably mysqld crashed writing it.\n");
 
2488
  }
 
2489
  if (!artificial_event && created)
 
2490
  {
 
2491
#ifdef WHEN_WE_HAVE_THE_RESET_CONNECTION_SQL_COMMAND
 
2492
    /*
 
2493
      This is for mysqlbinlog: like in replication, we want to delete the stale
 
2494
      tmp files left by an unclean shutdown of mysqld (temporary tables)
 
2495
      and rollback unfinished transaction.
 
2496
      Probably this can be done with RESET CONNECTION (syntax to be defined).
 
2497
    */
 
2498
    my_b_printf(&cache,"RESET CONNECTION%s\n", print_event_info->delimiter);
 
2499
#else
 
2500
    my_b_printf(&cache,"ROLLBACK%s\n", print_event_info->delimiter);
 
2501
#endif
 
2502
  }
 
2503
  if (temp_buf &&
 
2504
      print_event_info->base64_output_mode != BASE64_OUTPUT_NEVER &&
 
2505
      !print_event_info->short_form)
 
2506
  {
 
2507
    my_b_printf(&cache, "BINLOG '\n");
 
2508
    print_base64(&cache, print_event_info, false);
 
2509
    print_event_info->printed_fd_event= true;
 
2510
  }
 
2511
  return;
 
2512
}
 
2513
#endif /* MYSQL_CLIENT */
2017
2514
 
2018
2515
/*
2019
2516
  Start_log_event_v3::Start_log_event_v3()
2041
2538
  Start_log_event_v3::write()
2042
2539
*/
2043
2540
 
 
2541
#ifndef MYSQL_CLIENT
2044
2542
bool Start_log_event_v3::write(IO_CACHE* file)
2045
2543
{
2046
2544
  char buff[START_V3_HEADER_LEN];
2050
2548
    created= when= get_time();
2051
2549
  int4store(buff + ST_CREATED_OFFSET,created);
2052
2550
  return (write_header(file, sizeof(buff)) ||
2053
 
          my_b_safe_write(file, (unsigned char*) buff, sizeof(buff)));
 
2551
          my_b_safe_write(file, (uchar*) buff, sizeof(buff)));
2054
2552
}
2055
 
 
 
2553
#endif
 
2554
 
 
2555
 
 
2556
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2056
2557
 
2057
2558
/**
2058
2559
  Start_log_event_v3::do_apply_event() .
2060
2561
 
2061
2562
    IMPLEMENTATION
2062
2563
    - To handle the case where the master died without having time to write
2063
 
    DROP TEMPORARY Table, DO RELEASE_LOCK (prepared statements' deletion is
 
2564
    DROP TEMPORARY TABLE, DO RELEASE_LOCK (prepared statements' deletion is
2064
2565
    TODO), we clean up all temporary tables that we got, if we are sure we
2065
2566
    can (see below).
2066
2567
 
2117
2618
  }
2118
2619
  return(0);
2119
2620
}
 
2621
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
2120
2622
 
2121
2623
/***************************************************************************
2122
2624
       Format_description_log_event methods
2186
2688
      describes what those old master versions send.
2187
2689
    */
2188
2690
    if (binlog_ver==1)
2189
 
      my_stpcpy(server_version, server_ver ? server_ver : "3.23");
 
2691
      strmov(server_version, server_ver ? server_ver : "3.23");
2190
2692
    else
2191
 
      my_stpcpy(server_version, server_ver ? server_ver : "4.0");
 
2693
      strmov(server_version, server_ver ? server_ver : "4.0");
2192
2694
    common_header_len= binlog_ver==1 ? OLD_HEADER_LEN :
2193
2695
      LOG_EVENT_MINIMAL_HEADER_LEN;
2194
2696
    /*
2247
2749
 
2248
2750
Format_description_log_event::
2249
2751
Format_description_log_event(const char* buf,
2250
 
                             uint32_t event_len,
 
2752
                             uint event_len,
2251
2753
                             const
2252
2754
                             Format_description_log_event*
2253
2755
                             description_event)
2259
2761
  number_of_event_types=
2260
2762
    event_len-(LOG_EVENT_MINIMAL_HEADER_LEN+ST_COMMON_HEADER_LEN_OFFSET+1);
2261
2763
  /* If alloc fails, we'll detect it in is_valid() */
2262
 
  post_header_len= (uint8_t*) my_memdup((unsigned char*)buf+ST_COMMON_HEADER_LEN_OFFSET+1,
 
2764
  post_header_len= (uint8_t*) my_memdup((uchar*)buf+ST_COMMON_HEADER_LEN_OFFSET+1,
2263
2765
                                      number_of_event_types*
2264
2766
                                      sizeof(*post_header_len), MYF(0));
2265
2767
  calc_server_version_split();
2334
2836
    if (number_of_event_types != 22)
2335
2837
    {
2336
2838
      /* this makes is_valid() return false. */
2337
 
      free(post_header_len);
 
2839
      my_free(post_header_len, MYF(MY_ALLOW_ZERO_PTR));
2338
2840
      post_header_len= NULL;
2339
2841
      return;
2340
2842
    }
2368
2870
  return;
2369
2871
}
2370
2872
 
 
2873
#ifndef MYSQL_CLIENT
2371
2874
bool Format_description_log_event::write(IO_CACHE* file)
2372
2875
{
2373
2876
  /*
2374
2877
    We don't call Start_log_event_v3::write() because this would make 2
2375
2878
    my_b_safe_write().
2376
2879
  */
2377
 
  unsigned char buff[FORMAT_DESCRIPTION_HEADER_LEN];
 
2880
  uchar buff[FORMAT_DESCRIPTION_HEADER_LEN];
2378
2881
  int2store(buff + ST_BINLOG_VER_OFFSET,binlog_version);
2379
2882
  memcpy(buff + ST_SERVER_VER_OFFSET,server_version,ST_SERVER_VER_LEN);
2380
2883
  if (!dont_set_created)
2386
2889
  return (write_header(file, sizeof(buff)) ||
2387
2890
          my_b_safe_write(file, buff, sizeof(buff)));
2388
2891
}
2389
 
 
2390
 
 
 
2892
#endif
 
2893
 
 
2894
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2391
2895
int Format_description_log_event::do_apply_event(Relay_log_info const *rli)
2392
2896
{
2393
2897
  /*
2405
2909
  {
2406
2910
    /* This is not an error (XA is safe), just an information */
2407
2911
    rli->report(INFORMATION_LEVEL, 0,
2408
 
                _("Rolling back unfinished transaction (no COMMIT "
2409
 
                  "or ROLLBACK in relay log). A probable cause is that "
2410
 
                  "the master died while writing the transaction to "
2411
 
                  "its binary log, thus rolled back too."));
 
2912
                "Rolling back unfinished transaction (no COMMIT "
 
2913
                "or ROLLBACK in relay log). A probable cause is that "
 
2914
                "the master died while writing the transaction to "
 
2915
                "its binary log, thus rolled back too."); 
2412
2916
    const_cast<Relay_log_info*>(rli)->cleanup_context(thd, 1);
2413
2917
  }
2414
2918
  /*
2468
2972
  return Log_event::EVENT_SKIP_NOT;
2469
2973
}
2470
2974
 
 
2975
#endif
 
2976
 
2471
2977
 
2472
2978
/**
2473
2979
   Splits the event's 'server_version' string into three numeric pieces stored
2482
2988
{
2483
2989
  char *p= server_version, *r;
2484
2990
  ulong number;
2485
 
  for (uint32_t i= 0; i<=2; i++)
 
2991
  for (uint i= 0; i<=2; i++)
2486
2992
  {
2487
2993
    number= strtoul(p, &r, 10);
2488
 
    server_version_split[i]= (unsigned char)number;
2489
 
    assert(number < 256); // fit in unsigned char
 
2994
    server_version_split[i]= (uchar)number;
 
2995
    assert(number < 256); // fit in uchar
2490
2996
    p= r;
2491
2997
    assert(!((i == 0) && (*r != '.'))); // should be true in practice
2492
2998
    if (*r == '.')
2516
3022
  Load_log_event::pack_info()
2517
3023
*/
2518
3024
 
2519
 
uint32_t Load_log_event::get_query_buffer_length()
 
3025
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 
3026
uint Load_log_event::get_query_buffer_length()
2520
3027
{
2521
3028
  return
2522
3029
    5 + db_len + 3 +                        // "use DB; "
2523
3030
    18 + fname_len + 2 +                    // "LOAD DATA INFILE 'file''"
2524
3031
    7 +                                     // LOCAL
2525
3032
    9 +                                     // " REPLACE or IGNORE "
2526
 
    13 + table_name_len*2 +                 // "INTO Table `table`"
 
3033
    13 + table_name_len*2 +                 // "INTO TABLE `table`"
2527
3034
    21 + sql_ex.field_term_len*4 + 2 +      // " FIELDS TERMINATED BY 'str'"
2528
3035
    23 + sql_ex.enclosed_len*4 + 2 +        // " OPTIONALLY ENCLOSED BY 'str'"
2529
3036
    12 + sql_ex.escaped_len*4 + 2 +         // " ESCAPED BY 'str'"
2541
3048
 
2542
3049
  if (need_db && db && db_len)
2543
3050
  {
2544
 
    pos= my_stpcpy(pos, "use `");
 
3051
    pos= strmov(pos, "use `");
2545
3052
    memcpy(pos, db, db_len);
2546
 
    pos= my_stpcpy(pos+db_len, "`; ");
 
3053
    pos= strmov(pos+db_len, "`; ");
2547
3054
  }
2548
3055
 
2549
 
  pos= my_stpcpy(pos, "LOAD DATA ");
 
3056
  pos= strmov(pos, "LOAD DATA ");
2550
3057
 
2551
3058
  if (fn_start)
2552
3059
    *fn_start= pos;
2553
3060
 
2554
3061
  if (check_fname_outside_temp_buf())
2555
 
    pos= my_stpcpy(pos, "LOCAL ");
2556
 
  pos= my_stpcpy(pos, "INFILE '");
 
3062
    pos= strmov(pos, "LOCAL ");
 
3063
  pos= strmov(pos, "INFILE '");
2557
3064
  memcpy(pos, fname, fname_len);
2558
 
  pos= my_stpcpy(pos+fname_len, "' ");
 
3065
  pos= strmov(pos+fname_len, "' ");
2559
3066
 
2560
3067
  if (sql_ex.opt_flags & REPLACE_FLAG)
2561
 
    pos= my_stpcpy(pos, " REPLACE ");
 
3068
    pos= strmov(pos, " REPLACE ");
2562
3069
  else if (sql_ex.opt_flags & IGNORE_FLAG)
2563
 
    pos= my_stpcpy(pos, " IGNORE ");
 
3070
    pos= strmov(pos, " IGNORE ");
2564
3071
 
2565
 
  pos= my_stpcpy(pos ,"INTO");
 
3072
  pos= strmov(pos ,"INTO");
2566
3073
 
2567
3074
  if (fn_end)
2568
3075
    *fn_end= pos;
2569
3076
 
2570
 
  pos= my_stpcpy(pos ," Table `");
 
3077
  pos= strmov(pos ," TABLE `");
2571
3078
  memcpy(pos, table_name, table_name_len);
2572
3079
  pos+= table_name_len;
2573
3080
 
2574
3081
  /* We have to create all optinal fields as the default is not empty */
2575
 
  pos= my_stpcpy(pos, "` FIELDS TERMINATED BY ");
 
3082
  pos= strmov(pos, "` FIELDS TERMINATED BY ");
2576
3083
  pos= pretty_print_str(pos, sql_ex.field_term, sql_ex.field_term_len);
2577
3084
  if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
2578
 
    pos= my_stpcpy(pos, " OPTIONALLY ");
2579
 
  pos= my_stpcpy(pos, " ENCLOSED BY ");
 
3085
    pos= strmov(pos, " OPTIONALLY ");
 
3086
  pos= strmov(pos, " ENCLOSED BY ");
2580
3087
  pos= pretty_print_str(pos, sql_ex.enclosed, sql_ex.enclosed_len);
2581
3088
 
2582
 
  pos= my_stpcpy(pos, " ESCAPED BY ");
 
3089
  pos= strmov(pos, " ESCAPED BY ");
2583
3090
  pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
2584
3091
 
2585
 
  pos= my_stpcpy(pos, " LINES TERMINATED BY ");
 
3092
  pos= strmov(pos, " LINES TERMINATED BY ");
2586
3093
  pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
2587
3094
  if (sql_ex.line_start_len)
2588
3095
  {
2589
 
    pos= my_stpcpy(pos, " STARTING BY ");
 
3096
    pos= strmov(pos, " STARTING BY ");
2590
3097
    pos= pretty_print_str(pos, sql_ex.line_start, sql_ex.line_start_len);
2591
3098
  }
2592
3099
 
2593
3100
  if ((long) skip_lines > 0)
2594
3101
  {
2595
 
    pos= my_stpcpy(pos, " IGNORE ");
 
3102
    pos= strmov(pos, " IGNORE ");
2596
3103
    pos= int64_t10_to_str((int64_t) skip_lines, pos, 10);
2597
 
    pos= my_stpcpy(pos," LINES ");    
 
3104
    pos= strmov(pos," LINES ");    
2598
3105
  }
2599
3106
 
2600
3107
  if (num_fields)
2601
3108
  {
2602
 
    uint32_t i;
 
3109
    uint i;
2603
3110
    const char *field= fields;
2604
 
    pos= my_stpcpy(pos, " (");
 
3111
    pos= strmov(pos, " (");
2605
3112
    for (i = 0; i < num_fields; i++)
2606
3113
    {
2607
3114
      if (i)
2628
3135
    return;
2629
3136
  print_query(true, buf, &end, 0, 0);
2630
3137
  protocol->store(buf, end-buf, &my_charset_bin);
2631
 
  free(buf);
 
3138
  my_free(buf, MYF(0));
2632
3139
}
2633
 
 
 
3140
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
 
3141
 
 
3142
 
 
3143
#ifndef MYSQL_CLIENT
2634
3144
 
2635
3145
/*
2636
3146
  Load_log_event::write_data_header()
2645
3155
  buf[L_TBL_LEN_OFFSET] = (char)table_name_len;
2646
3156
  buf[L_DB_LEN_OFFSET] = (char)db_len;
2647
3157
  int4store(buf + L_NUM_FIELDS_OFFSET, num_fields);
2648
 
  return my_b_safe_write(file, (unsigned char*)buf, LOAD_HEADER_LEN) != 0;
 
3158
  return my_b_safe_write(file, (uchar*)buf, LOAD_HEADER_LEN) != 0;
2649
3159
}
2650
3160
 
2651
3161
 
2659
3169
    return 1;
2660
3170
  if (num_fields && fields && field_lens)
2661
3171
  {
2662
 
    if (my_b_safe_write(file, (unsigned char*)field_lens, num_fields) ||
2663
 
        my_b_safe_write(file, (unsigned char*)fields, field_block_len))
 
3172
    if (my_b_safe_write(file, (uchar*)field_lens, num_fields) ||
 
3173
        my_b_safe_write(file, (uchar*)fields, field_block_len))
2664
3174
      return 1;
2665
3175
  }
2666
 
  return (my_b_safe_write(file, (unsigned char*)table_name, table_name_len + 1) ||
2667
 
          my_b_safe_write(file, (unsigned char*)db, db_len + 1) ||
2668
 
          my_b_safe_write(file, (unsigned char*)fname, fname_len));
 
3176
  return (my_b_safe_write(file, (uchar*)table_name, table_name_len + 1) ||
 
3177
          my_b_safe_write(file, (uchar*)db, db_len + 1) ||
 
3178
          my_b_safe_write(file, (uchar*)fname, fname_len));
2669
3179
}
2670
3180
 
2671
3181
 
2746
3256
  while ((item = li++))
2747
3257
  {
2748
3258
    num_fields++;
2749
 
    unsigned char len = (unsigned char) strlen(item->name);
 
3259
    uchar len = (uchar) strlen(item->name);
2750
3260
    field_block_len += len + 1;
2751
3261
    fields_buf.append(item->name, len + 1);
2752
3262
    field_lens_buf.append((char*)&len, 1);
2753
3263
  }
2754
3264
 
2755
 
  field_lens = (const unsigned char*)field_lens_buf.ptr();
 
3265
  field_lens = (const uchar*)field_lens_buf.ptr();
2756
3266
  fields = fields_buf.ptr();
2757
3267
}
 
3268
#endif /* !MYSQL_CLIENT */
2758
3269
 
2759
3270
 
2760
3271
/**
2762
3273
    The caller must do buf[event_len] = 0 before he starts using the
2763
3274
    constructed event.
2764
3275
*/
2765
 
Load_log_event::Load_log_event(const char *buf, uint32_t event_len,
 
3276
Load_log_event::Load_log_event(const char *buf, uint event_len,
2766
3277
                               const Format_description_log_event *description_event)
2767
3278
  :Log_event(buf, description_event), num_fields(0), fields(0),
2768
3279
   field_lens(0),field_block_len(0),
2792
3303
                                   int body_offset,
2793
3304
                                   const Format_description_log_event *description_event)
2794
3305
{
2795
 
  uint32_t data_len;
 
3306
  uint data_len;
2796
3307
  char* buf_end = (char*)buf + event_len;
2797
3308
  /* this is the beginning of the post-header */
2798
3309
  const char* data_head = buf + description_event->common_header_len;
2809
3320
    Sql_ex.init() on success returns the pointer to the first byte after
2810
3321
    the sql_ex structure, which is the start of field lengths array.
2811
3322
  */
2812
 
  if (!(field_lens= (unsigned char*)sql_ex.init((char*)buf + body_offset,
 
3323
  if (!(field_lens= (uchar*)sql_ex.init((char*)buf + body_offset,
2813
3324
                                        buf_end,
2814
3325
                                        buf[EVENT_TYPE_OFFSET] != LOAD_EVENT)))
2815
3326
    return(1);
2817
3328
  data_len = event_len - body_offset;
2818
3329
  if (num_fields > data_len) // simple sanity check against corruption
2819
3330
    return(1);
2820
 
  for (uint32_t i = 0; i < num_fields; i++)
 
3331
  for (uint i = 0; i < num_fields; i++)
2821
3332
    field_block_len += (uint)field_lens[i] + 1;
2822
3333
 
2823
3334
  fields = (char*)field_lens + num_fields;
2831
3342
}
2832
3343
 
2833
3344
 
 
3345
/*
 
3346
  Load_log_event::print()
 
3347
*/
 
3348
 
 
3349
#ifdef MYSQL_CLIENT
 
3350
void Load_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
3351
{
 
3352
  print(file, print_event_info, 0);
 
3353
}
 
3354
 
 
3355
 
 
3356
void Load_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info,
 
3357
                           bool commented)
 
3358
{
 
3359
  Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
 
3360
 
 
3361
  if (!print_event_info->short_form)
 
3362
  {
 
3363
    print_header(&cache, print_event_info, false);
 
3364
    my_b_printf(&cache, "\tQuery\tthread_id=%ld\texec_time=%ld\n",
 
3365
                thread_id, exec_time);
 
3366
  }
 
3367
 
 
3368
  bool different_db= 1;
 
3369
  if (db)
 
3370
  {
 
3371
    /*
 
3372
      If the database is different from the one of the previous statement, we
 
3373
      need to print the "use" command, and we update the last_db.
 
3374
      But if commented, the "use" is going to be commented so we should not
 
3375
      update the last_db.
 
3376
    */
 
3377
    if ((different_db= memcmp(print_event_info->db, db, db_len + 1)) &&
 
3378
        !commented)
 
3379
      memcpy(print_event_info->db, db, db_len + 1);
 
3380
  }
 
3381
  
 
3382
  if (db && db[0] && different_db)
 
3383
    my_b_printf(&cache, "%suse %s%s\n", 
 
3384
            commented ? "# " : "",
 
3385
            db, print_event_info->delimiter);
 
3386
 
 
3387
  if (flags & LOG_EVENT_THREAD_SPECIFIC_F)
 
3388
    my_b_printf(&cache,"%sSET @@session.pseudo_thread_id=%lu%s\n",
 
3389
            commented ? "# " : "", (ulong)thread_id,
 
3390
            print_event_info->delimiter);
 
3391
  my_b_printf(&cache, "%sLOAD DATA ",
 
3392
              commented ? "# " : "");
 
3393
  if (check_fname_outside_temp_buf())
 
3394
    my_b_printf(&cache, "LOCAL ");
 
3395
  my_b_printf(&cache, "INFILE '%-*s' ", fname_len, fname);
 
3396
 
 
3397
  if (sql_ex.opt_flags & REPLACE_FLAG)
 
3398
    my_b_printf(&cache," REPLACE ");
 
3399
  else if (sql_ex.opt_flags & IGNORE_FLAG)
 
3400
    my_b_printf(&cache," IGNORE ");
 
3401
  
 
3402
  my_b_printf(&cache, "INTO TABLE `%s`", table_name);
 
3403
  my_b_printf(&cache, " FIELDS TERMINATED BY ");
 
3404
  pretty_print_str(&cache, sql_ex.field_term, sql_ex.field_term_len);
 
3405
 
 
3406
  if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
 
3407
    my_b_printf(&cache," OPTIONALLY ");
 
3408
  my_b_printf(&cache, " ENCLOSED BY ");
 
3409
  pretty_print_str(&cache, sql_ex.enclosed, sql_ex.enclosed_len);
 
3410
     
 
3411
  my_b_printf(&cache, " ESCAPED BY ");
 
3412
  pretty_print_str(&cache, sql_ex.escaped, sql_ex.escaped_len);
 
3413
     
 
3414
  my_b_printf(&cache," LINES TERMINATED BY ");
 
3415
  pretty_print_str(&cache, sql_ex.line_term, sql_ex.line_term_len);
 
3416
 
 
3417
 
 
3418
  if (sql_ex.line_start)
 
3419
  {
 
3420
    my_b_printf(&cache," STARTING BY ");
 
3421
    pretty_print_str(&cache, sql_ex.line_start, sql_ex.line_start_len);
 
3422
  }
 
3423
  if ((long) skip_lines > 0)
 
3424
    my_b_printf(&cache, " IGNORE %ld LINES", (long) skip_lines);
 
3425
 
 
3426
  if (num_fields)
 
3427
  {
 
3428
    uint i;
 
3429
    const char* field = fields;
 
3430
    my_b_printf(&cache, " (");
 
3431
    for (i = 0; i < num_fields; i++)
 
3432
    {
 
3433
      if (i)
 
3434
        my_b_printf(&cache, ",");
 
3435
      my_b_printf(&cache, field);
 
3436
          
 
3437
      field += field_lens[i]  + 1;
 
3438
    }
 
3439
    my_b_printf(&cache, ")");
 
3440
  }
 
3441
 
 
3442
  my_b_printf(&cache, "%s\n", print_event_info->delimiter);
 
3443
  return;
 
3444
}
 
3445
#endif /* MYSQL_CLIENT */
 
3446
 
 
3447
#ifndef MYSQL_CLIENT
 
3448
 
2834
3449
/**
2835
3450
  Load_log_event::set_fields()
2836
3451
 
2845
3460
                                List<Item> &field_list,
2846
3461
                                Name_resolution_context *context)
2847
3462
{
2848
 
  uint32_t i;
 
3463
  uint i;
2849
3464
  const char* field = fields;
2850
3465
  for (i= 0; i < num_fields; i++)
2851
3466
  {
2854
3469
    field+= field_lens[i]  + 1;
2855
3470
  }
2856
3471
}
2857
 
 
2858
 
 
 
3472
#endif /* !MYSQL_CLIENT */
 
3473
 
 
3474
 
 
3475
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2859
3476
/**
2860
3477
  Does the data loading job when executing a LOAD DATA on the slave.
2861
3478
 
2941
3558
  if (rpl_filter->db_ok(thd->db))
2942
3559
  {
2943
3560
    thd->set_time((time_t)when);
2944
 
    pthread_mutex_lock(&LOCK_thread_count);
 
3561
    VOID(pthread_mutex_lock(&LOCK_thread_count));
2945
3562
    thd->query_id = next_query_id();
2946
 
    pthread_mutex_unlock(&LOCK_thread_count);
 
3563
    VOID(pthread_mutex_unlock(&LOCK_thread_count));
2947
3564
    /*
2948
3565
      Initing thd->row_count is not necessary in theory as this variable has no
2949
3566
      influence in the case of the slave SQL thread (it is used to generate a
2952
3569
    */
2953
3570
    drizzle_reset_errors(thd, 0);
2954
3571
 
2955
 
    TableList tables;
 
3572
    TABLE_LIST tables;
2956
3573
    memset(&tables, 0, sizeof(tables));
2957
3574
    tables.db= thd->strmake(thd->db, thd->db_length);
2958
3575
    tables.alias = tables.table_name = (char*) table_name;
3071
3688
      if (thd->cuted_fields)
3072
3689
      {
3073
3690
        /* log_pos is the position of the LOAD event in the master log */
3074
 
        sql_print_warning(_("Slave: load data infile on table '%s' at "
 
3691
        sql_print_warning("Slave: load data infile on table '%s' at "
3075
3692
                          "log position %s in log '%s' produced %ld "
3076
 
                          "warning(s). Default database: '%s'"),
 
3693
                          "warning(s). Default database: '%s'",
3077
3694
                          (char*) table_name,
3078
3695
                          llstr(log_pos,llbuff), RPL_LOG_NAME, 
3079
3696
                          (ulong) thd->cuted_fields,
3097
3714
error:
3098
3715
  thd->net.vio = 0; 
3099
3716
  const char *remember_db= thd->db;
3100
 
  pthread_mutex_lock(&LOCK_thread_count);
 
3717
  VOID(pthread_mutex_lock(&LOCK_thread_count));
3101
3718
  thd->catalog= 0;
3102
3719
  thd->set_db(NULL, 0);                   /* will free the current database */
3103
3720
  thd->query= 0;
3104
3721
  thd->query_length= 0;
3105
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
3722
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
3106
3723
  close_thread_tables(thd);
3107
3724
 
3108
3725
  if (thd->is_slave_error)
3118
3735
    else
3119
3736
    {
3120
3737
      sql_errno=ER_UNKNOWN_ERROR;
3121
 
      err=ER(sql_errno);
 
3738
      err=ER(sql_errno);       
3122
3739
    }
3123
 
    rli->report(ERROR_LEVEL, sql_errno,
3124
 
                _("Error '%s' running LOAD DATA INFILE on table '%s'. "
3125
 
                  "Default database: '%s'"),
3126
 
                err, (char*)table_name, print_slave_db_safe(remember_db));
 
3740
    rli->report(ERROR_LEVEL, sql_errno,"\
 
3741
Error '%s' running LOAD DATA INFILE on table '%s'. Default database: '%s'",
 
3742
                    err, (char*)table_name, print_slave_db_safe(remember_db));
3127
3743
    free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
3128
3744
    return 1;
3129
3745
  }
3133
3749
  {
3134
3750
    char buf[256];
3135
3751
    snprintf(buf, sizeof(buf),
3136
 
             _("Running LOAD DATA INFILE on table '%-.64s'."
3137
 
               " Default database: '%-.64s'"),
 
3752
             "Running LOAD DATA INFILE on table '%-.64s'."
 
3753
             " Default database: '%-.64s'",
3138
3754
             (char*)table_name,
3139
3755
             print_slave_db_safe(remember_db));
3140
3756
 
3143
3759
    return 1;
3144
3760
  }
3145
3761
 
3146
 
  return ( use_rli_only_for_errors ? 0 : Log_event::do_apply_event(rli) );
 
3762
  return ( use_rli_only_for_errors ? 0 : Log_event::do_apply_event(rli) ); 
3147
3763
}
 
3764
#endif
3148
3765
 
3149
3766
 
3150
3767
/**************************************************************************
3155
3772
  Rotate_log_event::pack_info()
3156
3773
*/
3157
3774
 
 
3775
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3158
3776
void Rotate_log_event::pack_info(Protocol *protocol)
3159
3777
{
3160
3778
  char buf1[256], buf[22];
3165
3783
  tmp.append(llstr(pos,buf));
3166
3784
  protocol->store(tmp.ptr(), tmp.length(), &my_charset_bin);
3167
3785
}
 
3786
#endif
 
3787
 
 
3788
 
 
3789
/*
 
3790
  Rotate_log_event::print()
 
3791
*/
 
3792
 
 
3793
#ifdef MYSQL_CLIENT
 
3794
void Rotate_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
3795
{
 
3796
  char buf[22];
 
3797
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
3798
                               Write_on_release_cache::FLUSH_F);
 
3799
 
 
3800
  if (print_event_info->short_form)
 
3801
    return;
 
3802
  print_header(&cache, print_event_info, false);
 
3803
  my_b_printf(&cache, "\tRotate to ");
 
3804
  if (new_log_ident)
 
3805
    my_b_write(&cache, (uchar*) new_log_ident, (uint)ident_len);
 
3806
  my_b_printf(&cache, "  pos: %s\n", llstr(pos, buf));
 
3807
}
 
3808
#endif /* MYSQL_CLIENT */
 
3809
 
3168
3810
 
3169
3811
 
3170
3812
/*
3172
3814
*/
3173
3815
 
3174
3816
 
 
3817
#ifndef MYSQL_CLIENT
3175
3818
Rotate_log_event::Rotate_log_event(const char* new_log_ident_arg,
3176
 
                                   uint32_t ident_len_arg, uint64_t pos_arg,
3177
 
                                   uint32_t flags_arg)
 
3819
                                   uint ident_len_arg, uint64_t pos_arg,
 
3820
                                   uint flags_arg)
3178
3821
  :Log_event(), new_log_ident(new_log_ident_arg),
3179
3822
   pos(pos_arg),ident_len(ident_len_arg ? ident_len_arg :
3180
3823
                          (uint) strlen(new_log_ident_arg)), flags(flags_arg)
3183
3826
    new_log_ident= my_strndup(new_log_ident_arg, ident_len, MYF(MY_WME));
3184
3827
  return;
3185
3828
}
3186
 
 
3187
 
 
3188
 
Rotate_log_event::Rotate_log_event(const char* buf, uint32_t event_len,
 
3829
#endif
 
3830
 
 
3831
 
 
3832
Rotate_log_event::Rotate_log_event(const char* buf, uint event_len,
3189
3833
                                   const Format_description_log_event* description_event)
3190
3834
  :Log_event(buf, description_event) ,new_log_ident(0), flags(DUP_NAME)
3191
3835
{
3192
3836
  // The caller will ensure that event_len is what we have at EVENT_LEN_OFFSET
3193
3837
  uint8_t header_size= description_event->common_header_len;
3194
3838
  uint8_t post_header_len= description_event->post_header_len[ROTATE_EVENT-1];
3195
 
  uint32_t ident_offset;
 
3839
  uint ident_offset;
3196
3840
  if (event_len < header_size)
3197
3841
    return;
3198
3842
  buf += header_size;
3210
3854
  Rotate_log_event::write()
3211
3855
*/
3212
3856
 
 
3857
#ifndef MYSQL_CLIENT
3213
3858
bool Rotate_log_event::write(IO_CACHE* file)
3214
3859
{
3215
3860
  char buf[ROTATE_HEADER_LEN];
3216
3861
  int8store(buf + R_POS_OFFSET, pos);
3217
3862
  return (write_header(file, ROTATE_HEADER_LEN + ident_len) ||
3218
 
          my_b_safe_write(file, (unsigned char*)buf, ROTATE_HEADER_LEN) ||
3219
 
          my_b_safe_write(file, (unsigned char*)new_log_ident, (uint) ident_len));
 
3863
          my_b_safe_write(file, (uchar*)buf, ROTATE_HEADER_LEN) ||
 
3864
          my_b_safe_write(file, (uchar*)new_log_ident, (uint) ident_len));
3220
3865
}
3221
 
 
 
3866
#endif
 
3867
 
 
3868
 
 
3869
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3222
3870
 
3223
3871
/*
3224
3872
  Got a rotate log event from the master.
3300
3948
  return Log_event::EVENT_SKIP_NOT;             // To keep compiler happy
3301
3949
}
3302
3950
 
 
3951
#endif
 
3952
 
3303
3953
 
3304
3954
/**************************************************************************
3305
3955
        Intvar_log_event methods
3309
3959
  Intvar_log_event::pack_info()
3310
3960
*/
3311
3961
 
 
3962
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3312
3963
void Intvar_log_event::pack_info(Protocol *protocol)
3313
3964
{
3314
3965
  char buf[256], *pos;
3317
3968
  pos= int64_t10_to_str(val, pos, -10);
3318
3969
  protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
3319
3970
}
 
3971
#endif
3320
3972
 
3321
3973
 
3322
3974
/*
3351
4003
  Intvar_log_event::write()
3352
4004
*/
3353
4005
 
 
4006
#ifndef MYSQL_CLIENT
3354
4007
bool Intvar_log_event::write(IO_CACHE* file)
3355
4008
{
3356
 
  unsigned char buf[9];
3357
 
  buf[I_TYPE_OFFSET]= (unsigned char) type;
 
4009
  uchar buf[9];
 
4010
  buf[I_TYPE_OFFSET]= (uchar) type;
3358
4011
  int8store(buf + I_VAL_OFFSET, val);
3359
4012
  return (write_header(file, sizeof(buf)) ||
3360
4013
          my_b_safe_write(file, buf, sizeof(buf)));
3361
4014
}
 
4015
#endif
3362
4016
 
3363
4017
 
3364
4018
/*
3365
4019
  Intvar_log_event::print()
3366
4020
*/
3367
4021
 
 
4022
#ifdef MYSQL_CLIENT
 
4023
void Intvar_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
4024
{
 
4025
  char llbuff[22];
 
4026
  const char *msg;
 
4027
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
4028
                               Write_on_release_cache::FLUSH_F);
 
4029
 
 
4030
  if (!print_event_info->short_form)
 
4031
  {
 
4032
    print_header(&cache, print_event_info, false);
 
4033
    my_b_printf(&cache, "\tIntvar\n");
 
4034
  }
 
4035
 
 
4036
  my_b_printf(&cache, "SET ");
 
4037
  switch (type) {
 
4038
  case LAST_INSERT_ID_EVENT:
 
4039
    msg="LAST_INSERT_ID";
 
4040
    break;
 
4041
  case INSERT_ID_EVENT:
 
4042
    msg="INSERT_ID";
 
4043
    break;
 
4044
  case INVALID_INT_EVENT:
 
4045
  default: // cannot happen
 
4046
    msg="INVALID_INT";
 
4047
    break;
 
4048
  }
 
4049
  my_b_printf(&cache, "%s=%s%s\n",
 
4050
              msg, llstr(val,llbuff), print_event_info->delimiter);
 
4051
}
 
4052
#endif
 
4053
 
 
4054
 
3368
4055
/*
3369
4056
  Intvar_log_event::do_apply_event()
3370
4057
*/
3371
4058
 
 
4059
#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
3372
4060
int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
3373
4061
{
3374
4062
  /*
3410
4098
  return continue_group(rli);
3411
4099
}
3412
4100
 
 
4101
#endif
 
4102
 
3413
4103
 
3414
4104
/**************************************************************************
3415
4105
  Rand_log_event methods
3416
4106
**************************************************************************/
3417
4107
 
 
4108
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3418
4109
void Rand_log_event::pack_info(Protocol *protocol)
3419
4110
{
3420
4111
  char buf1[256], *pos;
3421
 
  pos= my_stpcpy(buf1,"rand_seed1=");
 
4112
  pos= strmov(buf1,"rand_seed1=");
3422
4113
  pos= int10_to_str((long) seed1, pos, 10);
3423
 
  pos= my_stpcpy(pos, ",rand_seed2=");
 
4114
  pos= strmov(pos, ",rand_seed2=");
3424
4115
  pos= int10_to_str((long) seed2, pos, 10);
3425
4116
  protocol->store(buf1, (uint) (pos-buf1), &my_charset_bin);
3426
4117
}
 
4118
#endif
3427
4119
 
3428
4120
 
3429
4121
Rand_log_event::Rand_log_event(const char* buf,
3436
4128
}
3437
4129
 
3438
4130
 
 
4131
#ifndef MYSQL_CLIENT
3439
4132
bool Rand_log_event::write(IO_CACHE* file)
3440
4133
{
3441
 
  unsigned char buf[16];
 
4134
  uchar buf[16];
3442
4135
  int8store(buf + RAND_SEED1_OFFSET, seed1);
3443
4136
  int8store(buf + RAND_SEED2_OFFSET, seed2);
3444
4137
  return (write_header(file, sizeof(buf)) ||
3445
4138
          my_b_safe_write(file, buf, sizeof(buf)));
3446
4139
}
3447
 
 
3448
 
 
 
4140
#endif
 
4141
 
 
4142
 
 
4143
#ifdef MYSQL_CLIENT
 
4144
void Rand_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
4145
{
 
4146
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
4147
                               Write_on_release_cache::FLUSH_F);
 
4148
 
 
4149
  char llbuff[22],llbuff2[22];
 
4150
  if (!print_event_info->short_form)
 
4151
  {
 
4152
    print_header(&cache, print_event_info, false);
 
4153
    my_b_printf(&cache, "\tRand\n");
 
4154
  }
 
4155
  my_b_printf(&cache, "SET @@RAND_SEED1=%s, @@RAND_SEED2=%s%s\n",
 
4156
              llstr(seed1, llbuff),llstr(seed2, llbuff2),
 
4157
              print_event_info->delimiter);
 
4158
}
 
4159
#endif /* MYSQL_CLIENT */
 
4160
 
 
4161
 
 
4162
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3449
4163
int Rand_log_event::do_apply_event(Relay_log_info const *rli)
3450
4164
{
3451
4165
  /*
3480
4194
  return continue_group(rli);
3481
4195
}
3482
4196
 
 
4197
#endif /* !MYSQL_CLIENT */
 
4198
 
3483
4199
 
3484
4200
/**************************************************************************
3485
4201
  Xid_log_event methods
3486
4202
**************************************************************************/
3487
4203
 
 
4204
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3488
4205
void Xid_log_event::pack_info(Protocol *protocol)
3489
4206
{
3490
4207
  char buf[128], *pos;
3491
 
  pos= my_stpcpy(buf, "COMMIT /* xid=");
 
4208
  pos= strmov(buf, "COMMIT /* xid=");
3492
4209
  pos= int64_t10_to_str(xid, pos, 10);
3493
 
  pos= my_stpcpy(pos, " */");
 
4210
  pos= strmov(pos, " */");
3494
4211
  protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
3495
4212
}
 
4213
#endif
3496
4214
 
3497
4215
/**
3498
4216
  @note
3513
4231
}
3514
4232
 
3515
4233
 
 
4234
#ifndef MYSQL_CLIENT
3516
4235
bool Xid_log_event::write(IO_CACHE* file)
3517
4236
{
3518
4237
  return write_header(file, sizeof(xid)) ||
3519
 
         my_b_safe_write(file, (unsigned char*) &xid, sizeof(xid));
3520
 
}
3521
 
 
3522
 
 
 
4238
         my_b_safe_write(file, (uchar*) &xid, sizeof(xid));
 
4239
}
 
4240
#endif
 
4241
 
 
4242
 
 
4243
#ifdef MYSQL_CLIENT
 
4244
void Xid_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
4245
{
 
4246
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
4247
                               Write_on_release_cache::FLUSH_F);
 
4248
 
 
4249
  if (!print_event_info->short_form)
 
4250
  {
 
4251
    char buf[64];
 
4252
    int64_t10_to_str(xid, buf, 10);
 
4253
 
 
4254
    print_header(&cache, print_event_info, false);
 
4255
    my_b_printf(&cache, "\tXid = %s\n", buf);
 
4256
  }
 
4257
  my_b_printf(&cache, "COMMIT%s\n", print_event_info->delimiter);
 
4258
}
 
4259
#endif /* MYSQL_CLIENT */
 
4260
 
 
4261
 
 
4262
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3523
4263
int Xid_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
3524
4264
{
 
4265
  /* For a slave Xid_log_event is COMMIT */
 
4266
  general_log_print(thd, COM_QUERY,
 
4267
                    "COMMIT /* implicit, from Xid_log_event */");
3525
4268
  return end_trans(thd, COMMIT);
3526
4269
}
3527
4270
 
3534
4277
  }
3535
4278
  return(Log_event::do_shall_skip(rli));
3536
4279
}
 
4280
#endif /* !MYSQL_CLIENT */
3537
4281
 
3538
4282
 
3539
4283
/**************************************************************************
3540
4284
  User_var_log_event methods
3541
4285
**************************************************************************/
3542
4286
 
 
4287
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3543
4288
void User_var_log_event::pack_info(Protocol* protocol)
3544
4289
{
3545
4290
  char *buf= 0;
3546
 
  uint32_t val_offset= 4 + name_len;
3547
 
  uint32_t event_len= val_offset;
 
4291
  uint val_offset= 4 + name_len;
 
4292
  uint event_len= val_offset;
3548
4293
 
3549
4294
  if (is_null)
3550
4295
  {
3551
4296
    if (!(buf= (char*) my_malloc(val_offset + 5, MYF(MY_WME))))
3552
4297
      return;
3553
 
    my_stpcpy(buf + val_offset, "NULL");
 
4298
    strmov(buf + val_offset, "NULL");
3554
4299
    event_len= val_offset + 4;
3555
4300
  }
3556
4301
  else
3577
4322
        return;
3578
4323
      String str(buf+val_offset, DECIMAL_MAX_STR_LENGTH, &my_charset_bin);
3579
4324
      my_decimal dec;
3580
 
      binary2my_decimal(E_DEC_FATAL_ERROR, (unsigned char*) (val+2), &dec, val[0],
 
4325
      binary2my_decimal(E_DEC_FATAL_ERROR, (uchar*) (val+2), &dec, val[0],
3581
4326
                        val[1]);
3582
4327
      my_decimal2string(E_DEC_FATAL_ERROR, &dec, 0, 0, 0, &str);
3583
4328
      event_len= str.length() + val_offset;
3592
4337
        return;
3593
4338
      if (!(cs= get_charset(charset_number, MYF(0))))
3594
4339
      {
3595
 
        my_stpcpy(buf+val_offset, "???");
 
4340
        strmov(buf+val_offset, "???");
3596
4341
        event_len+= 3;
3597
4342
      }
3598
4343
      else
3599
4344
      {
3600
 
        char *p= strxmov(buf + val_offset, "_", cs->csname, " ", NULL);
 
4345
        char *p= strxmov(buf + val_offset, "_", cs->csname, " ", NullS);
3601
4346
        p= str_to_hex(p, val, val_len);
3602
 
        p= strxmov(p, " COLLATE ", cs->name, NULL);
 
4347
        p= strxmov(p, " COLLATE ", cs->name, NullS);
3603
4348
        event_len= p-buf;
3604
4349
      }
3605
4350
      break;
3615
4360
  buf[2+name_len]= '`';
3616
4361
  buf[3+name_len]= '=';
3617
4362
  protocol->store(buf, event_len, &my_charset_bin);
3618
 
  free(buf);
 
4363
  my_free(buf, MYF(0));
3619
4364
}
 
4365
#endif /* !MYSQL_CLIENT */
3620
4366
 
3621
4367
 
3622
4368
User_var_log_event::
3648
4394
}
3649
4395
 
3650
4396
 
 
4397
#ifndef MYSQL_CLIENT
3651
4398
bool User_var_log_event::write(IO_CACHE* file)
3652
4399
{
3653
4400
  char buf[UV_NAME_LEN_SIZE];
3654
4401
  char buf1[UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE + 
3655
4402
            UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE];
3656
 
  unsigned char buf2[(8 > DECIMAL_MAX_FIELD_SIZE + 2) ? 8 : DECIMAL_MAX_FIELD_SIZE +2], *pos= buf2;
3657
 
  uint32_t buf1_length;
 
4403
  uchar buf2[max(8, DECIMAL_MAX_FIELD_SIZE + 2)], *pos= buf2;
 
4404
  uint buf1_length;
3658
4405
  ulong event_length;
3659
4406
 
3660
4407
  int4store(buf, name_len);
3687
4434
      break;
3688
4435
    }
3689
4436
    case STRING_RESULT:
3690
 
      pos= (unsigned char*) val;
 
4437
      pos= (uchar*) val;
3691
4438
      break;
3692
4439
    case ROW_RESULT:
3693
4440
    default:
3702
4449
  event_length= sizeof(buf)+ name_len + buf1_length + val_len;
3703
4450
 
3704
4451
  return (write_header(file, event_length) ||
3705
 
          my_b_safe_write(file, (unsigned char*) buf, sizeof(buf))   ||
3706
 
          my_b_safe_write(file, (unsigned char*) name, name_len)     ||
3707
 
          my_b_safe_write(file, (unsigned char*) buf1, buf1_length) ||
 
4452
          my_b_safe_write(file, (uchar*) buf, sizeof(buf))   ||
 
4453
          my_b_safe_write(file, (uchar*) name, name_len)     ||
 
4454
          my_b_safe_write(file, (uchar*) buf1, buf1_length) ||
3708
4455
          my_b_safe_write(file, pos, val_len));
3709
4456
}
3710
 
 
 
4457
#endif
 
4458
 
 
4459
 
 
4460
/*
 
4461
  User_var_log_event::print()
 
4462
*/
 
4463
 
 
4464
#ifdef MYSQL_CLIENT
 
4465
void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
4466
{
 
4467
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
4468
                               Write_on_release_cache::FLUSH_F);
 
4469
 
 
4470
  if (!print_event_info->short_form)
 
4471
  {
 
4472
    print_header(&cache, print_event_info, false);
 
4473
    my_b_printf(&cache, "\tUser_var\n");
 
4474
  }
 
4475
 
 
4476
  my_b_printf(&cache, "SET @`");
 
4477
  my_b_write(&cache, (uchar*) name, (uint) (name_len));
 
4478
  my_b_printf(&cache, "`");
 
4479
 
 
4480
  if (is_null)
 
4481
  {
 
4482
    my_b_printf(&cache, ":=NULL%s\n", print_event_info->delimiter);
 
4483
  }
 
4484
  else
 
4485
  {
 
4486
    switch (type) {
 
4487
    case REAL_RESULT:
 
4488
      double real_val;
 
4489
      char real_buf[FMT_G_BUFSIZE(14)];
 
4490
      float8get(real_val, val);
 
4491
      sprintf(real_buf, "%.14g", real_val);
 
4492
      my_b_printf(&cache, ":=%s%s\n", real_buf, print_event_info->delimiter);
 
4493
      break;
 
4494
    case INT_RESULT:
 
4495
      char int_buf[22];
 
4496
      int64_t10_to_str(uint8korr(val), int_buf, -10);
 
4497
      my_b_printf(&cache, ":=%s%s\n", int_buf, print_event_info->delimiter);
 
4498
      break;
 
4499
    case DECIMAL_RESULT:
 
4500
    {
 
4501
      char str_buf[200];
 
4502
      int str_len= sizeof(str_buf) - 1;
 
4503
      int precision= (int)val[0];
 
4504
      int scale= (int)val[1];
 
4505
      decimal_digit_t dec_buf[10];
 
4506
      decimal_t dec;
 
4507
      dec.len= 10;
 
4508
      dec.buf= dec_buf;
 
4509
 
 
4510
      bin2decimal((uchar*) val+2, &dec, precision, scale);
 
4511
      decimal2string(&dec, str_buf, &str_len, 0, 0, 0);
 
4512
      str_buf[str_len]= 0;
 
4513
      my_b_printf(&cache, ":=%s%s\n", str_buf, print_event_info->delimiter);
 
4514
      break;
 
4515
    }
 
4516
    case STRING_RESULT:
 
4517
    {
 
4518
      /*
 
4519
        Let's express the string in hex. That's the most robust way. If we
 
4520
        print it in character form instead, we need to escape it with
 
4521
        character_set_client which we don't know (we will know it in 5.0, but
 
4522
        in 4.1 we don't know it easily when we are printing
 
4523
        User_var_log_event). Explanation why we would need to bother with
 
4524
        character_set_client (quoting Bar):
 
4525
        > Note, the parser doesn't switch to another unescaping mode after
 
4526
        > it has met a character set introducer.
 
4527
        > For example, if an SJIS client says something like:
 
4528
        > SET @a= _ucs2 \0a\0b'
 
4529
        > the string constant is still unescaped according to SJIS, not
 
4530
        > according to UCS2.
 
4531
      */
 
4532
      char *hex_str;
 
4533
      const CHARSET_INFO *cs;
 
4534
 
 
4535
      if (!(hex_str= (char *)my_alloca(2*val_len+1+2))) // 2 hex digits / byte
 
4536
        break; // no error, as we are 'void'
 
4537
      str_to_hex(hex_str, val, val_len);
 
4538
      /*
 
4539
        For proper behaviour when mysqlbinlog|mysql, we need to explicitely
 
4540
        specify the variable's collation. It will however cause problems when
 
4541
        people want to mysqlbinlog|mysql into another server not supporting the
 
4542
        character set. But there's not much to do about this and it's unlikely.
 
4543
      */
 
4544
      if (!(cs= get_charset(charset_number, MYF(0))))
 
4545
        /*
 
4546
          Generate an unusable command (=> syntax error) is probably the best
 
4547
          thing we can do here.
 
4548
        */
 
4549
        my_b_printf(&cache, ":=???%s\n", print_event_info->delimiter);
 
4550
      else
 
4551
        my_b_printf(&cache, ":=_%s %s COLLATE `%s`%s\n",
 
4552
                    cs->csname, hex_str, cs->name,
 
4553
                    print_event_info->delimiter);
 
4554
      my_afree(hex_str);
 
4555
    }
 
4556
      break;
 
4557
    case ROW_RESULT:
 
4558
    default:
 
4559
      assert(1);
 
4560
      return;
 
4561
    }
 
4562
  }
 
4563
}
 
4564
#endif
3711
4565
 
3712
4566
 
3713
4567
/*
3714
4568
  User_var_log_event::do_apply_event()
3715
4569
*/
3716
4570
 
 
4571
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3717
4572
int User_var_log_event::do_apply_event(Relay_log_info const *rli)
3718
4573
{
3719
4574
  Item *it= 0;
3753
4608
      break;
3754
4609
    case DECIMAL_RESULT:
3755
4610
    {
3756
 
      Item_decimal *dec= new Item_decimal((unsigned char*) val+2, val[0], val[1]);
 
4611
      Item_decimal *dec= new Item_decimal((uchar*) val+2, val[0], val[1]);
3757
4612
      it= dec;
3758
4613
      val= (char *)dec->val_decimal(NULL);
3759
4614
      val_len= sizeof(my_decimal);
3804
4659
  */
3805
4660
  return continue_group(rli);
3806
4661
}
 
4662
#endif /* !MYSQL_CLIENT */
3807
4663
 
3808
4664
 
3809
4665
/**************************************************************************
3810
4666
  Slave_log_event methods
3811
4667
**************************************************************************/
3812
4668
 
 
4669
#ifdef HAVE_REPLICATION
 
4670
#ifdef MYSQL_CLIENT
 
4671
void Unknown_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info)
 
4672
{
 
4673
  Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
 
4674
 
 
4675
  if (print_event_info->short_form)
 
4676
    return;
 
4677
  print_header(&cache, print_event_info, false);
 
4678
  my_b_printf(&cache, "\n# %s", "Unknown event\n");
 
4679
}
 
4680
#endif  
 
4681
 
 
4682
#ifndef MYSQL_CLIENT
3813
4683
void Slave_log_event::pack_info(Protocol *protocol)
3814
4684
{
3815
4685
  char buf[256+HOSTNAME_LENGTH], *pos;
3816
 
  pos= my_stpcpy(buf, "host=");
3817
 
  pos= my_stpncpy(pos, master_host, HOSTNAME_LENGTH);
3818
 
  pos= my_stpcpy(pos, ",port=");
 
4686
  pos= strmov(buf, "host=");
 
4687
  pos= strnmov(pos, master_host, HOSTNAME_LENGTH);
 
4688
  pos= strmov(pos, ",port=");
3819
4689
  pos= int10_to_str((long) master_port, pos, 10);
3820
 
  pos= my_stpcpy(pos, ",log=");
3821
 
  pos= my_stpcpy(pos, master_log);
3822
 
  pos= my_stpcpy(pos, ",pos=");
 
4690
  pos= strmov(pos, ",log=");
 
4691
  pos= strmov(pos, master_log);
 
4692
  pos= strmov(pos, ",pos=");
3823
4693
  pos= int64_t10_to_str(master_pos, pos, 10);
3824
4694
  protocol->store(buf, pos-buf, &my_charset_bin);
3825
4695
}
3826
 
 
3827
 
 
 
4696
#endif /* !MYSQL_CLIENT */
 
4697
 
 
4698
 
 
4699
#ifndef MYSQL_CLIENT
3828
4700
/**
3829
4701
  @todo
3830
4702
  re-write this better without holding both locks at the same time
3854
4726
    master_pos = rli->group_master_log_pos;
3855
4727
  }
3856
4728
  else
3857
 
    sql_print_error(_("Out of memory while recording slave event"));
 
4729
    sql_print_error("Out of memory while recording slave event");
3858
4730
  pthread_mutex_unlock(&rli->data_lock);
3859
4731
  pthread_mutex_unlock(&mi->data_lock);
3860
4732
  return;
3861
4733
}
 
4734
#endif /* !MYSQL_CLIENT */
3862
4735
 
3863
4736
 
3864
4737
Slave_log_event::~Slave_log_event()
3865
4738
{
3866
 
  free(mem_pool);
3867
 
}
 
4739
  my_free(mem_pool, MYF(MY_ALLOW_ZERO_PTR));
 
4740
}
 
4741
 
 
4742
 
 
4743
#ifdef MYSQL_CLIENT
 
4744
void Slave_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
4745
{
 
4746
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
4747
 
 
4748
  char llbuff[22];
 
4749
  if (print_event_info->short_form)
 
4750
    return;
 
4751
  print_header(&cache, print_event_info, false);
 
4752
  my_b_printf(&cache, "\n\
 
4753
Slave: master_host: '%s'  master_port: %d  master_log: '%s'  master_pos: %s\n",
 
4754
          master_host, master_port, master_log, llstr(master_pos, llbuff));
 
4755
}
 
4756
#endif /* MYSQL_CLIENT */
3868
4757
 
3869
4758
 
3870
4759
int Slave_log_event::get_data_size()
3873
4762
}
3874
4763
 
3875
4764
 
 
4765
#ifndef MYSQL_CLIENT
3876
4766
bool Slave_log_event::write(IO_CACHE* file)
3877
4767
{
3878
4768
  ulong event_length= get_data_size();
3881
4771
  // log and host are already there
3882
4772
 
3883
4773
  return (write_header(file, event_length) ||
3884
 
          my_b_safe_write(file, (unsigned char*) mem_pool, event_length));
 
4774
          my_b_safe_write(file, (uchar*) mem_pool, event_length));
3885
4775
}
 
4776
#endif
3886
4777
 
3887
4778
 
3888
4779
void Slave_log_event::init_from_mem_pool(int data_size)
3903
4794
 
3904
4795
 
3905
4796
/** This code is not used, so has not been updated to be format-tolerant. */
3906
 
Slave_log_event::Slave_log_event(const char* buf, uint32_t event_len)
 
4797
Slave_log_event::Slave_log_event(const char* buf, uint event_len)
3907
4798
  :Log_event(buf,0) /*unused event*/ ,mem_pool(0),master_host(0)
3908
4799
{
3909
4800
  if (event_len < LOG_EVENT_HEADER_LEN)
3917
4808
}
3918
4809
 
3919
4810
 
 
4811
#ifndef MYSQL_CLIENT
3920
4812
int Slave_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
3921
4813
{
3922
4814
  if (mysql_bin_log.is_open())
3923
4815
    mysql_bin_log.write(this);
3924
4816
  return 0;
3925
4817
}
 
4818
#endif /* !MYSQL_CLIENT */
3926
4819
 
3927
4820
 
3928
4821
/**************************************************************************
3930
4823
**************************************************************************/
3931
4824
 
3932
4825
/*
 
4826
  Stop_log_event::print()
 
4827
*/
 
4828
 
 
4829
#ifdef MYSQL_CLIENT
 
4830
void Stop_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
4831
{
 
4832
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
4833
                               Write_on_release_cache::FLUSH_F);
 
4834
 
 
4835
  if (print_event_info->short_form)
 
4836
    return;
 
4837
 
 
4838
  print_header(&cache, print_event_info, false);
 
4839
  my_b_printf(&cache, "\tStop\n");
 
4840
}
 
4841
#endif /* MYSQL_CLIENT */
 
4842
 
 
4843
 
 
4844
#ifndef MYSQL_CLIENT
 
4845
/*
3933
4846
  The master stopped.  We used to clean up all temporary tables but
3934
4847
  this is useless as, as the master has shut down properly, it has
3935
 
  written all DROP TEMPORARY Table (prepared statements' deletion is
 
4848
  written all DROP TEMPORARY TABLE (prepared statements' deletion is
3936
4849
  TODO only when we binlog prep stmts).  We used to clean up
3937
4850
  slave_load_tmpdir, but this is useless as it has been cleared at the
3938
4851
  end of LOAD DATA INFILE.  So we have nothing to do here.  The place
3959
4872
  return 0;
3960
4873
}
3961
4874
 
 
4875
#endif /* !MYSQL_CLIENT */
 
4876
#endif /* HAVE_REPLICATION */
 
4877
 
3962
4878
 
3963
4879
/**************************************************************************
3964
4880
        Create_file_log_event methods
3968
4884
  Create_file_log_event ctor
3969
4885
*/
3970
4886
 
 
4887
#ifndef MYSQL_CLIENT
3971
4888
Create_file_log_event::
3972
4889
Create_file_log_event(THD* thd_arg, sql_exchange* ex,
3973
4890
                      const char* db_arg, const char* table_name_arg,
3974
4891
                      List<Item>& fields_arg, enum enum_duplicates handle_dup,
3975
4892
                      bool ignore,
3976
 
                      unsigned char* block_arg, uint32_t block_len_arg, bool using_trans)
 
4893
                      uchar* block_arg, uint block_len_arg, bool using_trans)
3977
4894
  :Load_log_event(thd_arg,ex,db_arg,table_name_arg,fields_arg,handle_dup, ignore,
3978
4895
                  using_trans),
3979
4896
   fake_base(0), block(block_arg), event_buf(0), block_len(block_len_arg),
3993
4910
  bool res;
3994
4911
  if ((res= Load_log_event::write_data_body(file)) || fake_base)
3995
4912
    return res;
3996
 
  return (my_b_safe_write(file, (unsigned char*) "", 1) ||
3997
 
          my_b_safe_write(file, (unsigned char*) block, block_len));
 
4913
  return (my_b_safe_write(file, (uchar*) "", 1) ||
 
4914
          my_b_safe_write(file, (uchar*) block, block_len));
3998
4915
}
3999
4916
 
4000
4917
 
4005
4922
bool Create_file_log_event::write_data_header(IO_CACHE* file)
4006
4923
{
4007
4924
  bool res;
4008
 
  unsigned char buf[CREATE_FILE_HEADER_LEN];
 
4925
  uchar buf[CREATE_FILE_HEADER_LEN];
4009
4926
  if ((res= Load_log_event::write_data_header(file)) || fake_base)
4010
4927
    return res;
4011
4928
  int4store(buf + CF_FILE_ID_OFFSET, file_id);
4026
4943
  return res;
4027
4944
}
4028
4945
 
 
4946
#endif /* !MYSQL_CLIENT */
 
4947
 
4029
4948
/*
4030
4949
  Create_file_log_event ctor
4031
4950
*/
4032
4951
 
4033
 
Create_file_log_event::Create_file_log_event(const char* buf, uint32_t len,
 
4952
Create_file_log_event::Create_file_log_event(const char* buf, uint len,
4034
4953
                                             const Format_description_log_event* description_event)
4035
4954
  :Load_log_event(buf,0,description_event),fake_base(0),block(0),inited_from_old(0)
4036
4955
{
4037
 
  uint32_t block_offset;
4038
 
  uint32_t header_len= description_event->common_header_len;
 
4956
  uint block_offset;
 
4957
  uint header_len= description_event->common_header_len;
4039
4958
  uint8_t load_header_len= description_event->post_header_len[LOAD_EVENT-1];
4040
4959
  uint8_t create_file_header_len= description_event->post_header_len[CREATE_FILE_EVENT-1];
4041
4960
  if (!(event_buf= (char*) my_memdup(buf, len, MYF(MY_WME))) ||
4068
4987
                   create_file_header_len + 1);
4069
4988
    if (len < block_offset)
4070
4989
      return;
4071
 
    block = (unsigned char*)buf + block_offset;
 
4990
    block = (uchar*)buf + block_offset;
4072
4991
    block_len = len - block_offset;
4073
4992
  }
4074
4993
  else
4081
5000
 
4082
5001
 
4083
5002
/*
 
5003
  Create_file_log_event::print()
 
5004
*/
 
5005
 
 
5006
#ifdef MYSQL_CLIENT
 
5007
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info,
 
5008
                                  bool enable_local)
 
5009
{
 
5010
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
5011
 
 
5012
  if (print_event_info->short_form)
 
5013
  {
 
5014
    if (enable_local && check_fname_outside_temp_buf())
 
5015
      Load_log_event::print(file, print_event_info);
 
5016
    return;
 
5017
  }
 
5018
 
 
5019
  if (enable_local)
 
5020
  {
 
5021
    Load_log_event::print(file, print_event_info,
 
5022
                          !check_fname_outside_temp_buf());
 
5023
    /* 
 
5024
       That one is for "file_id: etc" below: in mysqlbinlog we want the #, in
 
5025
       SHOW BINLOG EVENTS we don't.
 
5026
    */
 
5027
    my_b_printf(&cache, "#"); 
 
5028
  }
 
5029
 
 
5030
  my_b_printf(&cache, " file_id: %d  block_len: %d\n", file_id, block_len);
 
5031
}
 
5032
 
 
5033
 
 
5034
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
5035
{
 
5036
  print(file, print_event_info, 0);
 
5037
}
 
5038
#endif /* MYSQL_CLIENT */
 
5039
 
 
5040
 
 
5041
/*
4084
5042
  Create_file_log_event::pack_info()
4085
5043
*/
4086
5044
 
 
5045
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4087
5046
void Create_file_log_event::pack_info(Protocol *protocol)
4088
5047
{
4089
5048
  char buf[NAME_LEN*2 + 30 + 21*2], *pos;
4090
 
  pos= my_stpcpy(buf, "db=");
 
5049
  pos= strmov(buf, "db=");
4091
5050
  memcpy(pos, db, db_len);
4092
 
  pos= my_stpcpy(pos + db_len, ";table=");
 
5051
  pos= strmov(pos + db_len, ";table=");
4093
5052
  memcpy(pos, table_name, table_name_len);
4094
 
  pos= my_stpcpy(pos + table_name_len, ";file_id=");
 
5053
  pos= strmov(pos + table_name_len, ";file_id=");
4095
5054
  pos= int10_to_str((long) file_id, pos, 10);
4096
 
  pos= my_stpcpy(pos, ";block_len=");
 
5055
  pos= strmov(pos, ";block_len=");
4097
5056
  pos= int10_to_str((long) block_len, pos, 10);
4098
5057
  protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
4099
5058
}
 
5059
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4100
5060
 
4101
5061
 
4102
5062
/*
4103
5063
  Create_file_log_event::do_apply_event()
4104
5064
*/
4105
5065
 
 
5066
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4106
5067
int Create_file_log_event::do_apply_event(Relay_log_info const *rli)
4107
5068
{
4108
5069
  char proc_info[17+FN_REFLEN+10], *fname_buf;
4112
5073
  int error = 1;
4113
5074
 
4114
5075
  memset(&file, 0, sizeof(file));
4115
 
  fname_buf= my_stpcpy(proc_info, "Making temp file ");
 
5076
  fname_buf= strmov(proc_info, "Making temp file ");
4116
5077
  ext= slave_load_file_stem(fname_buf, file_id, server_id, ".info");
4117
5078
  thd_proc_info(thd, proc_info);
4118
5079
  my_delete(fname_buf, MYF(0)); // old copy may exist already
4123
5084
                    MYF(MY_WME|MY_NABP)))
4124
5085
  {
4125
5086
    rli->report(ERROR_LEVEL, my_errno,
4126
 
                _("Error in Create_file event: could not open file '%s'"),
 
5087
                "Error in Create_file event: could not open file '%s'",
4127
5088
                fname_buf);
4128
5089
    goto err;
4129
5090
  }
4130
5091
  
4131
5092
  // a trick to avoid allocating another buffer
4132
5093
  fname= fname_buf;
4133
 
  fname_len= (uint) (my_stpcpy(ext, ".data") - fname);
 
5094
  fname_len= (uint) (strmov(ext, ".data") - fname);
4134
5095
  if (write_base(&file))
4135
5096
  {
4136
 
    my_stpcpy(ext, ".info"); // to have it right in the error message
 
5097
    strmov(ext, ".info"); // to have it right in the error message
4137
5098
    rli->report(ERROR_LEVEL, my_errno,
4138
 
                _("Error in Create_file event: could not write to file '%s'"),
 
5099
                "Error in Create_file event: could not write to file '%s'",
4139
5100
                fname_buf);
4140
5101
    goto err;
4141
5102
  }
4142
5103
  end_io_cache(&file);
4143
5104
  my_close(fd, MYF(0));
4144
 
 
 
5105
  
4145
5106
  // fname_buf now already has .data, not .info, because we did our trick
4146
5107
  my_delete(fname_buf, MYF(0)); // old copy may exist already
4147
5108
  if ((fd= my_create(fname_buf, CREATE_MODE,
4148
 
                     O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4149
 
                     MYF(MY_WME))) < 0)
 
5109
                     O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
 
5110
                     MYF(MY_WME))) < 0)
4150
5111
  {
4151
5112
    rli->report(ERROR_LEVEL, my_errno,
4152
 
                _("Error in Create_file event: could not open file '%s'"),
 
5113
                "Error in Create_file event: could not open file '%s'",
4153
5114
                fname_buf);
4154
5115
    goto err;
4155
5116
  }
4156
 
  if (my_write(fd, (unsigned char*) block, block_len, MYF(MY_WME+MY_NABP)))
 
5117
  if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4157
5118
  {
4158
5119
    rli->report(ERROR_LEVEL, my_errno,
4159
 
                _("Error in Create_file event: write to '%s' failed"),
 
5120
                "Error in Create_file event: write to '%s' failed",
4160
5121
                fname_buf);
4161
5122
    goto err;
4162
5123
  }
4170
5131
  thd_proc_info(thd, 0);
4171
5132
  return error == 0;
4172
5133
}
 
5134
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4173
5135
 
4174
5136
 
4175
5137
/**************************************************************************
4180
5142
  Append_block_log_event ctor
4181
5143
*/
4182
5144
 
 
5145
#ifndef MYSQL_CLIENT  
4183
5146
Append_block_log_event::Append_block_log_event(THD *thd_arg,
4184
5147
                                               const char *db_arg,
4185
 
                                               unsigned char *block_arg,
4186
 
                                               uint32_t block_len_arg,
 
5148
                                               uchar *block_arg,
 
5149
                                               uint block_len_arg,
4187
5150
                                               bool using_trans)
4188
5151
  :Log_event(thd_arg,0, using_trans), block(block_arg),
4189
5152
   block_len(block_len_arg), file_id(thd_arg->file_id), db(db_arg)
4190
5153
{
4191
5154
}
 
5155
#endif
4192
5156
 
4193
5157
 
4194
5158
/*
4195
5159
  Append_block_log_event ctor
4196
5160
*/
4197
5161
 
4198
 
Append_block_log_event::Append_block_log_event(const char* buf, uint32_t len,
 
5162
Append_block_log_event::Append_block_log_event(const char* buf, uint len,
4199
5163
                                               const Format_description_log_event* description_event)
4200
5164
  :Log_event(buf, description_event),block(0)
4201
5165
{
4202
5166
  uint8_t common_header_len= description_event->common_header_len; 
4203
5167
  uint8_t append_block_header_len=
4204
5168
    description_event->post_header_len[APPEND_BLOCK_EVENT-1];
4205
 
  uint32_t total_header_len= common_header_len+append_block_header_len;
 
5169
  uint total_header_len= common_header_len+append_block_header_len;
4206
5170
  if (len < total_header_len)
4207
5171
    return;
4208
5172
  file_id= uint4korr(buf + common_header_len + AB_FILE_ID_OFFSET);
4209
 
  block= (unsigned char*)buf + total_header_len;
 
5173
  block= (uchar*)buf + total_header_len;
4210
5174
  block_len= len - total_header_len;
4211
5175
  return;
4212
5176
}
4216
5180
  Append_block_log_event::write()
4217
5181
*/
4218
5182
 
 
5183
#ifndef MYSQL_CLIENT
4219
5184
bool Append_block_log_event::write(IO_CACHE* file)
4220
5185
{
4221
 
  unsigned char buf[APPEND_BLOCK_HEADER_LEN];
 
5186
  uchar buf[APPEND_BLOCK_HEADER_LEN];
4222
5187
  int4store(buf + AB_FILE_ID_OFFSET, file_id);
4223
5188
  return (write_header(file, APPEND_BLOCK_HEADER_LEN + block_len) ||
4224
5189
          my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) ||
4225
 
          my_b_safe_write(file, (unsigned char*) block, block_len));
4226
 
}
 
5190
          my_b_safe_write(file, (uchar*) block, block_len));
 
5191
}
 
5192
#endif
 
5193
 
 
5194
 
 
5195
/*
 
5196
  Append_block_log_event::print()
 
5197
*/
 
5198
 
 
5199
#ifdef MYSQL_CLIENT  
 
5200
void Append_block_log_event::print(FILE* file,
 
5201
                                   PRINT_EVENT_INFO* print_event_info)
 
5202
{
 
5203
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
5204
 
 
5205
  if (print_event_info->short_form)
 
5206
    return;
 
5207
  print_header(&cache, print_event_info, false);
 
5208
  my_b_printf(&cache, "\n#%s: file_id: %d  block_len: %d\n",
 
5209
              get_type_str(), file_id, block_len);
 
5210
}
 
5211
#endif /* MYSQL_CLIENT */
4227
5212
 
4228
5213
 
4229
5214
/*
4230
5215
  Append_block_log_event::pack_info()
4231
5216
*/
4232
5217
 
 
5218
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4233
5219
void Append_block_log_event::pack_info(Protocol *protocol)
4234
5220
{
4235
5221
  char buf[256];
4236
 
  uint32_t length;
 
5222
  uint length;
4237
5223
  length= (uint) sprintf(buf, ";file_id=%u;block_len=%u", file_id,
4238
5224
                             block_len);
4239
5225
  protocol->store(buf, length, &my_charset_bin);
4259
5245
  int fd;
4260
5246
  int error = 1;
4261
5247
 
4262
 
  fname= my_stpcpy(proc_info, "Making temp file ");
 
5248
  fname= strmov(proc_info, "Making temp file ");
4263
5249
  slave_load_file_stem(fname, file_id, server_id, ".data");
4264
5250
  thd_proc_info(thd, proc_info);
4265
5251
  if (get_create_or_append())
4270
5256
                       MYF(MY_WME))) < 0)
4271
5257
    {
4272
5258
      rli->report(ERROR_LEVEL, my_errno,
4273
 
                  _("Error in %s event: could not create file '%s'"),
 
5259
                  "Error in %s event: could not create file '%s'",
4274
5260
                  get_type_str(), fname);
4275
5261
      goto err;
4276
5262
    }
4279
5265
                         MYF(MY_WME))) < 0)
4280
5266
  {
4281
5267
    rli->report(ERROR_LEVEL, my_errno,
4282
 
                _("Error in %s event: could not open file '%s'"),
 
5268
                "Error in %s event: could not open file '%s'",
4283
5269
                get_type_str(), fname);
4284
5270
    goto err;
4285
5271
  }
4286
 
  if (my_write(fd, (unsigned char*) block, block_len, MYF(MY_WME+MY_NABP)))
 
5272
  if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4287
5273
  {
4288
5274
    rli->report(ERROR_LEVEL, my_errno,
4289
 
                _("Error in %s event: write to '%s' failed"),
 
5275
                "Error in %s event: write to '%s' failed",
4290
5276
                get_type_str(), fname);
4291
5277
    goto err;
4292
5278
  }
4298
5284
  thd_proc_info(thd, 0);
4299
5285
  return(error);
4300
5286
}
 
5287
#endif
4301
5288
 
4302
5289
 
4303
5290
/**************************************************************************
4308
5295
  Delete_file_log_event ctor
4309
5296
*/
4310
5297
 
 
5298
#ifndef MYSQL_CLIENT
4311
5299
Delete_file_log_event::Delete_file_log_event(THD *thd_arg, const char* db_arg,
4312
5300
                                             bool using_trans)
4313
5301
  :Log_event(thd_arg, 0, using_trans), file_id(thd_arg->file_id), db(db_arg)
4314
5302
{
4315
5303
}
 
5304
#endif
4316
5305
 
4317
5306
/*
4318
5307
  Delete_file_log_event ctor
4319
5308
*/
4320
5309
 
4321
 
Delete_file_log_event::Delete_file_log_event(const char* buf, uint32_t len,
 
5310
Delete_file_log_event::Delete_file_log_event(const char* buf, uint len,
4322
5311
                                             const Format_description_log_event* description_event)
4323
5312
  :Log_event(buf, description_event),file_id(0)
4324
5313
{
4334
5323
  Delete_file_log_event::write()
4335
5324
*/
4336
5325
 
 
5326
#ifndef MYSQL_CLIENT
4337
5327
bool Delete_file_log_event::write(IO_CACHE* file)
4338
5328
{
4339
 
 unsigned char buf[DELETE_FILE_HEADER_LEN];
 
5329
 uchar buf[DELETE_FILE_HEADER_LEN];
4340
5330
 int4store(buf + DF_FILE_ID_OFFSET, file_id);
4341
5331
 return (write_header(file, sizeof(buf)) ||
4342
5332
         my_b_safe_write(file, buf, sizeof(buf)));
4343
5333
}
4344
 
 
 
5334
#endif
 
5335
 
 
5336
 
 
5337
/*
 
5338
  Delete_file_log_event::print()
 
5339
*/
 
5340
 
 
5341
#ifdef MYSQL_CLIENT  
 
5342
void Delete_file_log_event::print(FILE* file,
 
5343
                                  PRINT_EVENT_INFO* print_event_info)
 
5344
{
 
5345
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
5346
 
 
5347
  if (print_event_info->short_form)
 
5348
    return;
 
5349
  print_header(&cache, print_event_info, false);
 
5350
  my_b_printf(&cache, "\n#Delete_file: file_id=%u\n", file_id);
 
5351
}
 
5352
#endif /* MYSQL_CLIENT */
4345
5353
 
4346
5354
/*
4347
5355
  Delete_file_log_event::pack_info()
4348
5356
*/
4349
5357
 
 
5358
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4350
5359
void Delete_file_log_event::pack_info(Protocol *protocol)
4351
5360
{
4352
5361
  char buf[64];
4353
 
  uint32_t length;
 
5362
  uint length;
4354
5363
  length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4355
5364
  protocol->store(buf, (int32_t) length, &my_charset_bin);
4356
5365
}
 
5366
#endif
4357
5367
 
4358
5368
/*
4359
5369
  Delete_file_log_event::do_apply_event()
4360
5370
*/
4361
5371
 
 
5372
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4362
5373
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
4363
5374
{
4364
5375
  char fname[FN_REFLEN+10];
4365
5376
  char *ext= slave_load_file_stem(fname, file_id, server_id, ".data");
4366
5377
  (void) my_delete(fname, MYF(MY_WME));
4367
 
  my_stpcpy(ext, ".info");
 
5378
  strmov(ext, ".info");
4368
5379
  (void) my_delete(fname, MYF(MY_WME));
4369
5380
  return 0;
4370
5381
}
 
5382
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4371
5383
 
4372
5384
 
4373
5385
/**************************************************************************
4378
5390
  Execute_load_log_event ctor
4379
5391
*/
4380
5392
 
 
5393
#ifndef MYSQL_CLIENT  
4381
5394
Execute_load_log_event::Execute_load_log_event(THD *thd_arg,
4382
5395
                                               const char* db_arg,
4383
5396
                                               bool using_trans)
4384
5397
  :Log_event(thd_arg, 0, using_trans), file_id(thd_arg->file_id), db(db_arg)
4385
5398
{
4386
5399
}
 
5400
#endif
4387
5401
  
4388
5402
 
4389
5403
/*
4390
5404
  Execute_load_log_event ctor
4391
5405
*/
4392
5406
 
4393
 
Execute_load_log_event::Execute_load_log_event(const char* buf, uint32_t len,
 
5407
Execute_load_log_event::Execute_load_log_event(const char* buf, uint len,
4394
5408
                                               const Format_description_log_event* description_event)
4395
5409
  :Log_event(buf, description_event), file_id(0)
4396
5410
{
4406
5420
  Execute_load_log_event::write()
4407
5421
*/
4408
5422
 
 
5423
#ifndef MYSQL_CLIENT
4409
5424
bool Execute_load_log_event::write(IO_CACHE* file)
4410
5425
{
4411
 
  unsigned char buf[EXEC_LOAD_HEADER_LEN];
 
5426
  uchar buf[EXEC_LOAD_HEADER_LEN];
4412
5427
  int4store(buf + EL_FILE_ID_OFFSET, file_id);
4413
5428
  return (write_header(file, sizeof(buf)) || 
4414
5429
          my_b_safe_write(file, buf, sizeof(buf)));
4415
5430
}
4416
 
 
 
5431
#endif
 
5432
 
 
5433
 
 
5434
/*
 
5435
  Execute_load_log_event::print()
 
5436
*/
 
5437
 
 
5438
#ifdef MYSQL_CLIENT  
 
5439
void Execute_load_log_event::print(FILE* file,
 
5440
                                   PRINT_EVENT_INFO* print_event_info)
 
5441
{
 
5442
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
5443
 
 
5444
  if (print_event_info->short_form)
 
5445
    return;
 
5446
  print_header(&cache, print_event_info, false);
 
5447
  my_b_printf(&cache, "\n#Exec_load: file_id=%d\n",
 
5448
              file_id);
 
5449
}
 
5450
#endif
4417
5451
 
4418
5452
/*
4419
5453
  Execute_load_log_event::pack_info()
4420
5454
*/
4421
5455
 
 
5456
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4422
5457
void Execute_load_log_event::pack_info(Protocol *protocol)
4423
5458
{
4424
5459
  char buf[64];
4425
 
  uint32_t length;
 
5460
  uint length;
4426
5461
  length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4427
5462
  protocol->store(buf, (int32_t) length, &my_charset_bin);
4428
5463
}
4448
5483
                    MYF(MY_WME|MY_NABP)))
4449
5484
  {
4450
5485
    rli->report(ERROR_LEVEL, my_errno,
4451
 
                _("Error in Exec_load event: could not open file '%s'"),
 
5486
                "Error in Exec_load event: could not open file '%s'",
4452
5487
                fname);
4453
5488
    goto err;
4454
5489
  }
4457
5492
                                                         rli->relay_log.description_event_for_exec)) ||
4458
5493
      lev->get_type_code() != NEW_LOAD_EVENT)
4459
5494
  {
4460
 
    rli->report(ERROR_LEVEL, 0,
4461
 
                _("Error in Exec_load event: "
4462
 
                  "file '%s' appears corrupted"),
4463
 
                fname);
 
5495
    rli->report(ERROR_LEVEL, 0, "Error in Exec_load event: "
 
5496
                    "file '%s' appears corrupted", fname);
4464
5497
    goto err;
4465
5498
  }
4466
5499
 
4488
5521
    if (tmp)
4489
5522
    {
4490
5523
      rli->report(ERROR_LEVEL, rli->last_error().number,
4491
 
                  _("%s. Failed executing load from '%s'"),
4492
 
                  tmp, fname);
4493
 
      free(tmp);
 
5524
                  "%s. Failed executing load from '%s'", tmp, fname);
 
5525
      my_free(tmp,MYF(0));
4494
5526
    }
4495
5527
    goto err;
4496
5528
  }
4519
5551
  return error;
4520
5552
}
4521
5553
 
 
5554
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
 
5555
 
4522
5556
 
4523
5557
/**************************************************************************
4524
5558
        Begin_load_query_log_event methods
4525
5559
**************************************************************************/
4526
5560
 
 
5561
#ifndef MYSQL_CLIENT
4527
5562
Begin_load_query_log_event::
4528
 
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, unsigned char* block_arg,
4529
 
                           uint32_t block_len_arg, bool using_trans)
 
5563
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, uchar* block_arg,
 
5564
                           uint block_len_arg, bool using_trans)
4530
5565
  :Append_block_log_event(thd_arg, db_arg, block_arg, block_len_arg,
4531
5566
                          using_trans)
4532
5567
{
4533
5568
   file_id= thd_arg->file_id= mysql_bin_log.next_file_id();
4534
5569
}
 
5570
#endif
4535
5571
 
4536
5572
 
4537
5573
Begin_load_query_log_event::
4538
 
Begin_load_query_log_event(const char* buf, uint32_t len,
 
5574
Begin_load_query_log_event(const char* buf, uint len,
4539
5575
                           const Format_description_log_event* desc_event)
4540
5576
  :Append_block_log_event(buf, len, desc_event)
4541
5577
{
4542
5578
}
4543
5579
 
4544
5580
 
 
5581
#if defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4545
5582
int Begin_load_query_log_event::get_create_or_append() const
4546
5583
{
4547
5584
  return 1; /* create the file */
4548
5585
}
4549
 
 
4550
 
 
 
5586
#endif /* defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
 
5587
 
 
5588
 
 
5589
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4551
5590
Log_event::enum_skip_reason
4552
5591
Begin_load_query_log_event::do_shall_skip(Relay_log_info *rli)
4553
5592
{
4557
5596
  */
4558
5597
  return continue_group(rli);
4559
5598
}
 
5599
#endif
4560
5600
 
4561
5601
 
4562
5602
/**************************************************************************
4564
5604
**************************************************************************/
4565
5605
 
4566
5606
 
 
5607
#ifndef MYSQL_CLIENT
4567
5608
Execute_load_query_log_event::
4568
5609
Execute_load_query_log_event(THD *thd_arg, const char* query_arg,
4569
 
                             ulong query_length_arg, uint32_t fn_pos_start_arg,
4570
 
                             uint32_t fn_pos_end_arg,
 
5610
                             ulong query_length_arg, uint fn_pos_start_arg,
 
5611
                             uint fn_pos_end_arg,
4571
5612
                             enum_load_dup_handling dup_handling_arg,
4572
5613
                             bool using_trans, bool suppress_use,
4573
5614
                             THD::killed_state killed_err_arg):
4577
5618
  fn_pos_end(fn_pos_end_arg), dup_handling(dup_handling_arg)
4578
5619
{
4579
5620
}
 
5621
#endif /* !MYSQL_CLIENT */
4580
5622
 
4581
5623
 
4582
5624
Execute_load_query_log_event::
4583
 
Execute_load_query_log_event(const char* buf, uint32_t event_len,
 
5625
Execute_load_query_log_event(const char* buf, uint event_len,
4584
5626
                             const Format_description_log_event* desc_event):
4585
5627
  Query_log_event(buf, event_len, desc_event, EXECUTE_LOAD_QUERY_EVENT),
4586
5628
  file_id(0), fn_pos_start(0), fn_pos_end(0)
4608
5650
}
4609
5651
 
4610
5652
 
 
5653
#ifndef MYSQL_CLIENT
4611
5654
bool
4612
5655
Execute_load_query_log_event::write_post_header_for_derived(IO_CACHE* file)
4613
5656
{
4614
 
  unsigned char buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
 
5657
  uchar buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
4615
5658
  int4store(buf, file_id);
4616
5659
  int4store(buf + 4, fn_pos_start);
4617
5660
  int4store(buf + 4 + 4, fn_pos_end);
4618
 
  *(buf + 4 + 4 + 4)= (unsigned char) dup_handling;
 
5661
  *(buf + 4 + 4 + 4)= (uchar) dup_handling;
4619
5662
  return my_b_safe_write(file, buf, EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
4620
5663
}
4621
 
 
4622
 
 
 
5664
#endif
 
5665
 
 
5666
 
 
5667
#ifdef MYSQL_CLIENT
 
5668
void Execute_load_query_log_event::print(FILE* file,
 
5669
                                         PRINT_EVENT_INFO* print_event_info)
 
5670
{
 
5671
  print(file, print_event_info, 0);
 
5672
}
 
5673
 
 
5674
/**
 
5675
  Prints the query as LOAD DATA LOCAL and with rewritten filename.
 
5676
*/
 
5677
void Execute_load_query_log_event::print(FILE* file,
 
5678
                                         PRINT_EVENT_INFO* print_event_info,
 
5679
                                         const char *local_fname)
 
5680
{
 
5681
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
5682
 
 
5683
  print_query_header(&cache, print_event_info);
 
5684
 
 
5685
  if (local_fname)
 
5686
  {
 
5687
    my_b_write(&cache, (uchar*) query, fn_pos_start);
 
5688
    my_b_printf(&cache, " LOCAL INFILE \'");
 
5689
    my_b_printf(&cache, local_fname);
 
5690
    my_b_printf(&cache, "\'");
 
5691
    if (dup_handling == LOAD_DUP_REPLACE)
 
5692
      my_b_printf(&cache, " REPLACE");
 
5693
    my_b_printf(&cache, " INTO");
 
5694
    my_b_write(&cache, (uchar*) query + fn_pos_end, q_len-fn_pos_end);
 
5695
    my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
 
5696
  }
 
5697
  else
 
5698
  {
 
5699
    my_b_write(&cache, (uchar*) query, q_len);
 
5700
    my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
 
5701
  }
 
5702
 
 
5703
  if (!print_event_info->short_form)
 
5704
    my_b_printf(&cache, "# file_id: %d \n", file_id);
 
5705
}
 
5706
#endif
 
5707
 
 
5708
 
 
5709
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4623
5710
void Execute_load_query_log_event::pack_info(Protocol *protocol)
4624
5711
{
4625
5712
  char *buf, *pos;
4628
5715
  pos= buf;
4629
5716
  if (db && db_len)
4630
5717
  {
4631
 
    pos= my_stpcpy(buf, "use `");
 
5718
    pos= strmov(buf, "use `");
4632
5719
    memcpy(pos, db, db_len);
4633
 
    pos= my_stpcpy(pos+db_len, "`; ");
 
5720
    pos= strmov(pos+db_len, "`; ");
4634
5721
  }
4635
5722
  if (query && q_len)
4636
5723
  {
4637
5724
    memcpy(pos, query, q_len);
4638
5725
    pos+= q_len;
4639
5726
  }
4640
 
  pos= my_stpcpy(pos, " ;file_id=");
 
5727
  pos= strmov(pos, " ;file_id=");
4641
5728
  pos= int10_to_str((long) file_id, pos, 10);
4642
5729
  protocol->store(buf, pos-buf, &my_charset_bin);
4643
 
  free(buf);
 
5730
  my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
4644
5731
}
4645
5732
 
4646
5733
 
4660
5747
  if (buf == NULL)
4661
5748
  {
4662
5749
    rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
4663
 
                ER(ER_SLAVE_FATAL_ERROR),
4664
 
                _("Not enough memory"));
 
5750
                ER(ER_SLAVE_FATAL_ERROR), "Not enough memory");
4665
5751
    return 1;
4666
5752
  }
4667
5753
 
4670
5756
  p+= fn_pos_start;
4671
5757
  fname= (p= strmake(p, STRING_WITH_LEN(" INFILE \'")));
4672
5758
  p= slave_load_file_stem(p, file_id, server_id, ".data");
4673
 
  fname_end= p= strchr(p, '\0');                      // Safer than p=p+5
 
5759
  fname_end= p= strend(p);                      // Safer than p=p+5
4674
5760
  *(p++)='\'';
4675
5761
  switch (dup_handling) {
4676
5762
  case LOAD_DUP_IGNORE:
4698
5784
  if (!error)
4699
5785
    (void) my_delete(fname, MYF(MY_WME));
4700
5786
 
4701
 
  free(buf);
 
5787
  my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
4702
5788
  return error;
4703
5789
}
 
5790
#endif
4704
5791
 
4705
5792
 
4706
5793
/**************************************************************************
4720
5807
            write_str(file, line_term,  (uint) line_term_len) ||
4721
5808
            write_str(file, line_start, (uint) line_start_len) ||
4722
5809
            write_str(file, escaped,    (uint) escaped_len) ||
4723
 
            my_b_safe_write(file,(unsigned char*) &opt_flags,1));
 
5810
            my_b_safe_write(file,(uchar*) &opt_flags,1));
4724
5811
  }
4725
5812
  else
4726
5813
  {
4736
5823
    old_ex.escaped=    *escaped;
4737
5824
    old_ex.opt_flags=  opt_flags;
4738
5825
    old_ex.empty_flags=empty_flags;
4739
 
    return my_b_safe_write(file, (unsigned char*) &old_ex, sizeof(old_ex)) != 0;
 
5826
    return my_b_safe_write(file, (uchar*) &old_ex, sizeof(old_ex)) != 0;
4740
5827
  }
4741
5828
}
4742
5829
 
4796
5883
        Rows_log_event member functions
4797
5884
**************************************************************************/
4798
5885
 
4799
 
Rows_log_event::Rows_log_event(THD *thd_arg, Table *tbl_arg, ulong tid,
 
5886
#ifndef MYSQL_CLIENT
 
5887
Rows_log_event::Rows_log_event(THD *thd_arg, TABLE *tbl_arg, ulong tid,
4800
5888
                               MY_BITMAP const *cols, bool is_transactional)
4801
5889
  : Log_event(thd_arg, 0, is_transactional),
4802
5890
    m_row_count(0),
4804
5892
    m_table_id(tid),
4805
5893
    m_width(tbl_arg ? tbl_arg->s->fields : 1),
4806
5894
    m_rows_buf(0), m_rows_cur(0), m_rows_end(0), m_flags(0) 
 
5895
#ifdef HAVE_REPLICATION
4807
5896
    , m_curr_row(NULL), m_curr_row_end(NULL), m_key(NULL)
 
5897
#endif
4808
5898
{
4809
5899
  /*
4810
5900
    We allow a special form of dummy event when the table, and cols
4811
 
    are null and the table id is UINT32_MAX.  This is a temporary
 
5901
    are null and the table id is ~0UL.  This is a temporary
4812
5902
    solution, to be able to terminate a started statement in the
4813
5903
    binary log: the extraneous events will be removed in the future.
4814
5904
   */
4815
 
  assert((tbl_arg && tbl_arg->s && tid != UINT32_MAX) || (!tbl_arg && !cols && tid == UINT32_MAX));
 
5905
  assert((tbl_arg && tbl_arg->s && tid != ~0UL) || (!tbl_arg && !cols && tid == ~0UL));
4816
5906
 
4817
5907
  if (thd_arg->options & OPTION_NO_FOREIGN_KEY_CHECKS)
4818
5908
      set_flags(NO_FOREIGN_KEY_CHECKS_F);
4837
5927
    m_cols.bitmap= 0;
4838
5928
  }
4839
5929
}
4840
 
 
4841
 
 
4842
 
Rows_log_event::Rows_log_event(const char *buf, uint32_t event_len,
 
5930
#endif
 
5931
 
 
5932
Rows_log_event::Rows_log_event(const char *buf, uint event_len,
4843
5933
                               Log_event_type event_type,
4844
5934
                               const Format_description_log_event
4845
5935
                               *description_event)
4846
5936
  : Log_event(buf, description_event),
4847
5937
    m_row_count(0),
 
5938
#ifndef MYSQL_CLIENT
4848
5939
    m_table(NULL),
 
5940
#endif
4849
5941
    m_table_id(0), m_rows_buf(0), m_rows_cur(0), m_rows_end(0)
 
5942
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4850
5943
    , m_curr_row(NULL), m_curr_row_end(NULL), m_key(NULL)
 
5944
#endif
4851
5945
{
4852
5946
  uint8_t const common_header_len= description_event->common_header_len;
4853
5947
  uint8_t const post_header_len= description_event->post_header_len[event_type-1];
4868
5962
 
4869
5963
  m_flags= uint2korr(post_start);
4870
5964
 
4871
 
  unsigned char const *const var_start=
4872
 
    (const unsigned char *)buf + common_header_len + post_header_len;
4873
 
  unsigned char const *const ptr_width= var_start;
4874
 
  unsigned char *ptr_after_width= (unsigned char*) ptr_width;
 
5965
  uchar const *const var_start=
 
5966
    (const uchar *)buf + common_header_len + post_header_len;
 
5967
  uchar const *const ptr_width= var_start;
 
5968
  uchar *ptr_after_width= (uchar*) ptr_width;
4875
5969
  m_width = net_field_length(&ptr_after_width);
4876
5970
  /* if bitmap_init fails, catched in is_valid() */
4877
5971
  if (likely(!bitmap_init(&m_cols,
4912
6006
    }
4913
6007
  }
4914
6008
 
4915
 
  const unsigned char* const ptr_rows_data= (const unsigned char*) ptr_after_width;
4916
 
 
4917
 
  size_t const data_size= event_len - (ptr_rows_data - (const unsigned char *) buf);
4918
 
 
4919
 
  m_rows_buf= (unsigned char*) my_malloc(data_size, MYF(MY_WME));
 
6009
  const uchar* const ptr_rows_data= (const uchar*) ptr_after_width;
 
6010
 
 
6011
  size_t const data_size= event_len - (ptr_rows_data - (const uchar *) buf);
 
6012
 
 
6013
  m_rows_buf= (uchar*) my_malloc(data_size, MYF(MY_WME));
4920
6014
  if (likely((bool)m_rows_buf))
4921
6015
  {
 
6016
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4922
6017
    m_curr_row= m_rows_buf;
 
6018
#endif
4923
6019
    m_rows_end= m_rows_buf + data_size;
4924
6020
    m_rows_cur= m_rows_end;
4925
6021
    memcpy(m_rows_buf, ptr_rows_data, data_size);
4933
6029
Rows_log_event::~Rows_log_event()
4934
6030
{
4935
6031
  if (m_cols.bitmap == m_bitbuf) // no my_malloc happened
4936
 
    m_cols.bitmap= 0; // so no free in bitmap_free
 
6032
    m_cols.bitmap= 0; // so no my_free in bitmap_free
4937
6033
  bitmap_free(&m_cols); // To pair with bitmap_init().
4938
 
  free((unsigned char*)m_rows_buf);
 
6034
  my_free((uchar*)m_rows_buf, MYF(MY_ALLOW_ZERO_PTR));
4939
6035
}
4940
6036
 
4941
6037
int Rows_log_event::get_data_size()
4942
6038
{
4943
6039
  int const type_code= get_type_code();
4944
6040
 
4945
 
  unsigned char buf[sizeof(m_width)+1];
4946
 
  unsigned char *end= net_store_length(buf, (m_width + 7) / 8);
 
6041
  uchar buf[sizeof(m_width)+1];
 
6042
  uchar *end= net_store_length(buf, (m_width + 7) / 8);
4947
6043
 
4948
6044
  int data_size= ROWS_HEADER_LEN;
4949
6045
  data_size+= no_bytes_in_map(&m_cols);
4957
6053
}
4958
6054
 
4959
6055
 
4960
 
int Rows_log_event::do_add_row_data(unsigned char *row_data, size_t length)
 
6056
#ifndef MYSQL_CLIENT
 
6057
int Rows_log_event::do_add_row_data(uchar *row_data, size_t length)
4961
6058
{
4962
6059
  /*
4963
6060
    When the table has a primary key, we would probably want, by default, to
4988
6085
    my_ptrdiff_t const new_alloc= 
4989
6086
        block_size * ((cur_size + length + block_size - 1) / block_size);
4990
6087
 
4991
 
    unsigned char* const new_buf= (unsigned char*)my_realloc((unsigned char*)m_rows_buf, (uint) new_alloc,
 
6088
    uchar* const new_buf= (uchar*)my_realloc((uchar*)m_rows_buf, (uint) new_alloc,
4992
6089
                                           MYF(MY_ALLOW_ZERO_PTR|MY_WME));
4993
6090
    if (unlikely(!new_buf))
4994
6091
      return(HA_ERR_OUT_OF_MEM);
5013
6110
  m_row_count++;
5014
6111
  return(0);
5015
6112
}
 
6113
#endif
5016
6114
 
 
6115
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
5017
6116
int Rows_log_event::do_apply_event(Relay_log_info const *rli)
5018
6117
{
5019
6118
  int error= 0;
5020
6119
  /*
5021
 
    If m_table_id == UINT32_MAX, then we have a dummy event that does not
 
6120
    If m_table_id == ~0UL, then we have a dummy event that does not
5022
6121
    contain any data.  In that case, we just remove all tables in the
5023
6122
    tables_to_lock list, close the thread tables, and return with
5024
6123
    success.
5025
6124
   */
5026
 
  if (m_table_id == UINT32_MAX)
 
6125
  if (m_table_id == ~0UL)
5027
6126
  {
5028
6127
    /*
5029
6128
       This one is supposed to be set: just an extra check so that
5091
6190
            Error reporting borrowed from Query_log_event with many excessive
5092
6191
            simplifications (we don't honour --slave-skip-errors)
5093
6192
          */
5094
 
          uint32_t actual_error= thd->main_da.sql_errno();
 
6193
          uint actual_error= thd->main_da.sql_errno();
5095
6194
          rli->report(ERROR_LEVEL, actual_error,
5096
 
                      _("Error '%s' in %s event: when locking tables"),
5097
 
                      (actual_error
5098
 
                       ? thd->main_da.message()
5099
 
                       : _("unexpected success or fatal error")),
 
6195
                      "Error '%s' in %s event: when locking tables",
 
6196
                      (actual_error ? thd->main_da.message():
 
6197
                       "unexpected success or fatal error"),
5100
6198
                      get_type_str());
5101
6199
          thd->is_fatal_error= 1;
5102
6200
        }
5103
6201
        else
5104
6202
        {
5105
6203
          rli->report(ERROR_LEVEL, error,
5106
 
                      _("Error in %s event: when locking tables"),
 
6204
                      "Error in %s event: when locking tables",
5107
6205
                      get_type_str());
5108
6206
        }
5109
6207
        const_cast<Relay_log_info*>(rli)->clear_tables_to_lock();
5124
6222
        need to add code to assert that is the case.
5125
6223
       */
5126
6224
      thd->binlog_flush_pending_rows_event(false);
5127
 
      TableList *tables= rli->tables_to_lock;
 
6225
      TABLE_LIST *tables= rli->tables_to_lock;
5128
6226
      close_tables_for_reopen(thd, &tables);
5129
6227
 
5130
 
      uint32_t tables_count= rli->tables_to_lock_count;
 
6228
      uint tables_count= rli->tables_to_lock_count;
5131
6229
      if ((error= open_tables(thd, &tables, &tables_count, 0)))
5132
6230
      {
5133
6231
        if (thd->is_slave_error || thd->is_fatal_error)
5136
6234
            Error reporting borrowed from Query_log_event with many excessive
5137
6235
            simplifications (we don't honour --slave-skip-errors)
5138
6236
          */
5139
 
          uint32_t actual_error= thd->main_da.sql_errno();
 
6237
          uint actual_error= thd->main_da.sql_errno();
5140
6238
          rli->report(ERROR_LEVEL, actual_error,
5141
 
                      _("Error '%s' on reopening tables"),
5142
 
                      (actual_error
5143
 
                       ? thd->main_da.message()
5144
 
                       : _("unexpected success or fatal error")));
 
6239
                      "Error '%s' on reopening tables",
 
6240
                      (actual_error ? thd->main_da.message() :
 
6241
                       "unexpected success or fatal error"));
5145
6242
          thd->is_slave_error= 1;
5146
6243
        }
5147
6244
        const_cast<Relay_log_info*>(rli)->clear_tables_to_lock();
5154
6251
      ensure that they still have the correct type.
5155
6252
 
5156
6253
      We can use a down cast here since we know that every table added
5157
 
      to the tables_to_lock is a RPL_TableList.
 
6254
      to the tables_to_lock is a RPL_TABLE_LIST.
5158
6255
    */
5159
6256
 
5160
6257
    {
5161
 
      RPL_TableList *ptr= rli->tables_to_lock;
5162
 
      for ( ; ptr ; ptr= static_cast<RPL_TableList*>(ptr->next_global))
 
6258
      RPL_TABLE_LIST *ptr= rli->tables_to_lock;
 
6259
      for ( ; ptr ; ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global))
5163
6260
      {
5164
6261
        if (ptr->m_tabledef.compatible_with(rli, ptr->table))
5165
6262
        {
5186
6283
      Rows_log_event, we can invalidate the query cache for the
5187
6284
      associated table.
5188
6285
     */
5189
 
    for (TableList *ptr= rli->tables_to_lock ; ptr ; ptr= ptr->next_global)
 
6286
    for (TABLE_LIST *ptr= rli->tables_to_lock ; ptr ; ptr= ptr->next_global)
5190
6287
    {
5191
6288
      const_cast<Relay_log_info*>(rli)->m_table_map.set_table(ptr->table_id, ptr->table);
5192
6289
    }
5193
6290
  }
5194
6291
 
5195
 
  Table* 
 
6292
  TABLE* 
5196
6293
    table= 
5197
6294
    m_table= const_cast<Relay_log_info*>(rli)->m_table_map.get_table(m_table_id);
5198
6295
 
5494
6591
    }
5495
6592
    else
5496
6593
      rli->report(ERROR_LEVEL, error,
5497
 
                  _("Error in %s event: commit of row events failed, "
5498
 
                    "table `%s`.`%s`"),
 
6594
                  "Error in %s event: commit of row events failed, "
 
6595
                  "table `%s`.`%s`",
5499
6596
                  get_type_str(), m_table->s->db.str,
5500
6597
                  m_table->s->table_name.str);
5501
6598
  }
5507
6604
  return(error);
5508
6605
}
5509
6606
 
 
6607
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
 
6608
 
 
6609
#ifndef MYSQL_CLIENT
5510
6610
bool Rows_log_event::write_data_header(IO_CACHE *file)
5511
6611
{
5512
 
  unsigned char buf[ROWS_HEADER_LEN];   // No need to init the buffer
5513
 
  assert(m_table_id != UINT32_MAX);
 
6612
  uchar buf[ROWS_HEADER_LEN];   // No need to init the buffer
 
6613
  assert(m_table_id != ~0UL);
5514
6614
  int6store(buf + RW_MAPID_OFFSET, (uint64_t)m_table_id);
5515
6615
  int2store(buf + RW_FLAGS_OFFSET, m_flags);
5516
6616
  return (my_b_safe_write(file, buf, ROWS_HEADER_LEN));
5522
6622
     Note that this should be the number of *bits*, not the number of
5523
6623
     bytes.
5524
6624
  */
5525
 
  unsigned char sbuf[sizeof(m_width)];
 
6625
  uchar sbuf[sizeof(m_width)];
5526
6626
  my_ptrdiff_t const data_size= m_rows_cur - m_rows_buf;
5527
6627
  bool res= false;
5528
 
  unsigned char *const sbuf_end= net_store_length(sbuf, (size_t) m_width);
 
6628
  uchar *const sbuf_end= net_store_length(sbuf, (size_t) m_width);
5529
6629
  assert(static_cast<size_t>(sbuf_end - sbuf) <= sizeof(sbuf));
5530
6630
 
5531
6631
  res= res || my_b_safe_write(file, sbuf, (size_t) (sbuf_end - sbuf));
5532
6632
 
5533
 
  res= res || my_b_safe_write(file, (unsigned char*) m_cols.bitmap,
 
6633
  res= res || my_b_safe_write(file, (uchar*) m_cols.bitmap,
5534
6634
                              no_bytes_in_map(&m_cols));
5535
6635
  /*
5536
6636
    TODO[refactor write]: Remove the "down cast" here (and elsewhere).
5537
6637
   */
5538
6638
  if (get_type_code() == UPDATE_ROWS_EVENT)
5539
6639
  {
5540
 
    res= res || my_b_safe_write(file, (unsigned char*) m_cols_ai.bitmap,
 
6640
    res= res || my_b_safe_write(file, (uchar*) m_cols_ai.bitmap,
5541
6641
                                no_bytes_in_map(&m_cols_ai));
5542
6642
  }
5543
6643
  res= res || my_b_safe_write(file, m_rows_buf, (size_t) data_size);
5545
6645
  return res;
5546
6646
 
5547
6647
}
5548
 
 
5549
 
 
 
6648
#endif
 
6649
 
 
6650
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5550
6651
void Rows_log_event::pack_info(Protocol *protocol)
5551
6652
{
5552
6653
  char buf[256];
5556
6657
                         "table_id: %lu%s", m_table_id, flagstr);
5557
6658
  protocol->store(buf, bytes, &my_charset_bin);
5558
6659
}
5559
 
 
 
6660
#endif
 
6661
 
 
6662
#ifdef MYSQL_CLIENT
 
6663
void Rows_log_event::print_helper(FILE *file,
 
6664
                                  PRINT_EVENT_INFO *print_event_info,
 
6665
                                  char const *const name)
 
6666
{
 
6667
  IO_CACHE *const head= &print_event_info->head_cache;
 
6668
  IO_CACHE *const body= &print_event_info->body_cache;
 
6669
  if (!print_event_info->short_form)
 
6670
  {
 
6671
    bool const last_stmt_event= get_flags(STMT_END_F);
 
6672
    print_header(head, print_event_info, !last_stmt_event);
 
6673
    my_b_printf(head, "\t%s: table id %lu%s\n",
 
6674
                name, m_table_id,
 
6675
                last_stmt_event ? " flags: STMT_END_F" : "");
 
6676
    print_base64(body, print_event_info, !last_stmt_event);
 
6677
  }
 
6678
 
 
6679
  if (get_flags(STMT_END_F))
 
6680
  {
 
6681
    copy_event_cache_to_file_and_reinit(head, file);
 
6682
    copy_event_cache_to_file_and_reinit(body, file);
 
6683
  }
 
6684
}
 
6685
#endif
5560
6686
 
5561
6687
/**************************************************************************
5562
6688
        Table_map_log_event member functions and support functions
5583
6709
  same as the columns for the table on the slave.
5584
6710
 
5585
6711
  Additionally, values saved for field metadata on the master are saved as a 
5586
 
  string of bytes (unsigned char) in the binlog. A field may require 1 or more bytes
 
6712
  string of bytes (uchar) in the binlog. A field may require 1 or more bytes
5587
6713
  to store the information. In cases where values require multiple bytes 
5588
6714
  (e.g. values > 255), the endian-safe methods are used to properly encode 
5589
6715
  the values on the master and decode them on the slave. When the field
5594
6720
  type used is uint32_t. 
5595
6721
*/
5596
6722
 
 
6723
#if !defined(MYSQL_CLIENT)
5597
6724
/**
5598
6725
  Save the field metadata based on the real_type of the field.
5599
6726
  The metadata saved depends on the type of the field. Some fields
5625
6752
    index+= m_table->s->field[i]->save_field_metadata(&m_field_metadata[index]);
5626
6753
  return(index);
5627
6754
}
 
6755
#endif /* !defined(MYSQL_CLIENT) */
5628
6756
 
5629
6757
/*
5630
6758
  Constructor used to build an event for writing to the binary log.
5631
6759
  Mats says tbl->s lives longer than this event so it's ok to copy pointers
5632
6760
  (tbl->s->db etc) and not pointer content.
5633
6761
 */
5634
 
Table_map_log_event::Table_map_log_event(THD *thd, Table *tbl, ulong tid,
 
6762
#if !defined(MYSQL_CLIENT)
 
6763
Table_map_log_event::Table_map_log_event(THD *thd, TABLE *tbl, ulong tid,
5635
6764
                                         bool is_transactional __attribute__((unused)),
5636
6765
                                         uint16_t flags)
5637
6766
  : Log_event(thd, 0, true),
5650
6779
    m_null_bits(0),
5651
6780
    m_meta_memory(NULL)
5652
6781
{
5653
 
  assert(m_table_id != UINT32_MAX);
 
6782
  assert(m_table_id != ~0UL);
5654
6783
  /*
5655
6784
    In TABLE_SHARE, "db" and "table_name" are 0-terminated (see this comment in
5656
6785
    table.cc / alloc_table_share():
5668
6797
  m_data_size+= 1 + m_colcnt;   // COLCNT and column types
5669
6798
 
5670
6799
  /* If malloc fails, caught in is_valid() */
5671
 
  if ((m_memory= (unsigned char*) my_malloc(m_colcnt, MYF(MY_WME))))
 
6800
  if ((m_memory= (uchar*) my_malloc(m_colcnt, MYF(MY_WME))))
5672
6801
  {
5673
 
    m_coltype= reinterpret_cast<unsigned char*>(m_memory);
 
6802
    m_coltype= reinterpret_cast<uchar*>(m_memory);
5674
6803
    for (unsigned int i= 0 ; i < m_table->s->fields ; ++i)
5675
6804
      m_coltype[i]= m_table->field[i]->type();
5676
6805
  }
5681
6810
    that is not on the slave and is null and thus not in the row data during
5682
6811
    replication.
5683
6812
  */
5684
 
  uint32_t num_null_bytes= (m_table->s->fields + 7) / 8;
 
6813
  uint num_null_bytes= (m_table->s->fields + 7) / 8;
5685
6814
  m_data_size+= num_null_bytes;
5686
 
  m_meta_memory= (unsigned char *)my_multi_malloc(MYF(MY_WME),
 
6815
  m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
5687
6816
                                 &m_null_bits, num_null_bytes,
5688
6817
                                 &m_field_metadata, (m_colcnt * 2),
5689
6818
                                 NULL);
5711
6840
      m_null_bits[(i / 8)]+= 1 << (i % 8);
5712
6841
 
5713
6842
}
5714
 
 
 
6843
#endif /* !defined(MYSQL_CLIENT) */
5715
6844
 
5716
6845
/*
5717
6846
  Constructor used by slave to read the event from the binary log.
5718
6847
 */
5719
 
Table_map_log_event::Table_map_log_event(const char *buf, uint32_t event_len,
 
6848
#if defined(HAVE_REPLICATION)
 
6849
Table_map_log_event::Table_map_log_event(const char *buf, uint event_len,
5720
6850
                                         const Format_description_log_event
5721
6851
                                         *description_event)
5722
6852
 
5723
6853
  : Log_event(buf, description_event),
 
6854
#ifndef MYSQL_CLIENT
5724
6855
    m_table(NULL),
 
6856
#endif
5725
6857
    m_dbnam(NULL), m_dblen(0), m_tblnam(NULL), m_tbllen(0),
5726
6858
    m_colcnt(0), m_coltype(0),
5727
6859
    m_memory(NULL), m_table_id(ULONG_MAX), m_flags(0),
5750
6882
    post_start+= TM_FLAGS_OFFSET;
5751
6883
  }
5752
6884
 
5753
 
  assert(m_table_id != UINT32_MAX);
 
6885
  assert(m_table_id != ~0UL);
5754
6886
 
5755
6887
  m_flags= uint2korr(post_start);
5756
6888
 
5758
6890
  const char *const vpart= buf + common_header_len + post_header_len;
5759
6891
 
5760
6892
  /* Extract the length of the various parts from the buffer */
5761
 
  unsigned char const *const ptr_dblen= (unsigned char const*)vpart + 0;
5762
 
  m_dblen= *(unsigned char*) ptr_dblen;
 
6893
  uchar const *const ptr_dblen= (uchar const*)vpart + 0;
 
6894
  m_dblen= *(uchar*) ptr_dblen;
5763
6895
 
5764
6896
  /* Length of database name + counter + terminating null */
5765
 
  unsigned char const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
5766
 
  m_tbllen= *(unsigned char*) ptr_tbllen;
 
6897
  uchar const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
 
6898
  m_tbllen= *(uchar*) ptr_tbllen;
5767
6899
 
5768
6900
  /* Length of table name + counter + terminating null */
5769
 
  unsigned char const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
5770
 
  unsigned char *ptr_after_colcnt= (unsigned char*) ptr_colcnt;
 
6901
  uchar const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
 
6902
  uchar *ptr_after_colcnt= (uchar*) ptr_colcnt;
5771
6903
  m_colcnt= net_field_length(&ptr_after_colcnt);
5772
6904
 
5773
6905
  /* Allocate mem for all fields in one go. If fails, caught in is_valid() */
5774
 
  m_memory= (unsigned char*) my_multi_malloc(MYF(MY_WME),
 
6906
  m_memory= (uchar*) my_multi_malloc(MYF(MY_WME),
5775
6907
                                     &m_dbnam, (uint) m_dblen + 1,
5776
6908
                                     &m_tblnam, (uint) m_tbllen + 1,
5777
6909
                                     &m_coltype, (uint) m_colcnt,
5778
 
                                     NULL);
 
6910
                                     NullS);
5779
6911
 
5780
6912
  if (m_memory)
5781
6913
  {
5785
6917
    memcpy(m_coltype, ptr_after_colcnt, m_colcnt);
5786
6918
 
5787
6919
    ptr_after_colcnt= ptr_after_colcnt + m_colcnt;
5788
 
    bytes_read= ptr_after_colcnt - (unsigned char *)buf;
 
6920
    bytes_read= ptr_after_colcnt - (uchar *)buf;
5789
6921
    if (bytes_read < event_len)
5790
6922
    {
5791
6923
      m_field_metadata_size= net_field_length(&ptr_after_colcnt);
5792
6924
      assert(m_field_metadata_size <= (m_colcnt * 2));
5793
 
      uint32_t num_null_bytes= (m_colcnt + 7) / 8;
5794
 
      m_meta_memory= (unsigned char *)my_multi_malloc(MYF(MY_WME),
 
6925
      uint num_null_bytes= (m_colcnt + 7) / 8;
 
6926
      m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
5795
6927
                                     &m_null_bits, num_null_bytes,
5796
6928
                                     &m_field_metadata, m_field_metadata_size,
5797
6929
                                     NULL);
5798
6930
      memcpy(m_field_metadata, ptr_after_colcnt, m_field_metadata_size);
5799
 
      ptr_after_colcnt= (unsigned char*)ptr_after_colcnt + m_field_metadata_size;
 
6931
      ptr_after_colcnt= (uchar*)ptr_after_colcnt + m_field_metadata_size;
5800
6932
      memcpy(m_null_bits, ptr_after_colcnt, num_null_bytes);
5801
6933
    }
5802
6934
  }
5803
6935
 
5804
6936
  return;
5805
6937
}
 
6938
#endif
5806
6939
 
5807
6940
Table_map_log_event::~Table_map_log_event()
5808
6941
{
5809
 
  free(m_meta_memory);
5810
 
  free(m_memory);
 
6942
  my_free(m_meta_memory, MYF(MY_ALLOW_ZERO_PTR));
 
6943
  my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));
5811
6944
}
5812
6945
 
5813
6946
/*
5821
6954
       4     Daisy-chaining RBR with SBR not possible
5822
6955
 */
5823
6956
 
 
6957
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
5824
6958
int Table_map_log_event::do_apply_event(Relay_log_info const *rli)
5825
6959
{
5826
 
  RPL_TableList *table_list;
 
6960
  RPL_TABLE_LIST *table_list;
5827
6961
  char *db_mem, *tname_mem;
5828
6962
  size_t dummy_len;
5829
6963
  void *memory;
5835
6969
  pthread_mutex_unlock(&LOCK_thread_count);
5836
6970
 
5837
6971
  if (!(memory= my_multi_malloc(MYF(MY_WME),
5838
 
                                &table_list, (uint) sizeof(RPL_TableList),
 
6972
                                &table_list, (uint) sizeof(RPL_TABLE_LIST),
5839
6973
                                &db_mem, (uint) NAME_LEN + 1,
5840
6974
                                &tname_mem, (uint) NAME_LEN + 1,
5841
 
                                NULL)))
 
6975
                                NullS)))
5842
6976
    return(HA_ERR_OUT_OF_MEM);
5843
6977
 
5844
6978
  memset(table_list, 0, sizeof(*table_list));
5848
6982
  table_list->next_global= table_list->next_local= 0;
5849
6983
  table_list->table_id= m_table_id;
5850
6984
  table_list->updating= 1;
5851
 
  my_stpcpy(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
5852
 
  my_stpcpy(table_list->table_name, m_tblnam);
 
6985
  strmov(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
 
6986
  strmov(table_list->table_name, m_tblnam);
5853
6987
 
5854
6988
  int error= 0;
5855
6989
 
5856
6990
  if (!rpl_filter->db_ok(table_list->db) ||
5857
6991
      (rpl_filter->is_on() && !rpl_filter->tables_ok("", table_list)))
5858
6992
  {
5859
 
    free(memory);
 
6993
    my_free(memory, MYF(MY_WME));
5860
6994
  }
5861
6995
  else
5862
6996
  {
5883
7017
      table map.  Note that for any table that should not be
5884
7018
      replicated, a filter is needed.
5885
7019
 
5886
 
      The creation of a new TableList is used to up-cast the
5887
 
      table_list consisting of RPL_TableList items. This will work
 
7020
      The creation of a new TABLE_LIST is used to up-cast the
 
7021
      table_list consisting of RPL_TABLE_LIST items. This will work
5888
7022
      since the only case where the argument to open_tables() is
5889
7023
      changed, is when thd->lex->query_tables == table_list, i.e.,
5890
7024
      when the statement requires prelocking. Since this is not
5896
7030
      internally in the open_tables() function, hence we take a copy
5897
7031
      of the pointer to make sure that it's not lost.
5898
7032
    */
5899
 
    uint32_t count;
 
7033
    uint count;
5900
7034
    assert(thd->lex->query_tables != table_list);
5901
 
    TableList *tmp_table_list= table_list;
 
7035
    TABLE_LIST *tmp_table_list= table_list;
5902
7036
    if ((error= open_tables(thd, &tmp_table_list, &count, 0)))
5903
7037
    {
5904
7038
      if (thd->is_slave_error || thd->is_fatal_error)
5907
7041
          Error reporting borrowed from Query_log_event with many excessive
5908
7042
          simplifications (we don't honour --slave-skip-errors)
5909
7043
        */
5910
 
        uint32_t actual_error= thd->main_da.sql_errno();
 
7044
        uint actual_error= thd->main_da.sql_errno();
5911
7045
        rli->report(ERROR_LEVEL, actual_error,
5912
 
                    _("Error '%s' on opening table `%s`.`%s`"),
5913
 
                    (actual_error
5914
 
                     ? thd->main_da.message()
5915
 
                     : _("unexpected success or fatal error")),
 
7046
                    "Error '%s' on opening table `%s`.`%s`",
 
7047
                    (actual_error ? thd->main_da.message() :
 
7048
                     "unexpected success or fatal error"),
5916
7049
                    table_list->db, table_list->table_name);
5917
7050
        thd->is_slave_error= 1;
5918
7051
      }
5953
7086
  return(error);
5954
7087
 
5955
7088
err:
5956
 
  free(memory);
 
7089
  my_free(memory, MYF(MY_WME));
5957
7090
  return(error);
5958
7091
}
5959
7092
 
5973
7106
  return 0;
5974
7107
}
5975
7108
 
 
7109
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
5976
7110
 
 
7111
#ifndef MYSQL_CLIENT
5977
7112
bool Table_map_log_event::write_data_header(IO_CACHE *file)
5978
7113
{
5979
 
  assert(m_table_id != UINT32_MAX);
5980
 
  unsigned char buf[TABLE_MAP_HEADER_LEN];
 
7114
  assert(m_table_id != ~0UL);
 
7115
  uchar buf[TABLE_MAP_HEADER_LEN];
5981
7116
  int6store(buf + TM_MAPID_OFFSET, (uint64_t)m_table_id);
5982
7117
  int2store(buf + TM_FLAGS_OFFSET, m_flags);
5983
7118
  return (my_b_safe_write(file, buf, TABLE_MAP_HEADER_LEN));
5991
7126
  assert(m_dblen < 128);
5992
7127
  assert(m_tbllen < 128);
5993
7128
 
5994
 
  unsigned char const dbuf[]= { (unsigned char) m_dblen };
5995
 
  unsigned char const tbuf[]= { (unsigned char) m_tbllen };
 
7129
  uchar const dbuf[]= { (uchar) m_dblen };
 
7130
  uchar const tbuf[]= { (uchar) m_tbllen };
5996
7131
 
5997
 
  unsigned char cbuf[sizeof(m_colcnt)];
5998
 
  unsigned char *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
 
7132
  uchar cbuf[sizeof(m_colcnt)];
 
7133
  uchar *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
5999
7134
  assert(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf));
6000
7135
 
6001
7136
  /*
6002
7137
    Store the size of the field metadata.
6003
7138
  */
6004
 
  unsigned char mbuf[sizeof(m_field_metadata_size)];
6005
 
  unsigned char *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
 
7139
  uchar mbuf[sizeof(m_field_metadata_size)];
 
7140
  uchar *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
6006
7141
 
6007
7142
  return (my_b_safe_write(file, dbuf,      sizeof(dbuf)) ||
6008
 
          my_b_safe_write(file, (const unsigned char*)m_dbnam,   m_dblen+1) ||
 
7143
          my_b_safe_write(file, (const uchar*)m_dbnam,   m_dblen+1) ||
6009
7144
          my_b_safe_write(file, tbuf,      sizeof(tbuf)) ||
6010
 
          my_b_safe_write(file, (const unsigned char*)m_tblnam,  m_tbllen+1) ||
 
7145
          my_b_safe_write(file, (const uchar*)m_tblnam,  m_tbllen+1) ||
6011
7146
          my_b_safe_write(file, cbuf, (size_t) (cbuf_end - cbuf)) ||
6012
7147
          my_b_safe_write(file, m_coltype, m_colcnt) ||
6013
7148
          my_b_safe_write(file, mbuf, (size_t) (mbuf_end - mbuf)) ||
6014
7149
          my_b_safe_write(file, m_field_metadata, m_field_metadata_size),
6015
7150
          my_b_safe_write(file, m_null_bits, (m_colcnt + 7) / 8));
6016
7151
 }
 
7152
#endif
6017
7153
 
 
7154
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6018
7155
 
6019
7156
/*
6020
7157
  Print some useful information for the SHOW BINARY LOG information
6021
7158
  field.
6022
7159
 */
6023
7160
 
 
7161
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6024
7162
void Table_map_log_event::pack_info(Protocol *protocol)
6025
7163
{
6026
7164
    char buf[256];
6029
7167
                           m_table_id, m_dbnam, m_tblnam);
6030
7168
    protocol->store(buf, bytes, &my_charset_bin);
6031
7169
}
6032
 
 
 
7170
#endif
 
7171
 
 
7172
 
 
7173
#endif
 
7174
 
 
7175
 
 
7176
#ifdef MYSQL_CLIENT
 
7177
void Table_map_log_event::print(FILE * /* unused */,
 
7178
                                PRINT_EVENT_INFO *print_event_info)
 
7179
{
 
7180
  if (!print_event_info->short_form)
 
7181
  {
 
7182
    print_header(&print_event_info->head_cache, print_event_info, true);
 
7183
    my_b_printf(&print_event_info->head_cache,
 
7184
                "\tTable_map: `%s`.`%s` mapped to number %lu\n",
 
7185
                m_dbnam, m_tblnam, m_table_id);
 
7186
    print_base64(&print_event_info->body_cache, print_event_info, true);
 
7187
  }
 
7188
}
 
7189
#endif
6033
7190
 
6034
7191
/**************************************************************************
6035
7192
        Write_rows_log_event member functions
6038
7195
/*
6039
7196
  Constructor used to build an event for writing to the binary log.
6040
7197
 */
6041
 
Write_rows_log_event::Write_rows_log_event(THD *thd_arg, Table *tbl_arg,
 
7198
#if !defined(MYSQL_CLIENT)
 
7199
Write_rows_log_event::Write_rows_log_event(THD *thd_arg, TABLE *tbl_arg,
6042
7200
                                           ulong tid_arg,
6043
7201
                                           bool is_transactional)
6044
7202
  : Rows_log_event(thd_arg, tbl_arg, tid_arg, tbl_arg->write_set, is_transactional)
6045
7203
{
6046
7204
}
 
7205
#endif
6047
7206
 
6048
7207
/*
6049
7208
  Constructor used by slave to read the event from the binary log.
6050
7209
 */
6051
 
Write_rows_log_event::Write_rows_log_event(const char *buf, uint32_t event_len,
 
7210
#ifdef HAVE_REPLICATION
 
7211
Write_rows_log_event::Write_rows_log_event(const char *buf, uint event_len,
6052
7212
                                           const Format_description_log_event
6053
7213
                                           *description_event)
6054
7214
: Rows_log_event(buf, event_len, WRITE_ROWS_EVENT, description_event)
6055
7215
{
6056
7216
}
 
7217
#endif
6057
7218
 
 
7219
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6058
7220
int 
6059
7221
Write_rows_log_event::do_before_row_operations(const Slave_reporting_capability *const)
6060
7222
{
6132
7294
  return error? error : local_error;
6133
7295
}
6134
7296
 
 
7297
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6135
7298
 
6136
7299
/*
6137
7300
  Check if there are more UNIQUE keys after the given key.
6138
7301
*/
6139
7302
static int
6140
 
last_uniq_key(Table *table, uint32_t keyno)
 
7303
last_uniq_key(TABLE *table, uint keyno)
6141
7304
{
6142
7305
  while (++keyno < table->s->keys)
6143
7306
    if (table->key_info[keyno].flags & HA_NOSAME)
6211
7374
{
6212
7375
  assert(m_table != NULL && thd != NULL);
6213
7376
 
6214
 
  Table *table= m_table;  // pointer to event's table
 
7377
  TABLE *table= m_table;  // pointer to event's table
6215
7378
  int error;
6216
7379
  int keynum;
6217
7380
  auto_afree_ptr<char> key(NULL);
6303
7466
        }
6304
7467
      }
6305
7468
 
6306
 
      key_copy((unsigned char*)key.get(), table->record[0], table->key_info + keynum,
 
7469
      key_copy((uchar*)key.get(), table->record[0], table->key_info + keynum,
6307
7470
               0);
6308
7471
      error= table->file->index_read_idx_map(table->record[1], keynum,
6309
 
                                             (const unsigned char*)key.get(),
 
7472
                                             (const uchar*)key.get(),
6310
7473
                                             HA_WHOLE_KEY,
6311
7474
                                             HA_READ_KEY_EXACT);
6312
7475
      if (error)
6380
7543
  return(error);
6381
7544
}
6382
7545
 
 
7546
#endif
6383
7547
 
6384
7548
int 
6385
7549
Write_rows_log_event::do_exec_row(const Relay_log_info *const rli)
6398
7562
  return error; 
6399
7563
}
6400
7564
 
 
7565
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
 
7566
 
 
7567
#ifdef MYSQL_CLIENT
 
7568
void Write_rows_log_event::print(FILE *file, PRINT_EVENT_INFO* print_event_info)
 
7569
{
 
7570
  Rows_log_event::print_helper(file, print_event_info, "Write_rows");
 
7571
}
 
7572
#endif
6401
7573
 
6402
7574
/**************************************************************************
6403
7575
        Delete_rows_log_event member functions
6404
7576
**************************************************************************/
6405
7577
 
 
7578
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6406
7579
/*
6407
7580
  Compares table->record[0] and table->record[1]
6408
7581
 
6409
7582
  Returns TRUE if different.
6410
7583
*/
6411
 
static bool record_compare(Table *table)
 
7584
static bool record_compare(TABLE *table)
6412
7585
{
6413
7586
  /*
6414
7587
    Need to set the X bit and the filler bits in both records since
6422
7595
    records. Check that the other engines also return correct records.
6423
7596
   */
6424
7597
  bool result= false;
6425
 
  unsigned char saved_x[2], saved_filler[2];
 
7598
  uchar saved_x[2], saved_filler[2];
6426
7599
 
6427
7600
  if (table->s->null_bytes > 0)
6428
7601
  {
6511
7684
{
6512
7685
  assert(m_table && m_table->in_use != NULL);
6513
7686
 
6514
 
  Table *table= m_table;
 
7687
  TABLE *table= m_table;
6515
7688
  int error;
6516
7689
 
6517
7690
  /* unpack row - missing fields get default values */
6699
7872
  return(error);
6700
7873
}
6701
7874
 
 
7875
#endif
6702
7876
 
6703
7877
/*
6704
7878
  Constructor used to build an event for writing to the binary log.
6705
7879
 */
6706
7880
 
6707
 
Delete_rows_log_event::Delete_rows_log_event(THD *thd_arg, Table *tbl_arg,
 
7881
#ifndef MYSQL_CLIENT
 
7882
Delete_rows_log_event::Delete_rows_log_event(THD *thd_arg, TABLE *tbl_arg,
6708
7883
                                             ulong tid,
6709
7884
                                             bool is_transactional)
6710
7885
  : Rows_log_event(thd_arg, tbl_arg, tid, tbl_arg->read_set, is_transactional)
6711
7886
{
6712
7887
}
 
7888
#endif /* #if !defined(MYSQL_CLIENT) */
6713
7889
 
6714
7890
/*
6715
7891
  Constructor used by slave to read the event from the binary log.
6716
7892
 */
6717
 
Delete_rows_log_event::Delete_rows_log_event(const char *buf, uint32_t event_len,
 
7893
#ifdef HAVE_REPLICATION
 
7894
Delete_rows_log_event::Delete_rows_log_event(const char *buf, uint event_len,
6718
7895
                                             const Format_description_log_event
6719
7896
                                             *description_event)
6720
7897
  : Rows_log_event(buf, event_len, DELETE_ROWS_EVENT, description_event)
6721
7898
{
6722
7899
}
 
7900
#endif
6723
7901
 
 
7902
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6724
7903
 
6725
7904
int 
6726
7905
Delete_rows_log_event::do_before_row_operations(const Slave_reporting_capability *const)
6737
7916
  if (m_table->s->keys > 0)
6738
7917
  {
6739
7918
    // Allocate buffer for key searches
6740
 
    m_key= (unsigned char*)my_malloc(m_table->key_info->key_length, MYF(MY_WME));
 
7919
    m_key= (uchar*)my_malloc(m_table->key_info->key_length, MYF(MY_WME));
6741
7920
    if (!m_key)
6742
7921
      return HA_ERR_OUT_OF_MEM;
6743
7922
  }
6751
7930
{
6752
7931
  /*error= ToDo:find out what this should really be, this triggers close_scan in nbd, returning error?*/
6753
7932
  m_table->file->ha_index_or_rnd_end();
6754
 
  free(m_key);
 
7933
  my_free(m_key, MYF(MY_ALLOW_ZERO_PTR));
6755
7934
  m_key= NULL;
6756
7935
 
6757
7936
  return error;
6772
7951
  return error;
6773
7952
}
6774
7953
 
 
7954
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
 
7955
 
 
7956
#ifdef MYSQL_CLIENT
 
7957
void Delete_rows_log_event::print(FILE *file,
 
7958
                                  PRINT_EVENT_INFO* print_event_info)
 
7959
{
 
7960
  Rows_log_event::print_helper(file, print_event_info, "Delete_rows");
 
7961
}
 
7962
#endif
 
7963
 
6775
7964
 
6776
7965
/**************************************************************************
6777
7966
        Update_rows_log_event member functions
6780
7969
/*
6781
7970
  Constructor used to build an event for writing to the binary log.
6782
7971
 */
6783
 
Update_rows_log_event::Update_rows_log_event(THD *thd_arg, Table *tbl_arg,
 
7972
#if !defined(MYSQL_CLIENT)
 
7973
Update_rows_log_event::Update_rows_log_event(THD *thd_arg, TABLE *tbl_arg,
6784
7974
                                             ulong tid,
6785
7975
                                             bool is_transactional)
6786
7976
: Rows_log_event(thd_arg, tbl_arg, tid, tbl_arg->read_set, is_transactional)
6804
7994
    }
6805
7995
  }
6806
7996
}
 
7997
#endif /* !defined(MYSQL_CLIENT) */
6807
7998
 
6808
7999
 
6809
8000
Update_rows_log_event::~Update_rows_log_event()
6810
8001
{
6811
8002
  if (m_cols_ai.bitmap == m_bitbuf_ai) // no my_malloc happened
6812
 
    m_cols_ai.bitmap= 0; // so no free in bitmap_free
 
8003
    m_cols_ai.bitmap= 0; // so no my_free in bitmap_free
6813
8004
  bitmap_free(&m_cols_ai); // To pair with bitmap_init().
6814
8005
}
6815
8006
 
6817
8008
/*
6818
8009
  Constructor used by slave to read the event from the binary log.
6819
8010
 */
6820
 
Update_rows_log_event::Update_rows_log_event(const char *buf, uint32_t event_len,
 
8011
#ifdef HAVE_REPLICATION
 
8012
Update_rows_log_event::Update_rows_log_event(const char *buf, uint event_len,
6821
8013
                                             const
6822
8014
                                             Format_description_log_event
6823
8015
                                             *description_event)
6824
8016
  : Rows_log_event(buf, event_len, UPDATE_ROWS_EVENT, description_event)
6825
8017
{
6826
8018
}
 
8019
#endif
6827
8020
 
 
8021
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6828
8022
 
6829
8023
int 
6830
8024
Update_rows_log_event::do_before_row_operations(const Slave_reporting_capability *const)
6832
8026
  if (m_table->s->keys > 0)
6833
8027
  {
6834
8028
    // Allocate buffer for key searches
6835
 
    m_key= (unsigned char*)my_malloc(m_table->key_info->key_length, MYF(MY_WME));
 
8029
    m_key= (uchar*)my_malloc(m_table->key_info->key_length, MYF(MY_WME));
6836
8030
    if (!m_key)
6837
8031
      return HA_ERR_OUT_OF_MEM;
6838
8032
  }
6848
8042
{
6849
8043
  /*error= ToDo:find out what this should really be, this triggers close_scan in nbd, returning error?*/
6850
8044
  m_table->file->ha_index_or_rnd_end();
6851
 
  free(m_key); // Free for multi_malloc
 
8045
  my_free(m_key, MYF(MY_ALLOW_ZERO_PTR)); // Free for multi_malloc
6852
8046
  m_key= NULL;
6853
8047
 
6854
8048
  return error;
6903
8097
  return error;
6904
8098
}
6905
8099
 
6906
 
 
6907
 
Incident_log_event::Incident_log_event(const char *buf, uint32_t event_len,
 
8100
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
 
8101
 
 
8102
#ifdef MYSQL_CLIENT
 
8103
void Update_rows_log_event::print(FILE *file,
 
8104
                                  PRINT_EVENT_INFO* print_event_info)
 
8105
{
 
8106
  Rows_log_event::print_helper(file, print_event_info, "Update_rows");
 
8107
}
 
8108
#endif
 
8109
 
 
8110
 
 
8111
Incident_log_event::Incident_log_event(const char *buf, uint event_len,
6908
8112
                                       const Format_description_log_event *descr_event)
6909
8113
  : Log_event(buf, descr_event)
6910
8114
{
6945
8149
}
6946
8150
 
6947
8151
 
 
8152
#ifndef MYSQL_CLIENT
6948
8153
void Incident_log_event::pack_info(Protocol *protocol)
6949
8154
{
6950
8155
  char buf[256];
6957
8162
                    m_incident, description(), m_message.str);
6958
8163
  protocol->store(buf, bytes, &my_charset_bin);
6959
8164
}
6960
 
 
6961
 
 
 
8165
#endif
 
8166
 
 
8167
 
 
8168
#ifdef MYSQL_CLIENT
 
8169
void
 
8170
Incident_log_event::print(FILE *file,
 
8171
                          PRINT_EVENT_INFO *print_event_info)
 
8172
{
 
8173
  if (print_event_info->short_form)
 
8174
    return;
 
8175
 
 
8176
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
8177
  print_header(&cache, print_event_info, false);
 
8178
  my_b_printf(&cache, "\n# Incident: %s", description());
 
8179
}
 
8180
#endif
 
8181
 
 
8182
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6962
8183
int
6963
8184
Incident_log_event::do_apply_event(Relay_log_info const *rli)
6964
8185
{
6968
8189
              m_message.length > 0 ? m_message.str : "<none>");
6969
8190
  return(1);
6970
8191
}
6971
 
 
 
8192
#endif
6972
8193
 
6973
8194
bool
6974
8195
Incident_log_event::write_data_header(IO_CACHE *file)
6975
8196
{
6976
 
  unsigned char buf[sizeof(int16_t)];
 
8197
  uchar buf[sizeof(int16_t)];
6977
8198
  int2store(buf, (int16_t) m_incident);
6978
8199
  return(my_b_safe_write(file, buf, sizeof(buf)));
6979
8200
}
6984
8205
  return(write_str(file, m_message.str, m_message.length));
6985
8206
}
6986
8207
 
6987
 
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint32_t event_len,
 
8208
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 
8209
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint event_len,
6988
8210
                    const Format_description_log_event* description_event)
6989
8211
  :Log_event(buf, description_event)
6990
8212
{
6993
8215
  set_if_smaller(ident_len,FN_REFLEN-1);
6994
8216
  log_ident= buf + header_size;
6995
8217
}
 
8218
#endif
 
8219
 
 
8220
 
 
8221
#ifdef MYSQL_CLIENT
 
8222
/**
 
8223
  The default values for these variables should be values that are
 
8224
  *incorrect*, i.e., values that cannot occur in an event.  This way,
 
8225
  they will always be printed for the first event.
 
8226
*/
 
8227
st_print_event_info::st_print_event_info()
 
8228
  :flags2_inited(0), sql_mode_inited(0),
 
8229
   auto_increment_increment(0),auto_increment_offset(0), charset_inited(0),
 
8230
   lc_time_names_number(~0),
 
8231
   charset_database_number(ILLEGAL_CHARSET_INFO_NUMBER),
 
8232
   thread_id(0), thread_id_printed(false),
 
8233
   base64_output_mode(BASE64_OUTPUT_UNSPEC), printed_fd_event(false)
 
8234
{
 
8235
  /*
 
8236
    Currently we only use static PRINT_EVENT_INFO objects, so zeroed at
 
8237
    program's startup, but these explicit memset() is for the day someone
 
8238
    creates dynamic instances.
 
8239
  */
 
8240
  memset(db, 0, sizeof(db));
 
8241
  memset(charset, 0, sizeof(charset));
 
8242
  memset(time_zone_str, 0, sizeof(time_zone_str));
 
8243
  delimiter[0]= ';';
 
8244
  delimiter[1]= 0;
 
8245
  myf const flags = MYF(MY_WME | MY_NABP);
 
8246
  open_cached_file(&head_cache, NULL, NULL, 0, flags);
 
8247
  open_cached_file(&body_cache, NULL, NULL, 0, flags);
 
8248
}
 
8249
#endif