~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/log_event.cc

Removed/replaced DBUG symbols and standardized TRUE/FALSE

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
 
#include <drizzled/server_includes.h>
 
17
#ifdef MYSQL_CLIENT
 
18
 
 
19
#include "mysql_priv.h"
 
20
 
 
21
#else
 
22
 
 
23
#ifdef USE_PRAGMA_IMPLEMENTATION
 
24
#pragma implementation                          // gcc: Class implementation
 
25
#endif
 
26
 
 
27
#include "mysql_priv.h"
 
28
#include "slave.h"
18
29
#include "rpl_rli.h"
19
30
#include "rpl_mi.h"
20
31
#include "rpl_filter.h"
21
32
#include "rpl_utility.h"
22
33
#include "rpl_record.h"
23
 
#include <mysys/my_dir.h>
24
 
#include <drizzled/drizzled_error_messages.h>
25
 
 
26
 
#include <algorithm>
27
 
 
28
 
#include <mysys/base64.h>
29
 
#include <mysys/my_bitmap.h>
30
 
 
31
 
#include <libdrizzle/gettext.h>
32
 
#include <libdrizzle/libdrizzle.h>
33
 
 
34
 
#define log_cs  &my_charset_utf8_general_ci
 
34
#include <my_dir.h>
 
35
 
 
36
#endif /* MYSQL_CLIENT */
 
37
 
 
38
#include <base64.h>
 
39
#include <my_bitmap.h>
 
40
 
 
41
#define log_cs  &my_charset_latin1
35
42
 
36
43
#define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
37
44
 
45
52
#define FMT_G_BUFSIZE(PREC) (3 + (PREC) + 5 + 1)
46
53
 
47
54
 
 
55
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
48
56
static const char *HA_ERR(int i)
49
57
{
50
58
  switch (i) {
117
125
*/
118
126
static void inline slave_rows_error_report(enum loglevel level, int ha_error,
119
127
                                           Relay_log_info const *rli, THD *thd,
120
 
                                           Table *table, const char * type,
 
128
                                           TABLE *table, const char * type,
121
129
                                           const char *log_name, ulong pos)
122
130
{
123
131
  const char *handler_error= HA_ERR(ha_error);
124
132
  char buff[MAX_SLAVE_ERRMSG], *slider;
125
133
  const char *buff_end= buff + sizeof(buff);
126
 
  uint32_t len;
127
 
  List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
128
 
  DRIZZLE_ERROR *err;
 
134
  uint len;
 
135
  List_iterator_fast<MYSQL_ERROR> it(thd->warn_list);
 
136
  MYSQL_ERROR *err;
129
137
  buff[0]= 0;
130
138
 
131
139
  for (err= it++, slider= buff; err && slider < buff_end - 1;
132
140
       slider += len, err= it++)
133
141
  {
134
142
    len= snprintf(slider, buff_end - slider,
135
 
                  _(" %s, Error_code: %d;"), err->msg, err->code);
 
143
                  " %s, Error_code: %d;", err->msg, err->code);
136
144
  }
137
145
  
138
146
  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"),
 
147
              "Could not execute %s event on table %s.%s;"
 
148
              "%s handler error %s; "
 
149
              "the event's master log %s, end_log_pos %lu",
142
150
              type, table->s->db.str,
143
151
              table->s->table_name.str,
144
152
              buff,
145
 
              handler_error == NULL? _("<unknown>") : handler_error,
 
153
              handler_error == NULL? "<unknown>" : handler_error,
146
154
              log_name, pos);
147
155
}
148
 
 
 
156
#endif
149
157
 
150
158
/*
151
159
  Cache that will automatically be written to a dedicated file on
225
233
  flag_set m_flags;
226
234
};
227
235
 
228
 
uint32_t debug_not_change_ts_if_art_event= 1; // bug#29309 simulation
 
236
uint debug_not_change_ts_if_art_event= 1; // bug#29309 simulation
229
237
 
230
238
/*
231
239
  pretty_print_str()
232
240
*/
233
241
 
 
242
#ifdef MYSQL_CLIENT
 
243
static void pretty_print_str(IO_CACHE* cache, const char* str, int len)
 
244
{
 
245
  const char* end = str + len;
 
246
  my_b_printf(cache, "\'");
 
247
  while (str < end)
 
248
  {
 
249
    char c;
 
250
    switch ((c=*str++)) {
 
251
    case '\n': my_b_printf(cache, "\\n"); break;
 
252
    case '\r': my_b_printf(cache, "\\r"); break;
 
253
    case '\\': my_b_printf(cache, "\\\\"); break;
 
254
    case '\b': my_b_printf(cache, "\\b"); break;
 
255
    case '\t': my_b_printf(cache, "\\t"); break;
 
256
    case '\'': my_b_printf(cache, "\\'"); break;
 
257
    case 0   : my_b_printf(cache, "\\0"); break;
 
258
    default:
 
259
      my_b_printf(cache, "%c", c);
 
260
      break;
 
261
    }
 
262
  }
 
263
  my_b_printf(cache, "\'");
 
264
}
 
265
#endif /* MYSQL_CLIENT */
 
266
 
 
267
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 
268
 
234
269
static void clear_all_errors(THD *thd, Relay_log_info *rli)
235
270
{
236
271
  thd->is_slave_error = 0;
248
283
  return ((err_code == ER_SLAVE_IGNORED_TABLE) ||
249
284
          (use_slave_mask && bitmap_is_set(&slave_error_mask, err_code)));
250
285
}
 
286
#endif
251
287
 
252
288
 
253
289
/*
254
290
  pretty_print_str()
255
291
*/
256
292
 
 
293
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
257
294
static char *pretty_print_str(char *packet, const char *str, int len)
258
295
{
259
296
  const char *end= str + len;
278
315
  *pos++= '\'';
279
316
  return pos;
280
317
}
281
 
 
 
318
#endif /* !MYSQL_CLIENT */
 
319
 
 
320
 
 
321
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
282
322
 
283
323
/**
284
324
  Creates a temporary name for load data infile:.
292
332
    Pointer to start of extension
293
333
*/
294
334
 
295
 
static char *slave_load_file_stem(char *buf, uint32_t file_id,
 
335
static char *slave_load_file_stem(char *buf, uint file_id,
296
336
                                  int event_server_id, const char *ext)
297
337
{
298
338
  char *res;
299
339
  fn_format(buf,"SQL_LOAD-",slave_load_tmpdir, "", MY_UNPACK_FILENAME);
300
340
  to_unix_path(buf);
301
341
 
302
 
  buf= strchr(buf, '\0');
303
 
  buf= int10_to_str(::server_id, buf, 10);
 
342
  buf = strend(buf);
 
343
  buf = int10_to_str(::server_id, buf, 10);
304
344
  *buf++ = '-';
305
 
  buf= int10_to_str(event_server_id, buf, 10);
 
345
  buf = int10_to_str(event_server_id, buf, 10);
306
346
  *buf++ = '-';
307
347
  res= int10_to_str(file_id, buf, 10);
308
 
  my_stpcpy(res, ext);                             // Add extension last
 
348
  strmov(res, ext);                             // Add extension last
309
349
  return res;                                   // Pointer to extension
310
350
}
311
 
 
 
351
#endif
 
352
 
 
353
 
 
354
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
312
355
 
313
356
/**
314
357
  Delete all temporary files used for SQL_LOAD.
318
361
{
319
362
  MY_DIR *dirp;
320
363
  FILEINFO *file;
321
 
  uint32_t i;
 
364
  uint i;
322
365
  char fname[FN_REFLEN], prefbuf[31], *p;
323
366
 
324
367
  if (!(dirp=my_dir(slave_load_tmpdir,MYF(MY_WME))))
349
392
 
350
393
  my_dirend(dirp);
351
394
}
 
395
#endif
352
396
 
353
397
 
354
398
/*
355
399
  write_str()
356
400
*/
357
401
 
358
 
static bool write_str(IO_CACHE *file, const char *str, uint32_t length)
 
402
static bool write_str(IO_CACHE *file, const char *str, uint length)
359
403
{
360
 
  unsigned char tmp[1];
361
 
  tmp[0]= (unsigned char) length;
 
404
  uchar tmp[1];
 
405
  tmp[0]= (uchar) length;
362
406
  return (my_b_safe_write(file, tmp, sizeof(tmp)) ||
363
 
          my_b_safe_write(file, (unsigned char*) str, length));
 
407
          my_b_safe_write(file, (uchar*) str, length));
364
408
}
365
409
 
366
410
 
369
413
*/
370
414
 
371
415
static inline int read_str(const char **buf, const char *buf_end,
372
 
                           const char **str, uint8_t *len)
 
416
                           const char **str, uint8 *len)
373
417
{
374
 
  if (*buf + ((uint) (unsigned char) **buf) >= buf_end)
 
418
  if (*buf + ((uint) (uchar) **buf) >= buf_end)
375
419
    return 1;
376
 
  *len= (uint8_t) **buf;
 
420
  *len= (uint8) **buf;
377
421
  *str= (*buf)+1;
378
422
  (*buf)+= (uint) *len+1;
379
423
  return 0;
384
428
  Transforms a string into "" or its expression in 0x... form.
385
429
*/
386
430
 
387
 
char *str_to_hex(char *to, const char *from, uint32_t len)
 
431
char *str_to_hex(char *to, const char *from, uint len)
388
432
{
389
433
  if (len)
390
434
  {
393
437
    to= octet2hex(to, from, len);
394
438
  }
395
439
  else
396
 
    to= my_stpcpy(to, "\"\"");
 
440
    to= strmov(to, "\"\"");
397
441
  return to;                               // pointer to end 0 of 'to'
398
442
}
399
443
 
 
444
#ifndef MYSQL_CLIENT
400
445
 
401
446
/**
402
447
  Append a version of the 'from' string suitable for use in a query to
405
450
*/
406
451
 
407
452
int
408
 
append_query_string(const CHARSET_INFO * const csinfo,
 
453
append_query_string(CHARSET_INFO *csinfo,
409
454
                    String const *from, String *to)
410
455
{
411
456
  char *beg, *ptr;
412
 
  uint32_t const orig_len= to->length();
 
457
  uint32 const orig_len= to->length();
413
458
  if (to->reserve(orig_len + from->length()*2+3))
414
459
    return 1;
415
460
 
420
465
  else
421
466
  {
422
467
    *ptr++= '\'';
423
 
    ptr+= drizzle_escape_string(ptr, from->ptr(), from->length());
 
468
    ptr+= escape_string_for_mysql(csinfo, ptr, 0,
 
469
                                  from->ptr(), from->length());
424
470
    *ptr++='\'';
425
471
  }
426
472
  to->length(orig_len + ptr - beg);
427
473
  return 0;
428
474
}
429
 
 
 
475
#endif
 
476
 
 
477
 
 
478
/**
 
479
  Prints a "session_var=value" string. Used by mysqlbinlog to print some SET
 
480
  commands just before it prints a query.
 
481
*/
 
482
 
 
483
#ifdef MYSQL_CLIENT
 
484
 
 
485
static void print_set_option(IO_CACHE* file, uint32 bits_changed,
 
486
                             uint32 option, uint32 flags, const char* name,
 
487
                             bool* need_comma)
 
488
{
 
489
  if (bits_changed & option)
 
490
  {
 
491
    if (*need_comma)
 
492
      my_b_printf(file,", ");
 
493
    my_b_printf(file,"%s=%d", name, test(flags & option));
 
494
    *need_comma= 1;
 
495
  }
 
496
}
 
497
#endif
430
498
 
431
499
/**************************************************************************
432
500
        Log_event methods (= the parent class of all events)
480
548
  Log_event::Log_event()
481
549
*/
482
550
 
483
 
Log_event::Log_event(THD* thd_arg, uint16_t flags_arg, bool using_trans)
 
551
#ifndef MYSQL_CLIENT
 
552
Log_event::Log_event(THD* thd_arg, uint16 flags_arg, bool using_trans)
484
553
  :log_pos(0), temp_buf(0), exec_time(0), flags(flags_arg), thd(thd_arg)
485
554
{
486
555
  server_id=    thd->server_id;
508
577
  when=         0;
509
578
  log_pos=      0;
510
579
}
 
580
#endif /* !MYSQL_CLIENT */
511
581
 
512
582
 
513
583
/*
518
588
                     const Format_description_log_event* description_event)
519
589
  :temp_buf(0), cache_stmt(0)
520
590
{
521
 
  thd= 0;
522
 
  when= uint4korr(buf);
523
 
  server_id= uint4korr(buf + SERVER_ID_OFFSET);
 
591
#ifndef MYSQL_CLIENT
 
592
  thd = 0;
 
593
#endif
 
594
  when = uint4korr(buf);
 
595
  server_id = uint4korr(buf + SERVER_ID_OFFSET);
524
596
  data_written= uint4korr(buf + EVENT_LEN_OFFSET);
525
597
  if (description_event->binlog_version==1)
526
598
  {
579
651
  /* otherwise, go on with reading the header from buf (nothing now) */
580
652
}
581
653
 
 
654
#ifndef MYSQL_CLIENT
 
655
#ifdef HAVE_REPLICATION
582
656
 
583
657
int Log_event::do_update_pos(Relay_log_info *rli)
584
658
{
649
723
 
650
724
  protocol->prepare_for_resend();
651
725
  protocol->store(log_name, &my_charset_bin);
652
 
  protocol->store((uint64_t) pos);
 
726
  protocol->store((ulonglong) pos);
653
727
  event_type = get_type_str();
654
728
  protocol->store(event_type, strlen(event_type), &my_charset_bin);
655
 
  protocol->store((uint32_t) server_id);
656
 
  protocol->store((uint64_t) log_pos);
 
729
  protocol->store((uint32) server_id);
 
730
  protocol->store((ulonglong) log_pos);
657
731
  pack_info(protocol);
658
732
  return protocol->write();
659
733
}
 
734
#endif /* HAVE_REPLICATION */
660
735
 
661
736
 
662
737
/**
669
744
{
670
745
  field_list->push_back(new Item_empty_string("Log_name", 20));
671
746
  field_list->push_back(new Item_return_int("Pos", MY_INT32_NUM_DECIMAL_DIGITS,
672
 
                                            DRIZZLE_TYPE_LONGLONG));
 
747
                                            MYSQL_TYPE_LONGLONG));
673
748
  field_list->push_back(new Item_empty_string("Event_type", 20));
674
749
  field_list->push_back(new Item_return_int("Server_id", 10,
675
 
                                            DRIZZLE_TYPE_LONG));
 
750
                                            MYSQL_TYPE_LONG));
676
751
  field_list->push_back(new Item_return_int("End_log_pos",
677
752
                                            MY_INT32_NUM_DECIMAL_DIGITS,
678
 
                                            DRIZZLE_TYPE_LONGLONG));
 
753
                                            MYSQL_TYPE_LONGLONG));
679
754
  field_list->push_back(new Item_empty_string("Info", 20));
680
755
}
681
756
 
685
760
 
686
761
bool Log_event::write_header(IO_CACHE* file, ulong event_data_length)
687
762
{
688
 
  unsigned char header[LOG_EVENT_HEADER_LEN];
 
763
  uchar header[LOG_EVENT_HEADER_LEN];
689
764
  ulong now;
690
765
 
691
766
  /* Store number of bytes that will be written by this event */
770
845
 
771
846
  if (log_lock)
772
847
    pthread_mutex_lock(log_lock);
773
 
  if (my_b_read(file, (unsigned char*) buf, sizeof(buf)))
 
848
  if (my_b_read(file, (uchar*) buf, sizeof(buf)))
774
849
  {
775
850
    /*
776
851
      If the read hits eof, we must report it as eof so the caller
828
903
    pthread_mutex_unlock(log_lock);
829
904
  return(result);
830
905
}
 
906
#endif /* !MYSQL_CLIENT */
831
907
 
 
908
#ifndef MYSQL_CLIENT
832
909
#define UNLOCK_MUTEX if (log_lock) pthread_mutex_unlock(log_lock);
833
910
#define LOCK_MUTEX if (log_lock) pthread_mutex_lock(log_lock);
 
911
#else
 
912
#define UNLOCK_MUTEX
 
913
#define LOCK_MUTEX
 
914
#endif
834
915
 
 
916
#ifndef MYSQL_CLIENT
835
917
/**
836
918
  @note
837
919
    Allocates memory;  The caller is responsible for clean-up.
840
922
                                     pthread_mutex_t* log_lock,
841
923
                                     const Format_description_log_event
842
924
                                     *description_event)
 
925
#else
 
926
Log_event* Log_event::read_log_event(IO_CACHE* file,
 
927
                                     const Format_description_log_event
 
928
                                     *description_event)
 
929
#endif
843
930
{
844
931
  assert(description_event != 0);
845
932
  char head[LOG_EVENT_MINIMAL_HEADER_LEN];
850
937
    of 13 bytes, whereas LOG_EVENT_MINIMAL_HEADER_LEN is 19 bytes (it's
851
938
    "minimal" over the set {MySQL >=4.0}).
852
939
  */
853
 
  uint32_t header_size= cmin(description_event->common_header_len,
 
940
  uint header_size= min(description_event->common_header_len,
854
941
                        LOG_EVENT_MINIMAL_HEADER_LEN);
855
942
 
856
943
  LOCK_MUTEX;
857
 
  if (my_b_read(file, (unsigned char *) head, header_size))
 
944
  if (my_b_read(file, (uchar *) head, header_size))
858
945
  {
859
946
    UNLOCK_MUTEX;
860
947
    /*
864
951
    */
865
952
    return(0);
866
953
  }
867
 
  uint32_t data_len = uint4korr(head + EVENT_LEN_OFFSET);
 
954
  uint data_len = uint4korr(head + EVENT_LEN_OFFSET);
868
955
  char *buf= 0;
869
956
  const char *error= 0;
870
957
  Log_event *res=  0;
871
958
#ifndef max_allowed_packet
872
959
  THD *thd=current_thd;
873
 
  uint32_t max_allowed_packet= thd ? thd->variables.max_allowed_packet : ~(ulong)0;
 
960
  uint max_allowed_packet= thd ? thd->variables.max_allowed_packet : ~(ulong)0;
874
961
#endif
875
962
 
876
963
  if (data_len > max_allowed_packet)
893
980
  }
894
981
  buf[data_len] = 0;
895
982
  memcpy(buf, head, header_size);
896
 
  if (my_b_read(file, (unsigned char*) buf + header_size, data_len - header_size))
 
983
  if (my_b_read(file, (uchar*) buf + header_size, data_len - header_size))
897
984
  {
898
985
    error = "read error";
899
986
    goto err;
906
993
  if (!res)
907
994
  {
908
995
    assert(error != 0);
909
 
    sql_print_error(_("Error in Log_event::read_log_event(): "
910
 
                    "'%s', data_len: %d, event_type: %d"),
 
996
    sql_print_error("Error in Log_event::read_log_event(): "
 
997
                    "'%s', data_len: %d, event_type: %d",
911
998
                    error,data_len,head[EVENT_TYPE_OFFSET]);
912
 
    free(buf);
 
999
    my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
913
1000
    /*
914
1001
      The SQL slave thread will check if file->error<0 to know
915
1002
      if there was an I/O error. Even if there is no "low-level" I/O errors
929
1016
  constructors.
930
1017
*/
931
1018
 
932
 
Log_event* Log_event::read_log_event(const char* buf, uint32_t event_len,
 
1019
Log_event* Log_event::read_log_event(const char* buf, uint event_len,
933
1020
                                     const char **error,
934
1021
                                     const Format_description_log_event *description_event)
935
1022
{
945
1032
    return(NULL); // general sanity check - will fail on a partial read
946
1033
  }
947
1034
 
948
 
  uint32_t event_type= buf[EVENT_TYPE_OFFSET];
 
1035
  uint event_type= buf[EVENT_TYPE_OFFSET];
949
1036
  if (event_type > description_event->number_of_event_types &&
950
1037
      event_type != FORMAT_DESCRIPTION_EVENT)
951
1038
  {
968
1055
      was read.
969
1056
    */
970
1057
    if (description_event->event_type_permutation)
 
1058
    {
 
1059
      int new_event_type= description_event->event_type_permutation[event_type];
971
1060
      event_type= description_event->event_type_permutation[event_type];
 
1061
    }
972
1062
 
973
1063
    switch(event_type) {
974
1064
    case QUERY_EVENT:
983
1073
    case ROTATE_EVENT:
984
1074
      ev = new Rotate_log_event(buf, event_len, description_event);
985
1075
      break;
 
1076
#ifdef HAVE_REPLICATION
986
1077
    case SLAVE_EVENT: /* can never happen (unused event) */
987
1078
      ev = new Slave_log_event(buf, event_len);
988
1079
      break;
 
1080
#endif /* HAVE_REPLICATION */
989
1081
    case CREATE_FILE_EVENT:
990
1082
      ev = new Create_file_log_event(buf, event_len, description_event);
991
1083
      break;
1019
1111
    case FORMAT_DESCRIPTION_EVENT:
1020
1112
      ev = new Format_description_log_event(buf, event_len, description_event);
1021
1113
      break;
 
1114
#if defined(HAVE_REPLICATION) 
1022
1115
    case WRITE_ROWS_EVENT:
1023
1116
      ev = new Write_rows_log_event(buf, event_len, description_event);
1024
1117
      break;
1031
1124
    case TABLE_MAP_EVENT:
1032
1125
      ev = new Table_map_log_event(buf, event_len, description_event);
1033
1126
      break;
 
1127
#endif
1034
1128
    case BEGIN_LOAD_QUERY_EVENT:
1035
1129
      ev = new Begin_load_query_log_event(buf, event_len, description_event);
1036
1130
      break;
1058
1152
  if (!ev || !ev->is_valid())
1059
1153
  {
1060
1154
    delete ev;
 
1155
#ifdef MYSQL_CLIENT
 
1156
    if (!force_opt) /* then mysqlbinlog dies */
 
1157
    {
 
1158
      *error= "Found invalid event in binary log";
 
1159
      return(0);
 
1160
    }
 
1161
    ev= new Unknown_log_event(buf, description_event);
 
1162
#else
1061
1163
    *error= "Found invalid event in binary log";
1062
1164
    return(0);
 
1165
#endif
1063
1166
  }
1064
1167
  return(ev);  
1065
1168
}
1066
1169
 
 
1170
#ifdef MYSQL_CLIENT
 
1171
 
 
1172
/*
 
1173
  Log_event::print_header()
 
1174
*/
 
1175
 
 
1176
void Log_event::print_header(IO_CACHE* file,
 
1177
                             PRINT_EVENT_INFO* print_event_info,
 
1178
                             bool is_more __attribute__((unused)))
 
1179
{
 
1180
  char llbuff[22];
 
1181
  my_off_t hexdump_from= print_event_info->hexdump_from;
 
1182
 
 
1183
  my_b_printf(file, "#");
 
1184
  print_timestamp(file);
 
1185
  my_b_printf(file, " server id %d  end_log_pos %s ", server_id,
 
1186
              llstr(log_pos,llbuff));
 
1187
 
 
1188
  /* mysqlbinlog --hexdump */
 
1189
  if (print_event_info->hexdump_from)
 
1190
  {
 
1191
    my_b_printf(file, "\n");
 
1192
    uchar *ptr= (uchar*)temp_buf;
 
1193
    my_off_t size=
 
1194
      uint4korr(ptr + EVENT_LEN_OFFSET) - LOG_EVENT_MINIMAL_HEADER_LEN;
 
1195
    my_off_t i;
 
1196
 
 
1197
    /* Header len * 4 >= header len * (2 chars + space + extra space) */
 
1198
    char *h, hex_string[LOG_EVENT_MINIMAL_HEADER_LEN*4]= {0};
 
1199
    char *c, char_string[16+1]= {0};
 
1200
 
 
1201
    /* Pretty-print event common header if header is exactly 19 bytes */
 
1202
    if (print_event_info->common_header_len == LOG_EVENT_MINIMAL_HEADER_LEN)
 
1203
    {
 
1204
      char emit_buf[256];               // Enough for storing one line
 
1205
      my_b_printf(file, "# Position  Timestamp   Type   Master ID        "
 
1206
                  "Size      Master Pos    Flags \n");
 
1207
      int const bytes_written=
 
1208
        snprintf(emit_buf, sizeof(emit_buf),
 
1209
                 "# %8.8lx %02x %02x %02x %02x   %02x   "
 
1210
                 "%02x %02x %02x %02x   %02x %02x %02x %02x   "
 
1211
                 "%02x %02x %02x %02x   %02x %02x\n",
 
1212
                 (unsigned long) hexdump_from,
 
1213
                 ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6],
 
1214
                 ptr[7], ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13],
 
1215
                 ptr[14], ptr[15], ptr[16], ptr[17], ptr[18]);
 
1216
      assert(bytes_written >= 0);
 
1217
      assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
 
1218
      my_b_write(file, (uchar*) emit_buf, bytes_written);
 
1219
      ptr += LOG_EVENT_MINIMAL_HEADER_LEN;
 
1220
      hexdump_from += LOG_EVENT_MINIMAL_HEADER_LEN;
 
1221
    }
 
1222
 
 
1223
    /* Rest of event (without common header) */
 
1224
    for (i= 0, c= char_string, h=hex_string;
 
1225
         i < size;
 
1226
         i++, ptr++)
 
1227
    {
 
1228
      snprintf(h, 4, "%02x ", *ptr);
 
1229
      h += 3;
 
1230
 
 
1231
      *c++= my_isalnum(&my_charset_bin, *ptr) ? *ptr : '.';
 
1232
 
 
1233
      if (i % 16 == 15)
 
1234
      {
 
1235
        /*
 
1236
          my_b_printf() does not support full printf() formats, so we
 
1237
          have to do it this way.
 
1238
 
 
1239
          TODO: Rewrite my_b_printf() to support full printf() syntax.
 
1240
         */
 
1241
        char emit_buf[256];
 
1242
        int const bytes_written=
 
1243
          snprintf(emit_buf, sizeof(emit_buf),
 
1244
                   "# %8.8lx %-48.48s |%16s|\n",
 
1245
                   (unsigned long) (hexdump_from + (i & 0xfffffff0)),
 
1246
                   hex_string, char_string);
 
1247
        assert(bytes_written >= 0);
 
1248
        assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
 
1249
        my_b_write(file, (uchar*) emit_buf, bytes_written);
 
1250
        hex_string[0]= 0;
 
1251
        char_string[0]= 0;
 
1252
        c= char_string;
 
1253
        h= hex_string;
 
1254
      }
 
1255
      else if (i % 8 == 7) *h++ = ' ';
 
1256
    }
 
1257
    *c= '\0';
 
1258
 
 
1259
    if (hex_string[0])
 
1260
    {
 
1261
      char emit_buf[256];
 
1262
      int const bytes_written=
 
1263
        snprintf(emit_buf, sizeof(emit_buf),
 
1264
                    "# %8.8lx %-48.48s |%s|\n",
 
1265
                    (unsigned long) (hexdump_from + (i & 0xfffffff0)),
 
1266
                    hex_string, char_string);
 
1267
      assert(bytes_written >= 0);
 
1268
      assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
 
1269
      my_b_write(file, (uchar*) emit_buf, bytes_written);
 
1270
    }
 
1271
    /*
 
1272
      need a # to prefix the rest of printouts for example those of
 
1273
      Rows_log_event::print_helper().
 
1274
    */
 
1275
    my_b_write(file, reinterpret_cast<const uchar*>("# "), 2);
 
1276
  }
 
1277
  return;
 
1278
}
 
1279
 
 
1280
 
 
1281
void Log_event::print_base64(IO_CACHE* file,
 
1282
                             PRINT_EVENT_INFO* print_event_info,
 
1283
                             bool more)
 
1284
{
 
1285
  const uchar *ptr= (const uchar *)temp_buf;
 
1286
  uint32 size= uint4korr(ptr + EVENT_LEN_OFFSET);
 
1287
 
 
1288
  size_t const tmp_str_sz= base64_needed_encoded_length((int) size);
 
1289
  char *const tmp_str= (char *) my_malloc(tmp_str_sz, MYF(MY_WME));
 
1290
  if (!tmp_str) {
 
1291
    fprintf(stderr, "\nError: Out of memory. "
 
1292
            "Could not print correct binlog event.\n");
 
1293
    return;
 
1294
  }
 
1295
 
 
1296
  if (base64_encode(ptr, (size_t) size, tmp_str))
 
1297
  {
 
1298
    assert(0);
 
1299
  }
 
1300
 
 
1301
  if (my_b_tell(file) == 0)
 
1302
    my_b_printf(file, "\nBINLOG '\n");
 
1303
 
 
1304
  my_b_printf(file, "%s\n", tmp_str);
 
1305
 
 
1306
  if (!more)
 
1307
    my_b_printf(file, "'%s\n", print_event_info->delimiter);
 
1308
 
 
1309
  my_free(tmp_str, MYF(0));
 
1310
  return;
 
1311
}
 
1312
 
 
1313
 
 
1314
/*
 
1315
  Log_event::print_timestamp()
 
1316
*/
 
1317
 
 
1318
void Log_event::print_timestamp(IO_CACHE* file, time_t* ts)
 
1319
{
 
1320
  struct tm *res;
 
1321
  if (!ts)
 
1322
    ts = &when;
 
1323
#ifdef MYSQL_SERVER                             // This is always false
 
1324
  struct tm tm_tmp;
 
1325
  localtime_r(ts,(res= &tm_tmp));
 
1326
#else
 
1327
  res=localtime(ts);
 
1328
#endif
 
1329
 
 
1330
  my_b_printf(file,"%02d%02d%02d %2d:%02d:%02d",
 
1331
              res->tm_year % 100,
 
1332
              res->tm_mon+1,
 
1333
              res->tm_mday,
 
1334
              res->tm_hour,
 
1335
              res->tm_min,
 
1336
              res->tm_sec);
 
1337
  return;
 
1338
}
 
1339
 
 
1340
#endif /* MYSQL_CLIENT */
 
1341
 
 
1342
 
 
1343
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1067
1344
inline Log_event::enum_skip_reason
1068
1345
Log_event::continue_group(Relay_log_info *rli)
1069
1346
{
1071
1348
    return Log_event::EVENT_SKIP_IGNORE;
1072
1349
  return Log_event::do_shall_skip(rli);
1073
1350
}
 
1351
#endif
1074
1352
 
1075
1353
/**************************************************************************
1076
1354
        Query_log_event methods
1077
1355
**************************************************************************/
1078
1356
 
 
1357
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 
1358
 
1079
1359
/**
1080
1360
  This (which is used only for SHOW BINLOG EVENTS) could be updated to
1081
1361
  print SET @@session_var=. But this is not urgent, as SHOW BINLOG EVENTS is
1095
1375
  if (!(flags & LOG_EVENT_SUPPRESS_USE_F)
1096
1376
      && db && db_len)
1097
1377
  {
1098
 
    pos= my_stpcpy(buf, "use `");
 
1378
    pos= strmov(buf, "use `");
1099
1379
    memcpy(pos, db, db_len);
1100
 
    pos= my_stpcpy(pos+db_len, "`; ");
 
1380
    pos= strmov(pos+db_len, "`; ");
1101
1381
  }
1102
1382
  if (query && q_len)
1103
1383
  {
1105
1385
    pos+= q_len;
1106
1386
  }
1107
1387
  protocol->store(buf, pos-buf, &my_charset_bin);
1108
 
  free(buf);
 
1388
  my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
1109
1389
}
 
1390
#endif
1110
1391
 
 
1392
#ifndef MYSQL_CLIENT
1111
1393
 
1112
1394
/**
1113
1395
  Utility function for the next method (Query_log_event::write()) .
1114
1396
*/
1115
1397
static void write_str_with_code_and_len(char **dst, const char *src,
1116
 
                                        int len, uint32_t code)
 
1398
                                        int len, uint code)
1117
1399
{
1118
1400
  assert(src);
1119
1401
  *((*dst)++)= code;
1120
 
  *((*dst)++)= (unsigned char) len;
1121
 
  memcpy(*dst, src, len);
 
1402
  *((*dst)++)= (uchar) len;
 
1403
  bmove(*dst, src, len);
1122
1404
  (*dst)+= len;
1123
1405
}
1124
1406
 
1139
1421
    replicating it correctly, since the length is stored in a byte
1140
1422
    /sven
1141
1423
  */
1142
 
  unsigned char buf[QUERY_HEADER_LEN+
 
1424
  uchar buf[QUERY_HEADER_LEN+
1143
1425
            1+4+           // code of flags2 and flags2
1144
1426
            1+8+           // code of sql_mode and sql_mode
1145
1427
            1+1+FN_REFLEN+ // code of catalog and catalog length and catalog
1211
1493
  if (sql_mode_inited)
1212
1494
  {
1213
1495
    *start++= Q_SQL_MODE_CODE;
1214
 
    int8store(start, (uint64_t)sql_mode);
 
1496
    int8store(start, (ulonglong)sql_mode);
1215
1497
    start+= 8;
1216
1498
  }
1217
1499
  if (catalog_len) // i.e. this var is inited (false for 4.0 events)
1295
1577
  event_length= (uint) (start-buf) + get_post_header_size_for_derived() + db_len + 1 + q_len;
1296
1578
 
1297
1579
  return (write_header(file, event_length) ||
1298
 
          my_b_safe_write(file, (unsigned char*) buf, QUERY_HEADER_LEN) ||
 
1580
          my_b_safe_write(file, (uchar*) buf, QUERY_HEADER_LEN) ||
1299
1581
          write_post_header_for_derived(file) ||
1300
 
          my_b_safe_write(file, (unsigned char*) start_of_status,
 
1582
          my_b_safe_write(file, (uchar*) start_of_status,
1301
1583
                          (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;
 
1584
          my_b_safe_write(file, (db) ? (uchar*) db : (uchar*)"", db_len + 1) ||
 
1585
          my_b_safe_write(file, (uchar*) query, q_len)) ? 1 : 0;
1304
1586
}
1305
1587
 
1306
1588
/**
1341
1623
             (suppress_use ? LOG_EVENT_SUPPRESS_USE_F : 0),
1342
1624
             using_trans),
1343
1625
   data_buf(0), query(query_arg), catalog(thd_arg->catalog),
1344
 
   db(thd_arg->db), q_len((uint32_t) query_length),
 
1626
   db(thd_arg->db), q_len((uint32) query_length),
1345
1627
   thread_id(thd_arg->thread_id),
1346
1628
   /* save the original thread id; we already know the server id */
1347
1629
   slave_proxy_id(thd_arg->variables.pseudo_thread_id),
1356
1638
 
1357
1639
  if (killed_status_arg == THD::KILLED_NO_VALUE)
1358
1640
    killed_status_arg= thd_arg->killed;
1359
 
 
1360
1641
  error_code=
1361
1642
    (killed_status_arg == THD::NOT_KILLED) ?
1362
1643
    (thd_arg->is_error() ? thd_arg->main_da.sql_errno() : 0) :
1363
 
    (thd_arg->killed_errno());
 
1644
    ((thd_arg->system_thread & SYSTEM_THREAD_DELAYED_INSERT) ? 0 :
 
1645
     thd_arg->killed_errno());
1364
1646
  
1365
1647
  time(&end_time);
1366
1648
  exec_time = (ulong) (end_time  - thd_arg->start_time);
1368
1650
    @todo this means that if we have no catalog, then it is replicated
1369
1651
    as an existing catalog of length zero. is that safe? /sven
1370
1652
  */
1371
 
  catalog_len = (catalog) ? (uint32_t) strlen(catalog) : 0;
 
1653
  catalog_len = (catalog) ? (uint32) strlen(catalog) : 0;
1372
1654
  /* status_vars_len is set just before writing the event */
1373
 
  db_len = (db) ? (uint32_t) strlen(db) : 0;
 
1655
  db_len = (db) ? (uint32) strlen(db) : 0;
1374
1656
  if (thd_arg->variables.collation_database != thd_arg->db_charset)
1375
1657
    charset_database_number= thd_arg->variables.collation_database->number;
1376
1658
  
1381
1663
    But it's likely that we don't want to use 32 bits for 3 bits; in the future
1382
1664
    we will probably want to reclaim the 29 bits. So we need the &.
1383
1665
  */
1384
 
  flags2= (uint32_t) (thd_arg->options & OPTIONS_WRITTEN_TO_BIN_LOG);
 
1666
  flags2= (uint32) (thd_arg->options & OPTIONS_WRITTEN_TO_BIN_LOG);
1385
1667
  assert(thd_arg->variables.character_set_client->number < 256*256);
1386
1668
  assert(thd_arg->variables.collation_connection->number < 256*256);
1387
1669
  assert(thd_arg->variables.collation_server->number < 256*256);
1402
1684
  else
1403
1685
    time_zone_len= 0;
1404
1686
}
 
1687
#endif /* MYSQL_CLIENT */
1405
1688
 
1406
1689
 
1407
1690
/* 2 utility functions for the next method */
1433
1716
static int
1434
1717
get_str_len_and_pointer(const Log_event::Byte **src,
1435
1718
                        const char **dst,
1436
 
                        uint32_t *len,
 
1719
                        uint *len,
1437
1720
                        const Log_event::Byte *end)
1438
1721
{
1439
1722
  if (*src >= end)
1440
1723
    return -1;       // Will be UINT_MAX in two-complement arithmetics
1441
 
  uint32_t length= **src;
 
1724
  uint length= **src;
1442
1725
  if (length > 0)
1443
1726
  {
1444
1727
    if (*src + length >= end)
1452
1735
 
1453
1736
static void copy_str_and_move(const char **src, 
1454
1737
                              Log_event::Byte **dst, 
1455
 
                              uint32_t len)
 
1738
                              uint len)
1456
1739
{
1457
1740
  memcpy(*dst, *src, len);
1458
1741
  *src= (const char *)*dst;
1461
1744
}
1462
1745
 
1463
1746
 
 
1747
static char const *
 
1748
code_name(int code)
 
1749
{
 
1750
  static char buf[255];
 
1751
  switch (code) {
 
1752
  case Q_FLAGS2_CODE: return "Q_FLAGS2_CODE";
 
1753
  case Q_SQL_MODE_CODE: return "Q_SQL_MODE_CODE";
 
1754
  case Q_CATALOG_CODE: return "Q_CATALOG_CODE";
 
1755
  case Q_AUTO_INCREMENT: return "Q_AUTO_INCREMENT";
 
1756
  case Q_CHARSET_CODE: return "Q_CHARSET_CODE";
 
1757
  case Q_TIME_ZONE_CODE: return "Q_TIME_ZONE_CODE";
 
1758
  case Q_CATALOG_NZ_CODE: return "Q_CATALOG_NZ_CODE";
 
1759
  case Q_LC_TIME_NAMES_CODE: return "Q_LC_TIME_NAMES_CODE";
 
1760
  case Q_CHARSET_DATABASE_CODE: return "Q_CHARSET_DATABASE_CODE";
 
1761
  }
 
1762
  sprintf(buf, "CODE#%d", code);
 
1763
  return buf;
 
1764
}
 
1765
 
1464
1766
/**
1465
1767
   Macro to check that there is enough space to read from memory.
1466
1768
 
1470
1772
 */
1471
1773
#define CHECK_SPACE(PTR,END,CNT)                      \
1472
1774
  do {                                                \
1473
 
    assert((PTR) + (CNT) <= (END));                   \
 
1775
    assert((PTR) + (CNT) <= (END));              \
1474
1776
    if ((PTR) + (CNT) > (END)) {                      \
1475
1777
      query= 0;                                       \
1476
 
      return;                                         \
 
1778
      return;                               \
1477
1779
    }                                                 \
1478
1780
  } while (0)
1479
1781
 
1481
1783
/**
1482
1784
  This is used by the SQL slave thread to prepare the event before execution.
1483
1785
*/
1484
 
Query_log_event::Query_log_event(const char* buf, uint32_t event_len,
 
1786
Query_log_event::Query_log_event(const char* buf, uint event_len,
1485
1787
                                 const Format_description_log_event
1486
1788
                                 *description_event,
1487
1789
                                 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),
 
1790
  :Log_event(buf, description_event), data_buf(0), query(NullS),
 
1791
   db(NullS), catalog_len(0), status_vars_len(0),
1490
1792
   flags2_inited(0), sql_mode_inited(0), charset_inited(0),
1491
1793
   auto_increment_increment(1), auto_increment_offset(1),
1492
1794
   time_zone_len(0), lc_time_names_number(0), charset_database_number(0)
1493
1795
{
1494
 
  uint32_t data_len;
1495
 
  uint32_t tmp;
1496
 
  uint8_t common_header_len, post_header_len;
 
1796
  ulong data_len;
 
1797
  uint32 tmp;
 
1798
  uint8 common_header_len, post_header_len;
1497
1799
  Log_event::Byte *start;
1498
1800
  const Log_event::Byte *end;
1499
1801
  bool catalog_nz= 1;
1531
1833
      be even bigger, but this will suffice to catch most corruption
1532
1834
      errors that can lead to a crash.
1533
1835
    */
1534
 
    if (status_vars_len > cmin(data_len, (uint32_t)MAX_SIZE_LOG_EVENT_STATUS))
 
1836
    if (status_vars_len > min(data_len, MAX_SIZE_LOG_EVENT_STATUS))
1535
1837
    {
1536
1838
      query= 0;
1537
1839
      return;
1560
1862
      break;
1561
1863
    case Q_SQL_MODE_CODE:
1562
1864
    {
 
1865
      char buff[22];
1563
1866
      CHECK_SPACE(pos, end, 8);
1564
1867
      sql_mode_inited= 1;
1565
 
      sql_mode= (ulong) uint8korr(pos); // QQ: Fix when sql_mode is uint64_t
 
1868
      sql_mode= (ulong) uint8korr(pos); // QQ: Fix when sql_mode is ulonglong
1566
1869
      pos+= 8;
1567
1870
      break;
1568
1871
    }
1616
1919
      break;
1617
1920
    default:
1618
1921
      /* That's why you must write status vars in growing order of code */
1619
 
      pos= (const unsigned char*) end;                         // Break loop
 
1922
      pos= (const uchar*) end;                         // Break loop
1620
1923
    }
1621
1924
  }
1622
1925
  
1652
1955
  */
1653
1956
 
1654
1957
  /* A 2nd variable part; this is common to all versions */ 
1655
 
  memcpy(start, end, data_len);          // Copy db and query
 
1958
  memcpy((char*) start, end, data_len);          // Copy db and query
1656
1959
  start[data_len]= '\0';              // End query with \0 (For safetly)
1657
1960
  db= (char *)start;
1658
1961
  query= (char *)(start + db_len + 1);
1661
1964
}
1662
1965
 
1663
1966
 
 
1967
#ifdef MYSQL_CLIENT
 
1968
/**
 
1969
  Query_log_event::print().
 
1970
 
 
1971
  @todo
 
1972
    print the catalog ??
 
1973
*/
 
1974
void Query_log_event::print_query_header(IO_CACHE* file,
 
1975
                                         PRINT_EVENT_INFO* print_event_info)
 
1976
{
 
1977
  // TODO: print the catalog ??
 
1978
  char buff[40],*end;                           // Enough for SET TIMESTAMP
 
1979
  bool different_db= 1;
 
1980
  uint32 tmp;
 
1981
 
 
1982
  if (!print_event_info->short_form)
 
1983
  {
 
1984
    print_header(file, print_event_info, false);
 
1985
    my_b_printf(file, "\t%s\tthread_id=%lu\texec_time=%lu\terror_code=%d\n",
 
1986
                get_type_str(), (ulong) thread_id, (ulong) exec_time,
 
1987
                error_code);
 
1988
  }
 
1989
 
 
1990
  if (!(flags & LOG_EVENT_SUPPRESS_USE_F) && db)
 
1991
  {
 
1992
    if ((different_db= memcmp(print_event_info->db, db, db_len + 1)))
 
1993
      memcpy(print_event_info->db, db, db_len + 1);
 
1994
    if (db[0] && different_db) 
 
1995
      my_b_printf(file, "use %s%s\n", db, print_event_info->delimiter);
 
1996
  }
 
1997
 
 
1998
  end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10);
 
1999
  end= strmov(end, print_event_info->delimiter);
 
2000
  *end++='\n';
 
2001
  my_b_write(file, (uchar*) buff, (uint) (end-buff));
 
2002
  if ((!print_event_info->thread_id_printed ||
 
2003
       ((flags & LOG_EVENT_THREAD_SPECIFIC_F) &&
 
2004
        thread_id != print_event_info->thread_id)))
 
2005
  {
 
2006
    // If --short-form, print deterministic value instead of pseudo_thread_id.
 
2007
    my_b_printf(file,"SET @@session.pseudo_thread_id=%lu%s\n",
 
2008
                short_form ? 999999999 : (ulong)thread_id,
 
2009
                print_event_info->delimiter);
 
2010
    print_event_info->thread_id= thread_id;
 
2011
    print_event_info->thread_id_printed= 1;
 
2012
  }
 
2013
 
 
2014
  /*
 
2015
    If flags2_inited==0, this is an event from 3.23 or 4.0; nothing to
 
2016
    print (remember we don't produce mixed relay logs so there cannot be
 
2017
    5.0 events before that one so there is nothing to reset).
 
2018
  */
 
2019
  if (likely(flags2_inited)) /* likely as this will mainly read 5.0 logs */
 
2020
  {
 
2021
    /* tmp is a bitmask of bits which have changed. */
 
2022
    if (likely(print_event_info->flags2_inited)) 
 
2023
      /* All bits which have changed */
 
2024
      tmp= (print_event_info->flags2) ^ flags2;
 
2025
    else /* that's the first Query event we read */
 
2026
    {
 
2027
      print_event_info->flags2_inited= 1;
 
2028
      tmp= ~((uint32)0); /* all bits have changed */
 
2029
    }
 
2030
 
 
2031
    if (unlikely(tmp)) /* some bits have changed */
 
2032
    {
 
2033
      bool need_comma= 0;
 
2034
      my_b_printf(file, "SET ");
 
2035
      print_set_option(file, tmp, OPTION_NO_FOREIGN_KEY_CHECKS, ~flags2,
 
2036
                   "@@session.foreign_key_checks", &need_comma);
 
2037
      print_set_option(file, tmp, OPTION_AUTO_IS_NULL, flags2,
 
2038
                   "@@session.sql_auto_is_null", &need_comma);
 
2039
      print_set_option(file, tmp, OPTION_RELAXED_UNIQUE_CHECKS, ~flags2,
 
2040
                   "@@session.unique_checks", &need_comma);
 
2041
      my_b_printf(file,"%s\n", print_event_info->delimiter);
 
2042
      print_event_info->flags2= flags2;
 
2043
    }
 
2044
  }
 
2045
 
 
2046
  /*
 
2047
    Now the session variables;
 
2048
    it's more efficient to pass SQL_MODE as a number instead of a
 
2049
    comma-separated list.
 
2050
    FOREIGN_KEY_CHECKS, SQL_AUTO_IS_NULL, UNIQUE_CHECKS are session-only
 
2051
    variables (they have no global version; they're not listed in
 
2052
    sql_class.h), The tests below work for pure binlogs or pure relay
 
2053
    logs. Won't work for mixed relay logs but we don't create mixed
 
2054
    relay logs (that is, there is no relay log with a format change
 
2055
    except within the 3 first events, which mysqlbinlog handles
 
2056
    gracefully). So this code should always be good.
 
2057
  */
 
2058
 
 
2059
  if (print_event_info->auto_increment_increment != auto_increment_increment ||
 
2060
      print_event_info->auto_increment_offset != auto_increment_offset)
 
2061
  {
 
2062
    my_b_printf(file,"SET @@session.auto_increment_increment=%lu, @@session.auto_increment_offset=%lu%s\n",
 
2063
                auto_increment_increment,auto_increment_offset,
 
2064
                print_event_info->delimiter);
 
2065
    print_event_info->auto_increment_increment= auto_increment_increment;
 
2066
    print_event_info->auto_increment_offset=    auto_increment_offset;
 
2067
  }
 
2068
 
 
2069
  /* TODO: print the catalog when we feature SET CATALOG */
 
2070
 
 
2071
  if (likely(charset_inited) &&
 
2072
      (unlikely(!print_event_info->charset_inited ||
 
2073
                bcmp((uchar*) print_event_info->charset, (uchar*) charset, 6))))
 
2074
  {
 
2075
    CHARSET_INFO *cs_info= get_charset(uint2korr(charset), MYF(MY_WME));
 
2076
    if (cs_info)
 
2077
    {
 
2078
      /* for mysql client */
 
2079
      my_b_printf(file, "/*!\\C %s */%s\n",
 
2080
                  cs_info->csname, print_event_info->delimiter);
 
2081
    }
 
2082
    my_b_printf(file,"SET "
 
2083
                "@@session.character_set_client=%d,"
 
2084
                "@@session.collation_connection=%d,"
 
2085
                "@@session.collation_server=%d"
 
2086
                "%s\n",
 
2087
                uint2korr(charset),
 
2088
                uint2korr(charset+2),
 
2089
                uint2korr(charset+4),
 
2090
                print_event_info->delimiter);
 
2091
    memcpy(print_event_info->charset, charset, 6);
 
2092
    print_event_info->charset_inited= 1;
 
2093
  }
 
2094
  if (time_zone_len)
 
2095
  {
 
2096
    if (bcmp((uchar*) print_event_info->time_zone_str,
 
2097
             (uchar*) time_zone_str, time_zone_len+1))
 
2098
    {
 
2099
      my_b_printf(file,"SET @@session.time_zone='%s'%s\n",
 
2100
                  time_zone_str, print_event_info->delimiter);
 
2101
      memcpy(print_event_info->time_zone_str, time_zone_str, time_zone_len+1);
 
2102
    }
 
2103
  }
 
2104
  if (lc_time_names_number != print_event_info->lc_time_names_number)
 
2105
  {
 
2106
    my_b_printf(file, "SET @@session.lc_time_names=%d%s\n",
 
2107
                lc_time_names_number, print_event_info->delimiter);
 
2108
    print_event_info->lc_time_names_number= lc_time_names_number;
 
2109
  }
 
2110
  if (charset_database_number != print_event_info->charset_database_number)
 
2111
  {
 
2112
    if (charset_database_number)
 
2113
      my_b_printf(file, "SET @@session.collation_database=%d%s\n",
 
2114
                  charset_database_number, print_event_info->delimiter);
 
2115
    else
 
2116
      my_b_printf(file, "SET @@session.collation_database=DEFAULT%s\n",
 
2117
                  print_event_info->delimiter);
 
2118
    print_event_info->charset_database_number= charset_database_number;
 
2119
  }
 
2120
}
 
2121
 
 
2122
 
 
2123
void Query_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
2124
{
 
2125
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
2126
 
 
2127
  print_query_header(&cache, print_event_info);
 
2128
  my_b_write(&cache, (uchar*) query, q_len);
 
2129
  my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
 
2130
}
 
2131
#endif /* MYSQL_CLIENT */
 
2132
 
 
2133
 
1664
2134
/*
1665
2135
  Query_log_event::do_apply_event()
1666
2136
*/
 
2137
 
 
2138
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 
2139
 
1667
2140
int Query_log_event::do_apply_event(Relay_log_info const *rli)
1668
2141
{
1669
2142
  return do_apply_event(rli, query, q_len);
1675
2148
  Compare the values of "affected rows" around here. Something
1676
2149
  like:
1677
2150
  @code
1678
 
     if ((uint32_t) affected_in_event != (uint32_t) affected_on_slave)
 
2151
     if ((uint32) affected_in_event != (uint32) affected_on_slave)
1679
2152
     {
1680
2153
     sql_print_error("Slave: did not get the expected number of affected \
1681
2154
     rows running query from master - expected %d, got %d (this numbers \
1688
2161
  to ignore it you would use --slave-skip-errors...
1689
2162
*/
1690
2163
int Query_log_event::do_apply_event(Relay_log_info const *rli,
1691
 
                                      const char *query_arg, uint32_t q_len_arg)
 
2164
                                      const char *query_arg, uint32 q_len_arg)
1692
2165
{
1693
2166
  LEX_STRING new_db;
1694
2167
  int expected_error,actual_error= 0;
1736
2209
    thd->set_time((time_t)when);
1737
2210
    thd->query_length= q_len_arg;
1738
2211
    thd->query= (char*)query_arg;
1739
 
    pthread_mutex_lock(&LOCK_thread_count);
 
2212
    VOID(pthread_mutex_lock(&LOCK_thread_count));
1740
2213
    thd->query_id = next_query_id();
1741
 
    pthread_mutex_unlock(&LOCK_thread_count);
 
2214
    VOID(pthread_mutex_unlock(&LOCK_thread_count));
1742
2215
    thd->variables.pseudo_thread_id= thread_id;         // for temp tables
1743
2216
 
1744
2217
    if (ignored_error_code((expected_error= error_code)) ||
1804
2277
        thd->variables.lc_time_names= &my_locale_en_US;
1805
2278
      if (charset_database_number)
1806
2279
      {
1807
 
        const CHARSET_INFO *cs;
 
2280
        CHARSET_INFO *cs;
1808
2281
        if (!(cs= get_charset(charset_database_number, MYF(0))))
1809
2282
        {
1810
2283
          char buf[20];
1835
2308
        clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); /* Can ignore query */
1836
2309
      else
1837
2310
      {
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);
 
2311
        rli->report(ERROR_LEVEL, expected_error, 
 
2312
                          "\
 
2313
Query partially completed on the master (error on master: %d) \
 
2314
and was aborted. There is a chance that your master is inconsistent at this \
 
2315
point. If you are sure that your master is ok, run this query manually on the \
 
2316
slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; \
 
2317
START SLAVE; . Query: '%s'", expected_error, thd->query);
1847
2318
        thd->is_slave_error= 1;
1848
2319
      }
1849
2320
      goto end;
1850
2321
    }
1851
2322
 
 
2323
    /* If the query was not ignored, it is printed to the general log */
 
2324
    if (!thd->is_error() || thd->main_da.sql_errno() != ER_SLAVE_IGNORED_TABLE)
 
2325
      general_log_write(thd, COM_QUERY, thd->query, thd->query_length);
 
2326
 
1852
2327
compare_errors:
1853
2328
 
1854
2329
     /*
1857
2332
    */
1858
2333
    actual_error= thd->is_error() ? thd->main_da.sql_errno() : 0;
1859
2334
    if ((expected_error != actual_error) &&
1860
 
        expected_error &&
1861
 
        !ignored_error_code(actual_error) &&
1862
 
        !ignored_error_code(expected_error))
 
2335
        expected_error &&
 
2336
        !ignored_error_code(actual_error) &&
 
2337
        !ignored_error_code(expected_error))
1863
2338
    {
1864
2339
      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);
 
2340
                      "\
 
2341
Query caused different errors on master and slave.     \
 
2342
Error on master: '%s' (%d), Error on slave: '%s' (%d). \
 
2343
Default database: '%s'. Query: '%s'",
 
2344
                      ER_SAFE(expected_error),
 
2345
                      expected_error,
 
2346
                      actual_error ? thd->main_da.message() : "no error",
 
2347
                      actual_error,
 
2348
                      print_slave_db_safe(db), query_arg);
1873
2349
      thd->is_slave_error= 1;
1874
2350
    }
1875
2351
    /*
1887
2363
    else if (thd->is_slave_error || thd->is_fatal_error)
1888
2364
    {
1889
2365
      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")),
 
2366
                      "Error '%s' on query. Default database: '%s'. Query: '%s'",
 
2367
                      (actual_error ? thd->main_da.message() :
 
2368
                       "unexpected success or fatal error"),
1893
2369
                      print_slave_db_safe(thd->db), query_arg);
1894
2370
      thd->is_slave_error= 1;
1895
2371
    }
1897
2373
    /*
1898
2374
      TODO: compare the values of "affected rows" around here. Something
1899
2375
      like:
1900
 
      if ((uint32_t) affected_in_event != (uint32_t) affected_on_slave)
 
2376
      if ((uint32) affected_in_event != (uint32) affected_on_slave)
1901
2377
      {
1902
2378
      sql_print_error("Slave: did not get the expected number of affected \
1903
2379
      rows running query from master - expected %d, got %d (this numbers \
1918
2394
  } /* End of if (db_ok(... */
1919
2395
 
1920
2396
end:
1921
 
  pthread_mutex_lock(&LOCK_thread_count);
 
2397
  VOID(pthread_mutex_lock(&LOCK_thread_count));
1922
2398
  /*
1923
2399
    Probably we have set thd->query, thd->db, thd->catalog to point to places
1924
2400
    in the data_buf of this event. Now the event is going to be deleted
1925
2401
    probably, so data_buf will be freed, so the thd->... listed above will be
1926
2402
    pointers to freed memory. 
1927
2403
    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
 
2404
    used. Note that "cleanup" queries like automatic DROP TEMPORARY TABLE
1929
2405
    don't suffer from these assignments to 0 as DROP TEMPORARY
1930
 
    Table uses the db.table syntax.
 
2406
    TABLE uses the db.table syntax.
1931
2407
  */
1932
2408
  thd->catalog= 0;
1933
2409
  thd->set_db(NULL, 0);                 /* will free the current database */
1934
2410
  thd->query= 0;                        // just to be sure
1935
2411
  thd->query_length= 0;
1936
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
2412
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1937
2413
  close_thread_tables(thd);      
1938
2414
  /*
1939
2415
    As a disk space optimization, future masters will not log an event for
1988
2464
  return(Log_event::do_shall_skip(rli));
1989
2465
}
1990
2466
 
 
2467
#endif
 
2468
 
1991
2469
 
1992
2470
/**************************************************************************
1993
2471
        Start_log_event_v3 methods
1994
2472
**************************************************************************/
1995
2473
 
 
2474
#ifndef MYSQL_CLIENT
1996
2475
Start_log_event_v3::Start_log_event_v3()
1997
2476
  :Log_event(), created(0), binlog_version(BINLOG_VERSION),
1998
2477
   artificial_event(0), dont_set_created(0)
1999
2478
{
2000
2479
  memcpy(server_version, ::server_version, ST_SERVER_VER_LEN);
2001
2480
}
 
2481
#endif
2002
2482
 
2003
2483
/*
2004
2484
  Start_log_event_v3::pack_info()
2005
2485
*/
2006
2486
 
 
2487
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2007
2488
void Start_log_event_v3::pack_info(Protocol *protocol)
2008
2489
{
2009
2490
  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: ");
 
2491
  pos= strmov(buf, "Server ver: ");
 
2492
  pos= strmov(pos, server_version);
 
2493
  pos= strmov(pos, ", Binlog ver: ");
2013
2494
  pos= int10_to_str(binlog_version, pos, 10);
2014
2495
  protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
2015
2496
}
2016
 
 
 
2497
#endif
 
2498
 
 
2499
 
 
2500
/*
 
2501
  Start_log_event_v3::print()
 
2502
*/
 
2503
 
 
2504
#ifdef MYSQL_CLIENT
 
2505
void Start_log_event_v3::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
2506
{
 
2507
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
2508
                               Write_on_release_cache::FLUSH_F);
 
2509
 
 
2510
  if (!print_event_info->short_form)
 
2511
  {
 
2512
    print_header(&cache, print_event_info, false);
 
2513
    my_b_printf(&cache, "\tStart: binlog v %d, server v %s created ",
 
2514
                binlog_version, server_version);
 
2515
    print_timestamp(&cache);
 
2516
    if (created)
 
2517
      my_b_printf(&cache," at startup");
 
2518
    my_b_printf(&cache, "\n");
 
2519
    if (flags & LOG_EVENT_BINLOG_IN_USE_F)
 
2520
      my_b_printf(&cache, "# Warning: this binlog was not closed properly. "
 
2521
                  "Most probably mysqld crashed writing it.\n");
 
2522
  }
 
2523
  if (!artificial_event && created)
 
2524
  {
 
2525
#ifdef WHEN_WE_HAVE_THE_RESET_CONNECTION_SQL_COMMAND
 
2526
    /*
 
2527
      This is for mysqlbinlog: like in replication, we want to delete the stale
 
2528
      tmp files left by an unclean shutdown of mysqld (temporary tables)
 
2529
      and rollback unfinished transaction.
 
2530
      Probably this can be done with RESET CONNECTION (syntax to be defined).
 
2531
    */
 
2532
    my_b_printf(&cache,"RESET CONNECTION%s\n", print_event_info->delimiter);
 
2533
#else
 
2534
    my_b_printf(&cache,"ROLLBACK%s\n", print_event_info->delimiter);
 
2535
#endif
 
2536
  }
 
2537
  if (temp_buf &&
 
2538
      print_event_info->base64_output_mode != BASE64_OUTPUT_NEVER &&
 
2539
      !print_event_info->short_form)
 
2540
  {
 
2541
    my_b_printf(&cache, "BINLOG '\n");
 
2542
    print_base64(&cache, print_event_info, false);
 
2543
    print_event_info->printed_fd_event= true;
 
2544
  }
 
2545
  return;
 
2546
}
 
2547
#endif /* MYSQL_CLIENT */
2017
2548
 
2018
2549
/*
2019
2550
  Start_log_event_v3::Start_log_event_v3()
2041
2572
  Start_log_event_v3::write()
2042
2573
*/
2043
2574
 
 
2575
#ifndef MYSQL_CLIENT
2044
2576
bool Start_log_event_v3::write(IO_CACHE* file)
2045
2577
{
2046
2578
  char buff[START_V3_HEADER_LEN];
2050
2582
    created= when= get_time();
2051
2583
  int4store(buff + ST_CREATED_OFFSET,created);
2052
2584
  return (write_header(file, sizeof(buff)) ||
2053
 
          my_b_safe_write(file, (unsigned char*) buff, sizeof(buff)));
 
2585
          my_b_safe_write(file, (uchar*) buff, sizeof(buff)));
2054
2586
}
2055
 
 
 
2587
#endif
 
2588
 
 
2589
 
 
2590
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2056
2591
 
2057
2592
/**
2058
2593
  Start_log_event_v3::do_apply_event() .
2060
2595
 
2061
2596
    IMPLEMENTATION
2062
2597
    - To handle the case where the master died without having time to write
2063
 
    DROP TEMPORARY Table, DO RELEASE_LOCK (prepared statements' deletion is
 
2598
    DROP TEMPORARY TABLE, DO RELEASE_LOCK (prepared statements' deletion is
2064
2599
    TODO), we clean up all temporary tables that we got, if we are sure we
2065
2600
    can (see below).
2066
2601
 
2117
2652
  }
2118
2653
  return(0);
2119
2654
}
 
2655
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
2120
2656
 
2121
2657
/***************************************************************************
2122
2658
       Format_description_log_event methods
2139
2675
*/
2140
2676
 
2141
2677
Format_description_log_event::
2142
 
Format_description_log_event(uint8_t binlog_ver, const char* server_ver)
 
2678
Format_description_log_event(uint8 binlog_ver, const char* server_ver)
2143
2679
  :Start_log_event_v3(), event_type_permutation(0)
2144
2680
{
2145
2681
  binlog_version= binlog_ver;
2149
2685
    common_header_len= LOG_EVENT_HEADER_LEN;
2150
2686
    number_of_event_types= LOG_EVENT_TYPES;
2151
2687
    /* we'll catch my_malloc() error in is_valid() */
2152
 
    post_header_len=(uint8_t*) my_malloc(number_of_event_types*sizeof(uint8_t),
 
2688
    post_header_len=(uint8*) my_malloc(number_of_event_types*sizeof(uint8),
2153
2689
                                       MYF(MY_ZEROFILL));
2154
2690
    /*
2155
2691
      This long list of assignments is not beautiful, but I see no way to
2186
2722
      describes what those old master versions send.
2187
2723
    */
2188
2724
    if (binlog_ver==1)
2189
 
      my_stpcpy(server_version, server_ver ? server_ver : "3.23");
 
2725
      strmov(server_version, server_ver ? server_ver : "3.23");
2190
2726
    else
2191
 
      my_stpcpy(server_version, server_ver ? server_ver : "4.0");
 
2727
      strmov(server_version, server_ver ? server_ver : "4.0");
2192
2728
    common_header_len= binlog_ver==1 ? OLD_HEADER_LEN :
2193
2729
      LOG_EVENT_MINIMAL_HEADER_LEN;
2194
2730
    /*
2199
2735
      make the slave detect less corruptions).
2200
2736
    */
2201
2737
    number_of_event_types= FORMAT_DESCRIPTION_EVENT - 1;
2202
 
    post_header_len=(uint8_t*) my_malloc(number_of_event_types*sizeof(uint8_t),
 
2738
    post_header_len=(uint8*) my_malloc(number_of_event_types*sizeof(uint8),
2203
2739
                                       MYF(0));
2204
2740
    if (post_header_len)
2205
2741
    {
2247
2783
 
2248
2784
Format_description_log_event::
2249
2785
Format_description_log_event(const char* buf,
2250
 
                             uint32_t event_len,
 
2786
                             uint event_len,
2251
2787
                             const
2252
2788
                             Format_description_log_event*
2253
2789
                             description_event)
2259
2795
  number_of_event_types=
2260
2796
    event_len-(LOG_EVENT_MINIMAL_HEADER_LEN+ST_COMMON_HEADER_LEN_OFFSET+1);
2261
2797
  /* 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,
 
2798
  post_header_len= (uint8*) my_memdup((uchar*)buf+ST_COMMON_HEADER_LEN_OFFSET+1,
2263
2799
                                      number_of_event_types*
2264
2800
                                      sizeof(*post_header_len), MYF(0));
2265
2801
  calc_server_version_split();
2334
2870
    if (number_of_event_types != 22)
2335
2871
    {
2336
2872
      /* this makes is_valid() return false. */
2337
 
      free(post_header_len);
 
2873
      my_free(post_header_len, MYF(MY_ALLOW_ZERO_PTR));
2338
2874
      post_header_len= NULL;
2339
2875
      return;
2340
2876
    }
2341
 
    static const uint8_t perm[23]=
 
2877
    static const uint8 perm[23]=
2342
2878
      {
2343
2879
        UNKNOWN_EVENT, START_EVENT_V3, QUERY_EVENT, STOP_EVENT, ROTATE_EVENT,
2344
2880
        INTVAR_EVENT, LOAD_EVENT, SLAVE_EVENT, CREATE_FILE_EVENT,
2359
2895
      Since we use (permuted) event id's to index the post_header_len
2360
2896
      array, we need to permute the post_header_len array too.
2361
2897
    */
2362
 
    uint8_t post_header_len_temp[23];
 
2898
    uint8 post_header_len_temp[23];
2363
2899
    for (int i= 1; i < 23; i++)
2364
2900
      post_header_len_temp[perm[i] - 1]= post_header_len[i - 1];
2365
2901
    for (int i= 0; i < 22; i++)
2368
2904
  return;
2369
2905
}
2370
2906
 
 
2907
#ifndef MYSQL_CLIENT
2371
2908
bool Format_description_log_event::write(IO_CACHE* file)
2372
2909
{
2373
2910
  /*
2374
2911
    We don't call Start_log_event_v3::write() because this would make 2
2375
2912
    my_b_safe_write().
2376
2913
  */
2377
 
  unsigned char buff[FORMAT_DESCRIPTION_HEADER_LEN];
 
2914
  uchar buff[FORMAT_DESCRIPTION_HEADER_LEN];
2378
2915
  int2store(buff + ST_BINLOG_VER_OFFSET,binlog_version);
2379
 
  memcpy(buff + ST_SERVER_VER_OFFSET,server_version,ST_SERVER_VER_LEN);
 
2916
  memcpy((char*) buff + ST_SERVER_VER_OFFSET,server_version,ST_SERVER_VER_LEN);
2380
2917
  if (!dont_set_created)
2381
2918
    created= when= get_time();
2382
2919
  int4store(buff + ST_CREATED_OFFSET,created);
2383
2920
  buff[ST_COMMON_HEADER_LEN_OFFSET]= LOG_EVENT_HEADER_LEN;
2384
 
  memcpy(buff+ST_COMMON_HEADER_LEN_OFFSET+1, post_header_len,
 
2921
  memcpy((char*) buff+ST_COMMON_HEADER_LEN_OFFSET+1, (uchar*) post_header_len,
2385
2922
         LOG_EVENT_TYPES);
2386
2923
  return (write_header(file, sizeof(buff)) ||
2387
2924
          my_b_safe_write(file, buff, sizeof(buff)));
2388
2925
}
2389
 
 
2390
 
 
 
2926
#endif
 
2927
 
 
2928
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2391
2929
int Format_description_log_event::do_apply_event(Relay_log_info const *rli)
2392
2930
{
2393
2931
  /*
2405
2943
  {
2406
2944
    /* This is not an error (XA is safe), just an information */
2407
2945
    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."));
 
2946
                "Rolling back unfinished transaction (no COMMIT "
 
2947
                "or ROLLBACK in relay log). A probable cause is that "
 
2948
                "the master died while writing the transaction to "
 
2949
                "its binary log, thus rolled back too."); 
2412
2950
    const_cast<Relay_log_info*>(rli)->cleanup_context(thd, 1);
2413
2951
  }
2414
2952
  /*
2416
2954
    perform, we don't call Start_log_event_v3::do_apply_event()
2417
2955
    (this was just to update the log's description event).
2418
2956
  */
2419
 
  if (server_id != (uint32_t) ::server_id)
 
2957
  if (server_id != (uint32) ::server_id)
2420
2958
  {
2421
2959
    /*
2422
2960
      If the event was not requested by the slave i.e. the master sent
2438
2976
  delete rli->relay_log.description_event_for_exec;
2439
2977
  rli->relay_log.description_event_for_exec= this;
2440
2978
 
2441
 
  if (server_id == (uint32_t) ::server_id)
 
2979
  if (server_id == (uint32) ::server_id)
2442
2980
  {
2443
2981
    /*
2444
2982
      We only increase the relay log position if we are skipping
2463
3001
}
2464
3002
 
2465
3003
Log_event::enum_skip_reason
2466
 
Format_description_log_event::do_shall_skip(Relay_log_info *rli __attribute__((unused)))
 
3004
Format_description_log_event::do_shall_skip(Relay_log_info *rli __attribute__((__unused__)))
2467
3005
{
2468
3006
  return Log_event::EVENT_SKIP_NOT;
2469
3007
}
2470
3008
 
 
3009
#endif
 
3010
 
2471
3011
 
2472
3012
/**
2473
3013
   Splits the event's 'server_version' string into three numeric pieces stored
2482
3022
{
2483
3023
  char *p= server_version, *r;
2484
3024
  ulong number;
2485
 
  for (uint32_t i= 0; i<=2; i++)
 
3025
  for (uint i= 0; i<=2; i++)
2486
3026
  {
2487
3027
    number= strtoul(p, &r, 10);
2488
 
    server_version_split[i]= (unsigned char)number;
2489
 
    assert(number < 256); // fit in unsigned char
 
3028
    server_version_split[i]= (uchar)number;
 
3029
    assert(number < 256); // fit in uchar
2490
3030
    p= r;
2491
3031
    assert(!((i == 0) && (*r != '.'))); // should be true in practice
2492
3032
    if (*r == '.')
2516
3056
  Load_log_event::pack_info()
2517
3057
*/
2518
3058
 
2519
 
uint32_t Load_log_event::get_query_buffer_length()
 
3059
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 
3060
uint Load_log_event::get_query_buffer_length()
2520
3061
{
2521
3062
  return
2522
3063
    5 + db_len + 3 +                        // "use DB; "
2523
3064
    18 + fname_len + 2 +                    // "LOAD DATA INFILE 'file''"
2524
3065
    7 +                                     // LOCAL
2525
3066
    9 +                                     // " REPLACE or IGNORE "
2526
 
    13 + table_name_len*2 +                 // "INTO Table `table`"
 
3067
    13 + table_name_len*2 +                 // "INTO TABLE `table`"
2527
3068
    21 + sql_ex.field_term_len*4 + 2 +      // " FIELDS TERMINATED BY 'str'"
2528
3069
    23 + sql_ex.enclosed_len*4 + 2 +        // " OPTIONALLY ENCLOSED BY 'str'"
2529
3070
    12 + sql_ex.escaped_len*4 + 2 +         // " ESCAPED BY 'str'"
2541
3082
 
2542
3083
  if (need_db && db && db_len)
2543
3084
  {
2544
 
    pos= my_stpcpy(pos, "use `");
 
3085
    pos= strmov(pos, "use `");
2545
3086
    memcpy(pos, db, db_len);
2546
 
    pos= my_stpcpy(pos+db_len, "`; ");
 
3087
    pos= strmov(pos+db_len, "`; ");
2547
3088
  }
2548
3089
 
2549
 
  pos= my_stpcpy(pos, "LOAD DATA ");
 
3090
  pos= strmov(pos, "LOAD DATA ");
2550
3091
 
2551
3092
  if (fn_start)
2552
3093
    *fn_start= pos;
2553
3094
 
2554
3095
  if (check_fname_outside_temp_buf())
2555
 
    pos= my_stpcpy(pos, "LOCAL ");
2556
 
  pos= my_stpcpy(pos, "INFILE '");
 
3096
    pos= strmov(pos, "LOCAL ");
 
3097
  pos= strmov(pos, "INFILE '");
2557
3098
  memcpy(pos, fname, fname_len);
2558
 
  pos= my_stpcpy(pos+fname_len, "' ");
 
3099
  pos= strmov(pos+fname_len, "' ");
2559
3100
 
2560
3101
  if (sql_ex.opt_flags & REPLACE_FLAG)
2561
 
    pos= my_stpcpy(pos, " REPLACE ");
 
3102
    pos= strmov(pos, " REPLACE ");
2562
3103
  else if (sql_ex.opt_flags & IGNORE_FLAG)
2563
 
    pos= my_stpcpy(pos, " IGNORE ");
 
3104
    pos= strmov(pos, " IGNORE ");
2564
3105
 
2565
 
  pos= my_stpcpy(pos ,"INTO");
 
3106
  pos= strmov(pos ,"INTO");
2566
3107
 
2567
3108
  if (fn_end)
2568
3109
    *fn_end= pos;
2569
3110
 
2570
 
  pos= my_stpcpy(pos ," Table `");
 
3111
  pos= strmov(pos ," TABLE `");
2571
3112
  memcpy(pos, table_name, table_name_len);
2572
3113
  pos+= table_name_len;
2573
3114
 
2574
3115
  /* We have to create all optinal fields as the default is not empty */
2575
 
  pos= my_stpcpy(pos, "` FIELDS TERMINATED BY ");
 
3116
  pos= strmov(pos, "` FIELDS TERMINATED BY ");
2576
3117
  pos= pretty_print_str(pos, sql_ex.field_term, sql_ex.field_term_len);
2577
3118
  if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
2578
 
    pos= my_stpcpy(pos, " OPTIONALLY ");
2579
 
  pos= my_stpcpy(pos, " ENCLOSED BY ");
 
3119
    pos= strmov(pos, " OPTIONALLY ");
 
3120
  pos= strmov(pos, " ENCLOSED BY ");
2580
3121
  pos= pretty_print_str(pos, sql_ex.enclosed, sql_ex.enclosed_len);
2581
3122
 
2582
 
  pos= my_stpcpy(pos, " ESCAPED BY ");
 
3123
  pos= strmov(pos, " ESCAPED BY ");
2583
3124
  pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
2584
3125
 
2585
 
  pos= my_stpcpy(pos, " LINES TERMINATED BY ");
 
3126
  pos= strmov(pos, " LINES TERMINATED BY ");
2586
3127
  pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
2587
3128
  if (sql_ex.line_start_len)
2588
3129
  {
2589
 
    pos= my_stpcpy(pos, " STARTING BY ");
 
3130
    pos= strmov(pos, " STARTING BY ");
2590
3131
    pos= pretty_print_str(pos, sql_ex.line_start, sql_ex.line_start_len);
2591
3132
  }
2592
3133
 
2593
3134
  if ((long) skip_lines > 0)
2594
3135
  {
2595
 
    pos= my_stpcpy(pos, " IGNORE ");
2596
 
    pos= int64_t10_to_str((int64_t) skip_lines, pos, 10);
2597
 
    pos= my_stpcpy(pos," LINES ");    
 
3136
    pos= strmov(pos, " IGNORE ");
 
3137
    pos= longlong10_to_str((longlong) skip_lines, pos, 10);
 
3138
    pos= strmov(pos," LINES ");    
2598
3139
  }
2599
3140
 
2600
3141
  if (num_fields)
2601
3142
  {
2602
 
    uint32_t i;
 
3143
    uint i;
2603
3144
    const char *field= fields;
2604
 
    pos= my_stpcpy(pos, " (");
 
3145
    pos= strmov(pos, " (");
2605
3146
    for (i = 0; i < num_fields; i++)
2606
3147
    {
2607
3148
      if (i)
2628
3169
    return;
2629
3170
  print_query(true, buf, &end, 0, 0);
2630
3171
  protocol->store(buf, end-buf, &my_charset_bin);
2631
 
  free(buf);
 
3172
  my_free(buf, MYF(0));
2632
3173
}
2633
 
 
 
3174
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
 
3175
 
 
3176
 
 
3177
#ifndef MYSQL_CLIENT
2634
3178
 
2635
3179
/*
2636
3180
  Load_log_event::write_data_header()
2645
3189
  buf[L_TBL_LEN_OFFSET] = (char)table_name_len;
2646
3190
  buf[L_DB_LEN_OFFSET] = (char)db_len;
2647
3191
  int4store(buf + L_NUM_FIELDS_OFFSET, num_fields);
2648
 
  return my_b_safe_write(file, (unsigned char*)buf, LOAD_HEADER_LEN) != 0;
 
3192
  return my_b_safe_write(file, (uchar*)buf, LOAD_HEADER_LEN) != 0;
2649
3193
}
2650
3194
 
2651
3195
 
2659
3203
    return 1;
2660
3204
  if (num_fields && fields && field_lens)
2661
3205
  {
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))
 
3206
    if (my_b_safe_write(file, (uchar*)field_lens, num_fields) ||
 
3207
        my_b_safe_write(file, (uchar*)fields, field_block_len))
2664
3208
      return 1;
2665
3209
  }
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));
 
3210
  return (my_b_safe_write(file, (uchar*)table_name, table_name_len + 1) ||
 
3211
          my_b_safe_write(file, (uchar*)db, db_len + 1) ||
 
3212
          my_b_safe_write(file, (uchar*)fname, fname_len));
2669
3213
}
2670
3214
 
2671
3215
 
2692
3236
  time(&end_time);
2693
3237
  exec_time = (ulong) (end_time  - thd_arg->start_time);
2694
3238
  /* db can never be a zero pointer in 4.0 */
2695
 
  db_len = (uint32_t) strlen(db);
2696
 
  table_name_len = (uint32_t) strlen(table_name);
 
3239
  db_len = (uint32) strlen(db);
 
3240
  table_name_len = (uint32) strlen(table_name);
2697
3241
  fname_len = (fname) ? (uint) strlen(fname) : 0;
2698
3242
  sql_ex.field_term = (char*) ex->field_term->ptr();
2699
 
  sql_ex.field_term_len = (uint8_t) ex->field_term->length();
 
3243
  sql_ex.field_term_len = (uint8) ex->field_term->length();
2700
3244
  sql_ex.enclosed = (char*) ex->enclosed->ptr();
2701
 
  sql_ex.enclosed_len = (uint8_t) ex->enclosed->length();
 
3245
  sql_ex.enclosed_len = (uint8) ex->enclosed->length();
2702
3246
  sql_ex.line_term = (char*) ex->line_term->ptr();
2703
 
  sql_ex.line_term_len = (uint8_t) ex->line_term->length();
 
3247
  sql_ex.line_term_len = (uint8) ex->line_term->length();
2704
3248
  sql_ex.line_start = (char*) ex->line_start->ptr();
2705
 
  sql_ex.line_start_len = (uint8_t) ex->line_start->length();
 
3249
  sql_ex.line_start_len = (uint8) ex->line_start->length();
2706
3250
  sql_ex.escaped = (char*) ex->escaped->ptr();
2707
 
  sql_ex.escaped_len = (uint8_t) ex->escaped->length();
 
3251
  sql_ex.escaped_len = (uint8) ex->escaped->length();
2708
3252
  sql_ex.opt_flags = 0;
2709
3253
  sql_ex.cached_new_format = -1;
2710
3254
    
2746
3290
  while ((item = li++))
2747
3291
  {
2748
3292
    num_fields++;
2749
 
    unsigned char len = (unsigned char) strlen(item->name);
 
3293
    uchar len = (uchar) strlen(item->name);
2750
3294
    field_block_len += len + 1;
2751
3295
    fields_buf.append(item->name, len + 1);
2752
3296
    field_lens_buf.append((char*)&len, 1);
2753
3297
  }
2754
3298
 
2755
 
  field_lens = (const unsigned char*)field_lens_buf.ptr();
 
3299
  field_lens = (const uchar*)field_lens_buf.ptr();
2756
3300
  fields = fields_buf.ptr();
2757
3301
}
 
3302
#endif /* !MYSQL_CLIENT */
2758
3303
 
2759
3304
 
2760
3305
/**
2762
3307
    The caller must do buf[event_len] = 0 before he starts using the
2763
3308
    constructed event.
2764
3309
*/
2765
 
Load_log_event::Load_log_event(const char *buf, uint32_t event_len,
 
3310
Load_log_event::Load_log_event(const char *buf, uint event_len,
2766
3311
                               const Format_description_log_event *description_event)
2767
3312
  :Log_event(buf, description_event), num_fields(0), fields(0),
2768
3313
   field_lens(0),field_block_len(0),
2792
3337
                                   int body_offset,
2793
3338
                                   const Format_description_log_event *description_event)
2794
3339
{
2795
 
  uint32_t data_len;
 
3340
  uint data_len;
2796
3341
  char* buf_end = (char*)buf + event_len;
2797
3342
  /* this is the beginning of the post-header */
2798
3343
  const char* data_head = buf + description_event->common_header_len;
2809
3354
    Sql_ex.init() on success returns the pointer to the first byte after
2810
3355
    the sql_ex structure, which is the start of field lengths array.
2811
3356
  */
2812
 
  if (!(field_lens= (unsigned char*)sql_ex.init((char*)buf + body_offset,
 
3357
  if (!(field_lens= (uchar*)sql_ex.init((char*)buf + body_offset,
2813
3358
                                        buf_end,
2814
3359
                                        buf[EVENT_TYPE_OFFSET] != LOAD_EVENT)))
2815
3360
    return(1);
2817
3362
  data_len = event_len - body_offset;
2818
3363
  if (num_fields > data_len) // simple sanity check against corruption
2819
3364
    return(1);
2820
 
  for (uint32_t i = 0; i < num_fields; i++)
 
3365
  for (uint i = 0; i < num_fields; i++)
2821
3366
    field_block_len += (uint)field_lens[i] + 1;
2822
3367
 
2823
3368
  fields = (char*)field_lens + num_fields;
2831
3376
}
2832
3377
 
2833
3378
 
 
3379
/*
 
3380
  Load_log_event::print()
 
3381
*/
 
3382
 
 
3383
#ifdef MYSQL_CLIENT
 
3384
void Load_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
3385
{
 
3386
  print(file, print_event_info, 0);
 
3387
}
 
3388
 
 
3389
 
 
3390
void Load_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info,
 
3391
                           bool commented)
 
3392
{
 
3393
  Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
 
3394
 
 
3395
  if (!print_event_info->short_form)
 
3396
  {
 
3397
    print_header(&cache, print_event_info, false);
 
3398
    my_b_printf(&cache, "\tQuery\tthread_id=%ld\texec_time=%ld\n",
 
3399
                thread_id, exec_time);
 
3400
  }
 
3401
 
 
3402
  bool different_db= 1;
 
3403
  if (db)
 
3404
  {
 
3405
    /*
 
3406
      If the database is different from the one of the previous statement, we
 
3407
      need to print the "use" command, and we update the last_db.
 
3408
      But if commented, the "use" is going to be commented so we should not
 
3409
      update the last_db.
 
3410
    */
 
3411
    if ((different_db= memcmp(print_event_info->db, db, db_len + 1)) &&
 
3412
        !commented)
 
3413
      memcpy(print_event_info->db, db, db_len + 1);
 
3414
  }
 
3415
  
 
3416
  if (db && db[0] && different_db)
 
3417
    my_b_printf(&cache, "%suse %s%s\n", 
 
3418
            commented ? "# " : "",
 
3419
            db, print_event_info->delimiter);
 
3420
 
 
3421
  if (flags & LOG_EVENT_THREAD_SPECIFIC_F)
 
3422
    my_b_printf(&cache,"%sSET @@session.pseudo_thread_id=%lu%s\n",
 
3423
            commented ? "# " : "", (ulong)thread_id,
 
3424
            print_event_info->delimiter);
 
3425
  my_b_printf(&cache, "%sLOAD DATA ",
 
3426
              commented ? "# " : "");
 
3427
  if (check_fname_outside_temp_buf())
 
3428
    my_b_printf(&cache, "LOCAL ");
 
3429
  my_b_printf(&cache, "INFILE '%-*s' ", fname_len, fname);
 
3430
 
 
3431
  if (sql_ex.opt_flags & REPLACE_FLAG)
 
3432
    my_b_printf(&cache," REPLACE ");
 
3433
  else if (sql_ex.opt_flags & IGNORE_FLAG)
 
3434
    my_b_printf(&cache," IGNORE ");
 
3435
  
 
3436
  my_b_printf(&cache, "INTO TABLE `%s`", table_name);
 
3437
  my_b_printf(&cache, " FIELDS TERMINATED BY ");
 
3438
  pretty_print_str(&cache, sql_ex.field_term, sql_ex.field_term_len);
 
3439
 
 
3440
  if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
 
3441
    my_b_printf(&cache," OPTIONALLY ");
 
3442
  my_b_printf(&cache, " ENCLOSED BY ");
 
3443
  pretty_print_str(&cache, sql_ex.enclosed, sql_ex.enclosed_len);
 
3444
     
 
3445
  my_b_printf(&cache, " ESCAPED BY ");
 
3446
  pretty_print_str(&cache, sql_ex.escaped, sql_ex.escaped_len);
 
3447
     
 
3448
  my_b_printf(&cache," LINES TERMINATED BY ");
 
3449
  pretty_print_str(&cache, sql_ex.line_term, sql_ex.line_term_len);
 
3450
 
 
3451
 
 
3452
  if (sql_ex.line_start)
 
3453
  {
 
3454
    my_b_printf(&cache," STARTING BY ");
 
3455
    pretty_print_str(&cache, sql_ex.line_start, sql_ex.line_start_len);
 
3456
  }
 
3457
  if ((long) skip_lines > 0)
 
3458
    my_b_printf(&cache, " IGNORE %ld LINES", (long) skip_lines);
 
3459
 
 
3460
  if (num_fields)
 
3461
  {
 
3462
    uint i;
 
3463
    const char* field = fields;
 
3464
    my_b_printf(&cache, " (");
 
3465
    for (i = 0; i < num_fields; i++)
 
3466
    {
 
3467
      if (i)
 
3468
        my_b_printf(&cache, ",");
 
3469
      my_b_printf(&cache, field);
 
3470
          
 
3471
      field += field_lens[i]  + 1;
 
3472
    }
 
3473
    my_b_printf(&cache, ")");
 
3474
  }
 
3475
 
 
3476
  my_b_printf(&cache, "%s\n", print_event_info->delimiter);
 
3477
  return;
 
3478
}
 
3479
#endif /* MYSQL_CLIENT */
 
3480
 
 
3481
#ifndef MYSQL_CLIENT
 
3482
 
2834
3483
/**
2835
3484
  Load_log_event::set_fields()
2836
3485
 
2845
3494
                                List<Item> &field_list,
2846
3495
                                Name_resolution_context *context)
2847
3496
{
2848
 
  uint32_t i;
 
3497
  uint i;
2849
3498
  const char* field = fields;
2850
3499
  for (i= 0; i < num_fields; i++)
2851
3500
  {
2854
3503
    field+= field_lens[i]  + 1;
2855
3504
  }
2856
3505
}
2857
 
 
2858
 
 
 
3506
#endif /* !MYSQL_CLIENT */
 
3507
 
 
3508
 
 
3509
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2859
3510
/**
2860
3511
  Does the data loading job when executing a LOAD DATA on the slave.
2861
3512
 
2941
3592
  if (rpl_filter->db_ok(thd->db))
2942
3593
  {
2943
3594
    thd->set_time((time_t)when);
2944
 
    pthread_mutex_lock(&LOCK_thread_count);
 
3595
    VOID(pthread_mutex_lock(&LOCK_thread_count));
2945
3596
    thd->query_id = next_query_id();
2946
 
    pthread_mutex_unlock(&LOCK_thread_count);
 
3597
    VOID(pthread_mutex_unlock(&LOCK_thread_count));
2947
3598
    /*
2948
3599
      Initing thd->row_count is not necessary in theory as this variable has no
2949
3600
      influence in the case of the slave SQL thread (it is used to generate a
2950
3601
      "data truncated" warning but which is absorbed and never gets to the
2951
3602
      error log); still we init it to avoid a Valgrind message.
2952
3603
    */
2953
 
    drizzle_reset_errors(thd, 0);
 
3604
    mysql_reset_errors(thd, 0);
2954
3605
 
2955
 
    TableList tables;
2956
 
    memset(&tables, 0, sizeof(tables));
 
3606
    TABLE_LIST tables;
 
3607
    bzero((char*) &tables,sizeof(tables));
2957
3608
    tables.db= thd->strmake(thd->db, thd->db_length);
2958
3609
    tables.alias = tables.table_name = (char*) table_name;
2959
3610
    tables.lock_type = TL_WRITE;
3071
3722
      if (thd->cuted_fields)
3072
3723
      {
3073
3724
        /* 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 "
 
3725
        sql_print_warning("Slave: load data infile on table '%s' at "
3075
3726
                          "log position %s in log '%s' produced %ld "
3076
 
                          "warning(s). Default database: '%s'"),
 
3727
                          "warning(s). Default database: '%s'",
3077
3728
                          (char*) table_name,
3078
3729
                          llstr(log_pos,llbuff), RPL_LOG_NAME, 
3079
3730
                          (ulong) thd->cuted_fields,
3097
3748
error:
3098
3749
  thd->net.vio = 0; 
3099
3750
  const char *remember_db= thd->db;
3100
 
  pthread_mutex_lock(&LOCK_thread_count);
 
3751
  VOID(pthread_mutex_lock(&LOCK_thread_count));
3101
3752
  thd->catalog= 0;
3102
3753
  thd->set_db(NULL, 0);                   /* will free the current database */
3103
3754
  thd->query= 0;
3104
3755
  thd->query_length= 0;
3105
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
3756
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
3106
3757
  close_thread_tables(thd);
3107
3758
 
3108
3759
  if (thd->is_slave_error)
3118
3769
    else
3119
3770
    {
3120
3771
      sql_errno=ER_UNKNOWN_ERROR;
3121
 
      err=ER(sql_errno);
 
3772
      err=ER(sql_errno);       
3122
3773
    }
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));
 
3774
    rli->report(ERROR_LEVEL, sql_errno,"\
 
3775
Error '%s' running LOAD DATA INFILE on table '%s'. Default database: '%s'",
 
3776
                    err, (char*)table_name, print_slave_db_safe(remember_db));
3127
3777
    free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
3128
3778
    return 1;
3129
3779
  }
3133
3783
  {
3134
3784
    char buf[256];
3135
3785
    snprintf(buf, sizeof(buf),
3136
 
             _("Running LOAD DATA INFILE on table '%-.64s'."
3137
 
               " Default database: '%-.64s'"),
 
3786
             "Running LOAD DATA INFILE on table '%-.64s'."
 
3787
             " Default database: '%-.64s'",
3138
3788
             (char*)table_name,
3139
3789
             print_slave_db_safe(remember_db));
3140
3790
 
3143
3793
    return 1;
3144
3794
  }
3145
3795
 
3146
 
  return ( use_rli_only_for_errors ? 0 : Log_event::do_apply_event(rli) );
 
3796
  return ( use_rli_only_for_errors ? 0 : Log_event::do_apply_event(rli) ); 
3147
3797
}
 
3798
#endif
3148
3799
 
3149
3800
 
3150
3801
/**************************************************************************
3155
3806
  Rotate_log_event::pack_info()
3156
3807
*/
3157
3808
 
 
3809
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3158
3810
void Rotate_log_event::pack_info(Protocol *protocol)
3159
3811
{
3160
3812
  char buf1[256], buf[22];
3165
3817
  tmp.append(llstr(pos,buf));
3166
3818
  protocol->store(tmp.ptr(), tmp.length(), &my_charset_bin);
3167
3819
}
 
3820
#endif
 
3821
 
 
3822
 
 
3823
/*
 
3824
  Rotate_log_event::print()
 
3825
*/
 
3826
 
 
3827
#ifdef MYSQL_CLIENT
 
3828
void Rotate_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
3829
{
 
3830
  char buf[22];
 
3831
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
3832
                               Write_on_release_cache::FLUSH_F);
 
3833
 
 
3834
  if (print_event_info->short_form)
 
3835
    return;
 
3836
  print_header(&cache, print_event_info, false);
 
3837
  my_b_printf(&cache, "\tRotate to ");
 
3838
  if (new_log_ident)
 
3839
    my_b_write(&cache, (uchar*) new_log_ident, (uint)ident_len);
 
3840
  my_b_printf(&cache, "  pos: %s\n", llstr(pos, buf));
 
3841
}
 
3842
#endif /* MYSQL_CLIENT */
 
3843
 
3168
3844
 
3169
3845
 
3170
3846
/*
3172
3848
*/
3173
3849
 
3174
3850
 
 
3851
#ifndef MYSQL_CLIENT
3175
3852
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)
 
3853
                                   uint ident_len_arg, ulonglong pos_arg,
 
3854
                                   uint flags_arg)
3178
3855
  :Log_event(), new_log_ident(new_log_ident_arg),
3179
3856
   pos(pos_arg),ident_len(ident_len_arg ? ident_len_arg :
3180
3857
                          (uint) strlen(new_log_ident_arg)), flags(flags_arg)
3181
3858
{
 
3859
  char buff[22];
3182
3860
  if (flags & DUP_NAME)
3183
3861
    new_log_ident= my_strndup(new_log_ident_arg, ident_len, MYF(MY_WME));
3184
3862
  return;
3185
3863
}
3186
 
 
3187
 
 
3188
 
Rotate_log_event::Rotate_log_event(const char* buf, uint32_t event_len,
 
3864
#endif
 
3865
 
 
3866
 
 
3867
Rotate_log_event::Rotate_log_event(const char* buf, uint event_len,
3189
3868
                                   const Format_description_log_event* description_event)
3190
3869
  :Log_event(buf, description_event) ,new_log_ident(0), flags(DUP_NAME)
3191
3870
{
3192
3871
  // The caller will ensure that event_len is what we have at EVENT_LEN_OFFSET
3193
 
  uint8_t header_size= description_event->common_header_len;
3194
 
  uint8_t post_header_len= description_event->post_header_len[ROTATE_EVENT-1];
3195
 
  uint32_t ident_offset;
 
3872
  uint8 header_size= description_event->common_header_len;
 
3873
  uint8 post_header_len= description_event->post_header_len[ROTATE_EVENT-1];
 
3874
  uint ident_offset;
3196
3875
  if (event_len < header_size)
3197
3876
    return;
3198
3877
  buf += header_size;
3210
3889
  Rotate_log_event::write()
3211
3890
*/
3212
3891
 
 
3892
#ifndef MYSQL_CLIENT
3213
3893
bool Rotate_log_event::write(IO_CACHE* file)
3214
3894
{
3215
3895
  char buf[ROTATE_HEADER_LEN];
3216
3896
  int8store(buf + R_POS_OFFSET, pos);
3217
3897
  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));
 
3898
          my_b_safe_write(file, (uchar*)buf, ROTATE_HEADER_LEN) ||
 
3899
          my_b_safe_write(file, (uchar*)new_log_ident, (uint) ident_len));
3220
3900
}
3221
 
 
 
3901
#endif
 
3902
 
 
3903
 
 
3904
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3222
3905
 
3223
3906
/*
3224
3907
  Got a rotate log event from the master.
3235
3918
*/
3236
3919
int Rotate_log_event::do_update_pos(Relay_log_info *rli)
3237
3920
{
 
3921
  char buf[32];
 
3922
 
3238
3923
  pthread_mutex_lock(&rli->data_lock);
3239
3924
  rli->event_relay_log_pos= my_b_tell(rli->cur_log);
3240
3925
  /*
3300
3985
  return Log_event::EVENT_SKIP_NOT;             // To keep compiler happy
3301
3986
}
3302
3987
 
 
3988
#endif
 
3989
 
3303
3990
 
3304
3991
/**************************************************************************
3305
3992
        Intvar_log_event methods
3309
3996
  Intvar_log_event::pack_info()
3310
3997
*/
3311
3998
 
 
3999
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3312
4000
void Intvar_log_event::pack_info(Protocol *protocol)
3313
4001
{
3314
4002
  char buf[256], *pos;
3315
4003
  pos= strmake(buf, get_var_type_name(), sizeof(buf)-23);
3316
4004
  *pos++= '=';
3317
 
  pos= int64_t10_to_str(val, pos, -10);
 
4005
  pos= longlong10_to_str(val, pos, -10);
3318
4006
  protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
3319
4007
}
 
4008
#endif
3320
4009
 
3321
4010
 
3322
4011
/*
3351
4040
  Intvar_log_event::write()
3352
4041
*/
3353
4042
 
 
4043
#ifndef MYSQL_CLIENT
3354
4044
bool Intvar_log_event::write(IO_CACHE* file)
3355
4045
{
3356
 
  unsigned char buf[9];
3357
 
  buf[I_TYPE_OFFSET]= (unsigned char) type;
 
4046
  uchar buf[9];
 
4047
  buf[I_TYPE_OFFSET]= (uchar) type;
3358
4048
  int8store(buf + I_VAL_OFFSET, val);
3359
4049
  return (write_header(file, sizeof(buf)) ||
3360
4050
          my_b_safe_write(file, buf, sizeof(buf)));
3361
4051
}
 
4052
#endif
3362
4053
 
3363
4054
 
3364
4055
/*
3365
4056
  Intvar_log_event::print()
3366
4057
*/
3367
4058
 
 
4059
#ifdef MYSQL_CLIENT
 
4060
void Intvar_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
4061
{
 
4062
  char llbuff[22];
 
4063
  const char *msg;
 
4064
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
4065
                               Write_on_release_cache::FLUSH_F);
 
4066
 
 
4067
  if (!print_event_info->short_form)
 
4068
  {
 
4069
    print_header(&cache, print_event_info, false);
 
4070
    my_b_printf(&cache, "\tIntvar\n");
 
4071
  }
 
4072
 
 
4073
  my_b_printf(&cache, "SET ");
 
4074
  switch (type) {
 
4075
  case LAST_INSERT_ID_EVENT:
 
4076
    msg="LAST_INSERT_ID";
 
4077
    break;
 
4078
  case INSERT_ID_EVENT:
 
4079
    msg="INSERT_ID";
 
4080
    break;
 
4081
  case INVALID_INT_EVENT:
 
4082
  default: // cannot happen
 
4083
    msg="INVALID_INT";
 
4084
    break;
 
4085
  }
 
4086
  my_b_printf(&cache, "%s=%s%s\n",
 
4087
              msg, llstr(val,llbuff), print_event_info->delimiter);
 
4088
}
 
4089
#endif
 
4090
 
 
4091
 
3368
4092
/*
3369
4093
  Intvar_log_event::do_apply_event()
3370
4094
*/
3371
4095
 
 
4096
#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
3372
4097
int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
3373
4098
{
3374
4099
  /*
3410
4135
  return continue_group(rli);
3411
4136
}
3412
4137
 
 
4138
#endif
 
4139
 
3413
4140
 
3414
4141
/**************************************************************************
3415
4142
  Rand_log_event methods
3416
4143
**************************************************************************/
3417
4144
 
 
4145
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3418
4146
void Rand_log_event::pack_info(Protocol *protocol)
3419
4147
{
3420
4148
  char buf1[256], *pos;
3421
 
  pos= my_stpcpy(buf1,"rand_seed1=");
 
4149
  pos= strmov(buf1,"rand_seed1=");
3422
4150
  pos= int10_to_str((long) seed1, pos, 10);
3423
 
  pos= my_stpcpy(pos, ",rand_seed2=");
 
4151
  pos= strmov(pos, ",rand_seed2=");
3424
4152
  pos= int10_to_str((long) seed2, pos, 10);
3425
4153
  protocol->store(buf1, (uint) (pos-buf1), &my_charset_bin);
3426
4154
}
 
4155
#endif
3427
4156
 
3428
4157
 
3429
4158
Rand_log_event::Rand_log_event(const char* buf,
3436
4165
}
3437
4166
 
3438
4167
 
 
4168
#ifndef MYSQL_CLIENT
3439
4169
bool Rand_log_event::write(IO_CACHE* file)
3440
4170
{
3441
 
  unsigned char buf[16];
 
4171
  uchar buf[16];
3442
4172
  int8store(buf + RAND_SEED1_OFFSET, seed1);
3443
4173
  int8store(buf + RAND_SEED2_OFFSET, seed2);
3444
4174
  return (write_header(file, sizeof(buf)) ||
3445
4175
          my_b_safe_write(file, buf, sizeof(buf)));
3446
4176
}
3447
 
 
3448
 
 
 
4177
#endif
 
4178
 
 
4179
 
 
4180
#ifdef MYSQL_CLIENT
 
4181
void Rand_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
4182
{
 
4183
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
4184
                               Write_on_release_cache::FLUSH_F);
 
4185
 
 
4186
  char llbuff[22],llbuff2[22];
 
4187
  if (!print_event_info->short_form)
 
4188
  {
 
4189
    print_header(&cache, print_event_info, false);
 
4190
    my_b_printf(&cache, "\tRand\n");
 
4191
  }
 
4192
  my_b_printf(&cache, "SET @@RAND_SEED1=%s, @@RAND_SEED2=%s%s\n",
 
4193
              llstr(seed1, llbuff),llstr(seed2, llbuff2),
 
4194
              print_event_info->delimiter);
 
4195
}
 
4196
#endif /* MYSQL_CLIENT */
 
4197
 
 
4198
 
 
4199
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3449
4200
int Rand_log_event::do_apply_event(Relay_log_info const *rli)
3450
4201
{
3451
4202
  /*
3480
4231
  return continue_group(rli);
3481
4232
}
3482
4233
 
 
4234
#endif /* !MYSQL_CLIENT */
 
4235
 
3483
4236
 
3484
4237
/**************************************************************************
3485
4238
  Xid_log_event methods
3486
4239
**************************************************************************/
3487
4240
 
 
4241
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3488
4242
void Xid_log_event::pack_info(Protocol *protocol)
3489
4243
{
3490
4244
  char buf[128], *pos;
3491
 
  pos= my_stpcpy(buf, "COMMIT /* xid=");
3492
 
  pos= int64_t10_to_str(xid, pos, 10);
3493
 
  pos= my_stpcpy(pos, " */");
 
4245
  pos= strmov(buf, "COMMIT /* xid=");
 
4246
  pos= longlong10_to_str(xid, pos, 10);
 
4247
  pos= strmov(pos, " */");
3494
4248
  protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
3495
4249
}
 
4250
#endif
3496
4251
 
3497
4252
/**
3498
4253
  @note
3499
4254
  It's ok not to use int8store here,
3500
 
  as long as xid_t::set(uint64_t) and
 
4255
  as long as xid_t::set(ulonglong) and
3501
4256
  xid_t::get_my_xid doesn't do it either.
3502
4257
  We don't care about actual values of xids as long as
3503
4258
  identical numbers compare identically
3509
4264
  :Log_event(buf, description_event)
3510
4265
{
3511
4266
  buf+= description_event->common_header_len;
3512
 
  memcpy(&xid, buf, sizeof(xid));
 
4267
  memcpy((char*) &xid, buf, sizeof(xid));
3513
4268
}
3514
4269
 
3515
4270
 
 
4271
#ifndef MYSQL_CLIENT
3516
4272
bool Xid_log_event::write(IO_CACHE* file)
3517
4273
{
3518
4274
  return write_header(file, sizeof(xid)) ||
3519
 
         my_b_safe_write(file, (unsigned char*) &xid, sizeof(xid));
3520
 
}
3521
 
 
3522
 
 
3523
 
int Xid_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
3524
 
{
 
4275
         my_b_safe_write(file, (uchar*) &xid, sizeof(xid));
 
4276
}
 
4277
#endif
 
4278
 
 
4279
 
 
4280
#ifdef MYSQL_CLIENT
 
4281
void Xid_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
4282
{
 
4283
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
4284
                               Write_on_release_cache::FLUSH_F);
 
4285
 
 
4286
  if (!print_event_info->short_form)
 
4287
  {
 
4288
    char buf[64];
 
4289
    longlong10_to_str(xid, buf, 10);
 
4290
 
 
4291
    print_header(&cache, print_event_info, false);
 
4292
    my_b_printf(&cache, "\tXid = %s\n", buf);
 
4293
  }
 
4294
  my_b_printf(&cache, "COMMIT%s\n", print_event_info->delimiter);
 
4295
}
 
4296
#endif /* MYSQL_CLIENT */
 
4297
 
 
4298
 
 
4299
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 
4300
int Xid_log_event::do_apply_event(Relay_log_info const *rli __attribute__((__unused__)))
 
4301
{
 
4302
  /* For a slave Xid_log_event is COMMIT */
 
4303
  general_log_print(thd, COM_QUERY,
 
4304
                    "COMMIT /* implicit, from Xid_log_event */");
3525
4305
  return end_trans(thd, COMMIT);
3526
4306
}
3527
4307
 
3534
4314
  }
3535
4315
  return(Log_event::do_shall_skip(rli));
3536
4316
}
 
4317
#endif /* !MYSQL_CLIENT */
3537
4318
 
3538
4319
 
3539
4320
/**************************************************************************
3540
4321
  User_var_log_event methods
3541
4322
**************************************************************************/
3542
4323
 
 
4324
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3543
4325
void User_var_log_event::pack_info(Protocol* protocol)
3544
4326
{
3545
4327
  char *buf= 0;
3546
 
  uint32_t val_offset= 4 + name_len;
3547
 
  uint32_t event_len= val_offset;
 
4328
  uint val_offset= 4 + name_len;
 
4329
  uint event_len= val_offset;
3548
4330
 
3549
4331
  if (is_null)
3550
4332
  {
3551
4333
    if (!(buf= (char*) my_malloc(val_offset + 5, MYF(MY_WME))))
3552
4334
      return;
3553
 
    my_stpcpy(buf + val_offset, "NULL");
 
4335
    strmov(buf + val_offset, "NULL");
3554
4336
    event_len= val_offset + 4;
3555
4337
  }
3556
4338
  else
3568
4350
    case INT_RESULT:
3569
4351
      if (!(buf= (char*) my_malloc(val_offset + 22, MYF(MY_WME))))
3570
4352
        return;
3571
 
      event_len= int64_t10_to_str(uint8korr(val), buf + val_offset,-10)-buf;
 
4353
      event_len= longlong10_to_str(uint8korr(val), buf + val_offset,-10)-buf;
3572
4354
      break;
3573
4355
    case DECIMAL_RESULT:
3574
4356
    {
3577
4359
        return;
3578
4360
      String str(buf+val_offset, DECIMAL_MAX_STR_LENGTH, &my_charset_bin);
3579
4361
      my_decimal dec;
3580
 
      binary2my_decimal(E_DEC_FATAL_ERROR, (unsigned char*) (val+2), &dec, val[0],
 
4362
      binary2my_decimal(E_DEC_FATAL_ERROR, (uchar*) (val+2), &dec, val[0],
3581
4363
                        val[1]);
3582
4364
      my_decimal2string(E_DEC_FATAL_ERROR, &dec, 0, 0, 0, &str);
3583
4365
      event_len= str.length() + val_offset;
3587
4369
      /* 15 is for 'COLLATE' and other chars */
3588
4370
      buf= (char*) my_malloc(event_len+val_len*2+1+2*MY_CS_NAME_SIZE+15,
3589
4371
                             MYF(MY_WME));
3590
 
      const CHARSET_INFO *cs;
 
4372
      CHARSET_INFO *cs;
3591
4373
      if (!buf)
3592
4374
        return;
3593
4375
      if (!(cs= get_charset(charset_number, MYF(0))))
3594
4376
      {
3595
 
        my_stpcpy(buf+val_offset, "???");
 
4377
        strmov(buf+val_offset, "???");
3596
4378
        event_len+= 3;
3597
4379
      }
3598
4380
      else
3599
4381
      {
3600
 
        char *p= strxmov(buf + val_offset, "_", cs->csname, " ", NULL);
 
4382
        char *p= strxmov(buf + val_offset, "_", cs->csname, " ", NullS);
3601
4383
        p= str_to_hex(p, val, val_len);
3602
 
        p= strxmov(p, " COLLATE ", cs->name, NULL);
 
4384
        p= strxmov(p, " COLLATE ", cs->name, NullS);
3603
4385
        event_len= p-buf;
3604
4386
      }
3605
4387
      break;
3615
4397
  buf[2+name_len]= '`';
3616
4398
  buf[3+name_len]= '=';
3617
4399
  protocol->store(buf, event_len, &my_charset_bin);
3618
 
  free(buf);
 
4400
  my_free(buf, MYF(0));
3619
4401
}
 
4402
#endif /* !MYSQL_CLIENT */
3620
4403
 
3621
4404
 
3622
4405
User_var_log_event::
3648
4431
}
3649
4432
 
3650
4433
 
 
4434
#ifndef MYSQL_CLIENT
3651
4435
bool User_var_log_event::write(IO_CACHE* file)
3652
4436
{
3653
4437
  char buf[UV_NAME_LEN_SIZE];
3654
4438
  char buf1[UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE + 
3655
4439
            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;
 
4440
  uchar buf2[max(8, DECIMAL_MAX_FIELD_SIZE + 2)], *pos= buf2;
 
4441
  uint buf1_length;
3658
4442
  ulong event_length;
3659
4443
 
3660
4444
  int4store(buf, name_len);
3674
4458
      float8store(buf2, *(double*) val);
3675
4459
      break;
3676
4460
    case INT_RESULT:
3677
 
      int8store(buf2, *(int64_t*) val);
 
4461
      int8store(buf2, *(longlong*) val);
3678
4462
      break;
3679
4463
    case DECIMAL_RESULT:
3680
4464
    {
3687
4471
      break;
3688
4472
    }
3689
4473
    case STRING_RESULT:
3690
 
      pos= (unsigned char*) val;
 
4474
      pos= (uchar*) val;
3691
4475
      break;
3692
4476
    case ROW_RESULT:
3693
4477
    default:
3702
4486
  event_length= sizeof(buf)+ name_len + buf1_length + val_len;
3703
4487
 
3704
4488
  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) ||
 
4489
          my_b_safe_write(file, (uchar*) buf, sizeof(buf))   ||
 
4490
          my_b_safe_write(file, (uchar*) name, name_len)     ||
 
4491
          my_b_safe_write(file, (uchar*) buf1, buf1_length) ||
3708
4492
          my_b_safe_write(file, pos, val_len));
3709
4493
}
3710
 
 
 
4494
#endif
 
4495
 
 
4496
 
 
4497
/*
 
4498
  User_var_log_event::print()
 
4499
*/
 
4500
 
 
4501
#ifdef MYSQL_CLIENT
 
4502
void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
4503
{
 
4504
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
4505
                               Write_on_release_cache::FLUSH_F);
 
4506
 
 
4507
  if (!print_event_info->short_form)
 
4508
  {
 
4509
    print_header(&cache, print_event_info, false);
 
4510
    my_b_printf(&cache, "\tUser_var\n");
 
4511
  }
 
4512
 
 
4513
  my_b_printf(&cache, "SET @`");
 
4514
  my_b_write(&cache, (uchar*) name, (uint) (name_len));
 
4515
  my_b_printf(&cache, "`");
 
4516
 
 
4517
  if (is_null)
 
4518
  {
 
4519
    my_b_printf(&cache, ":=NULL%s\n", print_event_info->delimiter);
 
4520
  }
 
4521
  else
 
4522
  {
 
4523
    switch (type) {
 
4524
    case REAL_RESULT:
 
4525
      double real_val;
 
4526
      char real_buf[FMT_G_BUFSIZE(14)];
 
4527
      float8get(real_val, val);
 
4528
      my_sprintf(real_buf, (real_buf, "%.14g", real_val));
 
4529
      my_b_printf(&cache, ":=%s%s\n", real_buf, print_event_info->delimiter);
 
4530
      break;
 
4531
    case INT_RESULT:
 
4532
      char int_buf[22];
 
4533
      longlong10_to_str(uint8korr(val), int_buf, -10);
 
4534
      my_b_printf(&cache, ":=%s%s\n", int_buf, print_event_info->delimiter);
 
4535
      break;
 
4536
    case DECIMAL_RESULT:
 
4537
    {
 
4538
      char str_buf[200];
 
4539
      int str_len= sizeof(str_buf) - 1;
 
4540
      int precision= (int)val[0];
 
4541
      int scale= (int)val[1];
 
4542
      decimal_digit_t dec_buf[10];
 
4543
      decimal_t dec;
 
4544
      dec.len= 10;
 
4545
      dec.buf= dec_buf;
 
4546
 
 
4547
      bin2decimal((uchar*) val+2, &dec, precision, scale);
 
4548
      decimal2string(&dec, str_buf, &str_len, 0, 0, 0);
 
4549
      str_buf[str_len]= 0;
 
4550
      my_b_printf(&cache, ":=%s%s\n", str_buf, print_event_info->delimiter);
 
4551
      break;
 
4552
    }
 
4553
    case STRING_RESULT:
 
4554
    {
 
4555
      /*
 
4556
        Let's express the string in hex. That's the most robust way. If we
 
4557
        print it in character form instead, we need to escape it with
 
4558
        character_set_client which we don't know (we will know it in 5.0, but
 
4559
        in 4.1 we don't know it easily when we are printing
 
4560
        User_var_log_event). Explanation why we would need to bother with
 
4561
        character_set_client (quoting Bar):
 
4562
        > Note, the parser doesn't switch to another unescaping mode after
 
4563
        > it has met a character set introducer.
 
4564
        > For example, if an SJIS client says something like:
 
4565
        > SET @a= _ucs2 \0a\0b'
 
4566
        > the string constant is still unescaped according to SJIS, not
 
4567
        > according to UCS2.
 
4568
      */
 
4569
      char *hex_str;
 
4570
      CHARSET_INFO *cs;
 
4571
 
 
4572
      if (!(hex_str= (char *)my_alloca(2*val_len+1+2))) // 2 hex digits / byte
 
4573
        break; // no error, as we are 'void'
 
4574
      str_to_hex(hex_str, val, val_len);
 
4575
      /*
 
4576
        For proper behaviour when mysqlbinlog|mysql, we need to explicitely
 
4577
        specify the variable's collation. It will however cause problems when
 
4578
        people want to mysqlbinlog|mysql into another server not supporting the
 
4579
        character set. But there's not much to do about this and it's unlikely.
 
4580
      */
 
4581
      if (!(cs= get_charset(charset_number, MYF(0))))
 
4582
        /*
 
4583
          Generate an unusable command (=> syntax error) is probably the best
 
4584
          thing we can do here.
 
4585
        */
 
4586
        my_b_printf(&cache, ":=???%s\n", print_event_info->delimiter);
 
4587
      else
 
4588
        my_b_printf(&cache, ":=_%s %s COLLATE `%s`%s\n",
 
4589
                    cs->csname, hex_str, cs->name,
 
4590
                    print_event_info->delimiter);
 
4591
      my_afree(hex_str);
 
4592
    }
 
4593
      break;
 
4594
    case ROW_RESULT:
 
4595
    default:
 
4596
      assert(1);
 
4597
      return;
 
4598
    }
 
4599
  }
 
4600
}
 
4601
#endif
3711
4602
 
3712
4603
 
3713
4604
/*
3714
4605
  User_var_log_event::do_apply_event()
3715
4606
*/
3716
4607
 
 
4608
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3717
4609
int User_var_log_event::do_apply_event(Relay_log_info const *rli)
3718
4610
{
3719
4611
  Item *it= 0;
3720
 
  const CHARSET_INFO *charset;
 
4612
  CHARSET_INFO *charset;
3721
4613
  if (!(charset= get_charset(charset_number, MYF(MY_WME))))
3722
4614
    return 1;
3723
4615
  LEX_STRING user_var_name;
3724
4616
  user_var_name.str= name;
3725
4617
  user_var_name.length= name_len;
3726
4618
  double real_val;
3727
 
  int64_t int_val;
 
4619
  longlong int_val;
3728
4620
 
3729
4621
  /*
3730
4622
    We are now in a statement until the associated query log event has
3746
4638
      val_len= 8;
3747
4639
      break;
3748
4640
    case INT_RESULT:
3749
 
      int_val= (int64_t) uint8korr(val);
 
4641
      int_val= (longlong) uint8korr(val);
3750
4642
      it= new Item_int(int_val);
3751
4643
      val= (char*) &int_val;            // Pointer to value in native format
3752
4644
      val_len= 8;
3753
4645
      break;
3754
4646
    case DECIMAL_RESULT:
3755
4647
    {
3756
 
      Item_decimal *dec= new Item_decimal((unsigned char*) val+2, val[0], val[1]);
 
4648
      Item_decimal *dec= new Item_decimal((uchar*) val+2, val[0], val[1]);
3757
4649
      it= dec;
3758
4650
      val= (char *)dec->val_decimal(NULL);
3759
4651
      val_len= sizeof(my_decimal);
3804
4696
  */
3805
4697
  return continue_group(rli);
3806
4698
}
 
4699
#endif /* !MYSQL_CLIENT */
3807
4700
 
3808
4701
 
3809
4702
/**************************************************************************
3810
4703
  Slave_log_event methods
3811
4704
**************************************************************************/
3812
4705
 
 
4706
#ifdef HAVE_REPLICATION
 
4707
#ifdef MYSQL_CLIENT
 
4708
void Unknown_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info)
 
4709
{
 
4710
  Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
 
4711
 
 
4712
  if (print_event_info->short_form)
 
4713
    return;
 
4714
  print_header(&cache, print_event_info, false);
 
4715
  my_b_printf(&cache, "\n# %s", "Unknown event\n");
 
4716
}
 
4717
#endif  
 
4718
 
 
4719
#ifndef MYSQL_CLIENT
3813
4720
void Slave_log_event::pack_info(Protocol *protocol)
3814
4721
{
3815
4722
  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=");
 
4723
  pos= strmov(buf, "host=");
 
4724
  pos= strnmov(pos, master_host, HOSTNAME_LENGTH);
 
4725
  pos= strmov(pos, ",port=");
3819
4726
  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=");
3823
 
  pos= int64_t10_to_str(master_pos, pos, 10);
 
4727
  pos= strmov(pos, ",log=");
 
4728
  pos= strmov(pos, master_log);
 
4729
  pos= strmov(pos, ",pos=");
 
4730
  pos= longlong10_to_str(master_pos, pos, 10);
3824
4731
  protocol->store(buf, pos-buf, &my_charset_bin);
3825
4732
}
3826
 
 
3827
 
 
 
4733
#endif /* !MYSQL_CLIENT */
 
4734
 
 
4735
 
 
4736
#ifndef MYSQL_CLIENT
3828
4737
/**
3829
4738
  @todo
3830
4739
  re-write this better without holding both locks at the same time
3854
4763
    master_pos = rli->group_master_log_pos;
3855
4764
  }
3856
4765
  else
3857
 
    sql_print_error(_("Out of memory while recording slave event"));
 
4766
    sql_print_error("Out of memory while recording slave event");
3858
4767
  pthread_mutex_unlock(&rli->data_lock);
3859
4768
  pthread_mutex_unlock(&mi->data_lock);
3860
4769
  return;
3861
4770
}
 
4771
#endif /* !MYSQL_CLIENT */
3862
4772
 
3863
4773
 
3864
4774
Slave_log_event::~Slave_log_event()
3865
4775
{
3866
 
  free(mem_pool);
3867
 
}
 
4776
  my_free(mem_pool, MYF(MY_ALLOW_ZERO_PTR));
 
4777
}
 
4778
 
 
4779
 
 
4780
#ifdef MYSQL_CLIENT
 
4781
void Slave_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
4782
{
 
4783
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
4784
 
 
4785
  char llbuff[22];
 
4786
  if (print_event_info->short_form)
 
4787
    return;
 
4788
  print_header(&cache, print_event_info, false);
 
4789
  my_b_printf(&cache, "\n\
 
4790
Slave: master_host: '%s'  master_port: %d  master_log: '%s'  master_pos: %s\n",
 
4791
          master_host, master_port, master_log, llstr(master_pos, llbuff));
 
4792
}
 
4793
#endif /* MYSQL_CLIENT */
3868
4794
 
3869
4795
 
3870
4796
int Slave_log_event::get_data_size()
3873
4799
}
3874
4800
 
3875
4801
 
 
4802
#ifndef MYSQL_CLIENT
3876
4803
bool Slave_log_event::write(IO_CACHE* file)
3877
4804
{
3878
4805
  ulong event_length= get_data_size();
3881
4808
  // log and host are already there
3882
4809
 
3883
4810
  return (write_header(file, event_length) ||
3884
 
          my_b_safe_write(file, (unsigned char*) mem_pool, event_length));
 
4811
          my_b_safe_write(file, (uchar*) mem_pool, event_length));
3885
4812
}
 
4813
#endif
3886
4814
 
3887
4815
 
3888
4816
void Slave_log_event::init_from_mem_pool(int data_size)
3903
4831
 
3904
4832
 
3905
4833
/** 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)
 
4834
Slave_log_event::Slave_log_event(const char* buf, uint event_len)
3907
4835
  :Log_event(buf,0) /*unused event*/ ,mem_pool(0),master_host(0)
3908
4836
{
3909
4837
  if (event_len < LOG_EVENT_HEADER_LEN)
3917
4845
}
3918
4846
 
3919
4847
 
3920
 
int Slave_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
 
4848
#ifndef MYSQL_CLIENT
 
4849
int Slave_log_event::do_apply_event(Relay_log_info const *rli __attribute__((__unused__)))
3921
4850
{
3922
4851
  if (mysql_bin_log.is_open())
3923
4852
    mysql_bin_log.write(this);
3924
4853
  return 0;
3925
4854
}
 
4855
#endif /* !MYSQL_CLIENT */
3926
4856
 
3927
4857
 
3928
4858
/**************************************************************************
3930
4860
**************************************************************************/
3931
4861
 
3932
4862
/*
 
4863
  Stop_log_event::print()
 
4864
*/
 
4865
 
 
4866
#ifdef MYSQL_CLIENT
 
4867
void Stop_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
4868
{
 
4869
  Write_on_release_cache cache(&print_event_info->head_cache, file,
 
4870
                               Write_on_release_cache::FLUSH_F);
 
4871
 
 
4872
  if (print_event_info->short_form)
 
4873
    return;
 
4874
 
 
4875
  print_header(&cache, print_event_info, false);
 
4876
  my_b_printf(&cache, "\tStop\n");
 
4877
}
 
4878
#endif /* MYSQL_CLIENT */
 
4879
 
 
4880
 
 
4881
#ifndef MYSQL_CLIENT
 
4882
/*
3933
4883
  The master stopped.  We used to clean up all temporary tables but
3934
4884
  this is useless as, as the master has shut down properly, it has
3935
 
  written all DROP TEMPORARY Table (prepared statements' deletion is
 
4885
  written all DROP TEMPORARY TABLE (prepared statements' deletion is
3936
4886
  TODO only when we binlog prep stmts).  We used to clean up
3937
4887
  slave_load_tmpdir, but this is useless as it has been cleared at the
3938
4888
  end of LOAD DATA INFILE.  So we have nothing to do here.  The place
3959
4909
  return 0;
3960
4910
}
3961
4911
 
 
4912
#endif /* !MYSQL_CLIENT */
 
4913
#endif /* HAVE_REPLICATION */
 
4914
 
3962
4915
 
3963
4916
/**************************************************************************
3964
4917
        Create_file_log_event methods
3968
4921
  Create_file_log_event ctor
3969
4922
*/
3970
4923
 
 
4924
#ifndef MYSQL_CLIENT
3971
4925
Create_file_log_event::
3972
4926
Create_file_log_event(THD* thd_arg, sql_exchange* ex,
3973
4927
                      const char* db_arg, const char* table_name_arg,
3974
4928
                      List<Item>& fields_arg, enum enum_duplicates handle_dup,
3975
4929
                      bool ignore,
3976
 
                      unsigned char* block_arg, uint32_t block_len_arg, bool using_trans)
 
4930
                      uchar* block_arg, uint block_len_arg, bool using_trans)
3977
4931
  :Load_log_event(thd_arg,ex,db_arg,table_name_arg,fields_arg,handle_dup, ignore,
3978
4932
                  using_trans),
3979
4933
   fake_base(0), block(block_arg), event_buf(0), block_len(block_len_arg),
3993
4947
  bool res;
3994
4948
  if ((res= Load_log_event::write_data_body(file)) || fake_base)
3995
4949
    return res;
3996
 
  return (my_b_safe_write(file, (unsigned char*) "", 1) ||
3997
 
          my_b_safe_write(file, (unsigned char*) block, block_len));
 
4950
  return (my_b_safe_write(file, (uchar*) "", 1) ||
 
4951
          my_b_safe_write(file, (uchar*) block, block_len));
3998
4952
}
3999
4953
 
4000
4954
 
4005
4959
bool Create_file_log_event::write_data_header(IO_CACHE* file)
4006
4960
{
4007
4961
  bool res;
4008
 
  unsigned char buf[CREATE_FILE_HEADER_LEN];
 
4962
  uchar buf[CREATE_FILE_HEADER_LEN];
4009
4963
  if ((res= Load_log_event::write_data_header(file)) || fake_base)
4010
4964
    return res;
4011
4965
  int4store(buf + CF_FILE_ID_OFFSET, file_id);
4026
4980
  return res;
4027
4981
}
4028
4982
 
 
4983
#endif /* !MYSQL_CLIENT */
 
4984
 
4029
4985
/*
4030
4986
  Create_file_log_event ctor
4031
4987
*/
4032
4988
 
4033
 
Create_file_log_event::Create_file_log_event(const char* buf, uint32_t len,
 
4989
Create_file_log_event::Create_file_log_event(const char* buf, uint len,
4034
4990
                                             const Format_description_log_event* description_event)
4035
4991
  :Load_log_event(buf,0,description_event),fake_base(0),block(0),inited_from_old(0)
4036
4992
{
4037
 
  uint32_t block_offset;
4038
 
  uint32_t header_len= description_event->common_header_len;
4039
 
  uint8_t load_header_len= description_event->post_header_len[LOAD_EVENT-1];
4040
 
  uint8_t create_file_header_len= description_event->post_header_len[CREATE_FILE_EVENT-1];
 
4993
  uint block_offset;
 
4994
  uint header_len= description_event->common_header_len;
 
4995
  uint8 load_header_len= description_event->post_header_len[LOAD_EVENT-1];
 
4996
  uint8 create_file_header_len= description_event->post_header_len[CREATE_FILE_EVENT-1];
4041
4997
  if (!(event_buf= (char*) my_memdup(buf, len, MYF(MY_WME))) ||
4042
4998
      copy_log_event(event_buf,len,
4043
4999
                     ((buf[EVENT_TYPE_OFFSET] == LOAD_EVENT) ?
4068
5024
                   create_file_header_len + 1);
4069
5025
    if (len < block_offset)
4070
5026
      return;
4071
 
    block = (unsigned char*)buf + block_offset;
 
5027
    block = (uchar*)buf + block_offset;
4072
5028
    block_len = len - block_offset;
4073
5029
  }
4074
5030
  else
4081
5037
 
4082
5038
 
4083
5039
/*
 
5040
  Create_file_log_event::print()
 
5041
*/
 
5042
 
 
5043
#ifdef MYSQL_CLIENT
 
5044
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info,
 
5045
                                  bool enable_local)
 
5046
{
 
5047
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
5048
 
 
5049
  if (print_event_info->short_form)
 
5050
  {
 
5051
    if (enable_local && check_fname_outside_temp_buf())
 
5052
      Load_log_event::print(file, print_event_info);
 
5053
    return;
 
5054
  }
 
5055
 
 
5056
  if (enable_local)
 
5057
  {
 
5058
    Load_log_event::print(file, print_event_info,
 
5059
                          !check_fname_outside_temp_buf());
 
5060
    /* 
 
5061
       That one is for "file_id: etc" below: in mysqlbinlog we want the #, in
 
5062
       SHOW BINLOG EVENTS we don't.
 
5063
    */
 
5064
    my_b_printf(&cache, "#"); 
 
5065
  }
 
5066
 
 
5067
  my_b_printf(&cache, " file_id: %d  block_len: %d\n", file_id, block_len);
 
5068
}
 
5069
 
 
5070
 
 
5071
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
 
5072
{
 
5073
  print(file, print_event_info, 0);
 
5074
}
 
5075
#endif /* MYSQL_CLIENT */
 
5076
 
 
5077
 
 
5078
/*
4084
5079
  Create_file_log_event::pack_info()
4085
5080
*/
4086
5081
 
 
5082
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4087
5083
void Create_file_log_event::pack_info(Protocol *protocol)
4088
5084
{
4089
5085
  char buf[NAME_LEN*2 + 30 + 21*2], *pos;
4090
 
  pos= my_stpcpy(buf, "db=");
 
5086
  pos= strmov(buf, "db=");
4091
5087
  memcpy(pos, db, db_len);
4092
 
  pos= my_stpcpy(pos + db_len, ";table=");
 
5088
  pos= strmov(pos + db_len, ";table=");
4093
5089
  memcpy(pos, table_name, table_name_len);
4094
 
  pos= my_stpcpy(pos + table_name_len, ";file_id=");
 
5090
  pos= strmov(pos + table_name_len, ";file_id=");
4095
5091
  pos= int10_to_str((long) file_id, pos, 10);
4096
 
  pos= my_stpcpy(pos, ";block_len=");
 
5092
  pos= strmov(pos, ";block_len=");
4097
5093
  pos= int10_to_str((long) block_len, pos, 10);
4098
5094
  protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
4099
5095
}
 
5096
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4100
5097
 
4101
5098
 
4102
5099
/*
4103
5100
  Create_file_log_event::do_apply_event()
4104
5101
*/
4105
5102
 
 
5103
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4106
5104
int Create_file_log_event::do_apply_event(Relay_log_info const *rli)
4107
5105
{
4108
5106
  char proc_info[17+FN_REFLEN+10], *fname_buf;
4111
5109
  IO_CACHE file;
4112
5110
  int error = 1;
4113
5111
 
4114
 
  memset(&file, 0, sizeof(file));
4115
 
  fname_buf= my_stpcpy(proc_info, "Making temp file ");
 
5112
  bzero((char*)&file, sizeof(file));
 
5113
  fname_buf= strmov(proc_info, "Making temp file ");
4116
5114
  ext= slave_load_file_stem(fname_buf, file_id, server_id, ".info");
4117
5115
  thd_proc_info(thd, proc_info);
4118
5116
  my_delete(fname_buf, MYF(0)); // old copy may exist already
4123
5121
                    MYF(MY_WME|MY_NABP)))
4124
5122
  {
4125
5123
    rli->report(ERROR_LEVEL, my_errno,
4126
 
                _("Error in Create_file event: could not open file '%s'"),
 
5124
                "Error in Create_file event: could not open file '%s'",
4127
5125
                fname_buf);
4128
5126
    goto err;
4129
5127
  }
4130
5128
  
4131
5129
  // a trick to avoid allocating another buffer
4132
5130
  fname= fname_buf;
4133
 
  fname_len= (uint) (my_stpcpy(ext, ".data") - fname);
 
5131
  fname_len= (uint) (strmov(ext, ".data") - fname);
4134
5132
  if (write_base(&file))
4135
5133
  {
4136
 
    my_stpcpy(ext, ".info"); // to have it right in the error message
 
5134
    strmov(ext, ".info"); // to have it right in the error message
4137
5135
    rli->report(ERROR_LEVEL, my_errno,
4138
 
                _("Error in Create_file event: could not write to file '%s'"),
 
5136
                "Error in Create_file event: could not write to file '%s'",
4139
5137
                fname_buf);
4140
5138
    goto err;
4141
5139
  }
4142
5140
  end_io_cache(&file);
4143
5141
  my_close(fd, MYF(0));
4144
 
 
 
5142
  
4145
5143
  // fname_buf now already has .data, not .info, because we did our trick
4146
5144
  my_delete(fname_buf, MYF(0)); // old copy may exist already
4147
5145
  if ((fd= my_create(fname_buf, CREATE_MODE,
4148
 
                     O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4149
 
                     MYF(MY_WME))) < 0)
 
5146
                     O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
 
5147
                     MYF(MY_WME))) < 0)
4150
5148
  {
4151
5149
    rli->report(ERROR_LEVEL, my_errno,
4152
 
                _("Error in Create_file event: could not open file '%s'"),
 
5150
                "Error in Create_file event: could not open file '%s'",
4153
5151
                fname_buf);
4154
5152
    goto err;
4155
5153
  }
4156
 
  if (my_write(fd, (unsigned char*) block, block_len, MYF(MY_WME+MY_NABP)))
 
5154
  if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4157
5155
  {
4158
5156
    rli->report(ERROR_LEVEL, my_errno,
4159
 
                _("Error in Create_file event: write to '%s' failed"),
 
5157
                "Error in Create_file event: write to '%s' failed",
4160
5158
                fname_buf);
4161
5159
    goto err;
4162
5160
  }
4170
5168
  thd_proc_info(thd, 0);
4171
5169
  return error == 0;
4172
5170
}
 
5171
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4173
5172
 
4174
5173
 
4175
5174
/**************************************************************************
4180
5179
  Append_block_log_event ctor
4181
5180
*/
4182
5181
 
 
5182
#ifndef MYSQL_CLIENT  
4183
5183
Append_block_log_event::Append_block_log_event(THD *thd_arg,
4184
5184
                                               const char *db_arg,
4185
 
                                               unsigned char *block_arg,
4186
 
                                               uint32_t block_len_arg,
 
5185
                                               uchar *block_arg,
 
5186
                                               uint block_len_arg,
4187
5187
                                               bool using_trans)
4188
5188
  :Log_event(thd_arg,0, using_trans), block(block_arg),
4189
5189
   block_len(block_len_arg), file_id(thd_arg->file_id), db(db_arg)
4190
5190
{
4191
5191
}
 
5192
#endif
4192
5193
 
4193
5194
 
4194
5195
/*
4195
5196
  Append_block_log_event ctor
4196
5197
*/
4197
5198
 
4198
 
Append_block_log_event::Append_block_log_event(const char* buf, uint32_t len,
 
5199
Append_block_log_event::Append_block_log_event(const char* buf, uint len,
4199
5200
                                               const Format_description_log_event* description_event)
4200
5201
  :Log_event(buf, description_event),block(0)
4201
5202
{
4202
 
  uint8_t common_header_len= description_event->common_header_len; 
4203
 
  uint8_t append_block_header_len=
 
5203
  uint8 common_header_len= description_event->common_header_len; 
 
5204
  uint8 append_block_header_len=
4204
5205
    description_event->post_header_len[APPEND_BLOCK_EVENT-1];
4205
 
  uint32_t total_header_len= common_header_len+append_block_header_len;
 
5206
  uint total_header_len= common_header_len+append_block_header_len;
4206
5207
  if (len < total_header_len)
4207
5208
    return;
4208
5209
  file_id= uint4korr(buf + common_header_len + AB_FILE_ID_OFFSET);
4209
 
  block= (unsigned char*)buf + total_header_len;
 
5210
  block= (uchar*)buf + total_header_len;
4210
5211
  block_len= len - total_header_len;
4211
5212
  return;
4212
5213
}
4216
5217
  Append_block_log_event::write()
4217
5218
*/
4218
5219
 
 
5220
#ifndef MYSQL_CLIENT
4219
5221
bool Append_block_log_event::write(IO_CACHE* file)
4220
5222
{
4221
 
  unsigned char buf[APPEND_BLOCK_HEADER_LEN];
 
5223
  uchar buf[APPEND_BLOCK_HEADER_LEN];
4222
5224
  int4store(buf + AB_FILE_ID_OFFSET, file_id);
4223
5225
  return (write_header(file, APPEND_BLOCK_HEADER_LEN + block_len) ||
4224
5226
          my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) ||
4225
 
          my_b_safe_write(file, (unsigned char*) block, block_len));
4226
 
}
 
5227
          my_b_safe_write(file, (uchar*) block, block_len));
 
5228
}
 
5229
#endif
 
5230
 
 
5231
 
 
5232
/*
 
5233
  Append_block_log_event::print()
 
5234
*/
 
5235
 
 
5236
#ifdef MYSQL_CLIENT  
 
5237
void Append_block_log_event::print(FILE* file,
 
5238
                                   PRINT_EVENT_INFO* print_event_info)
 
5239
{
 
5240
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
5241
 
 
5242
  if (print_event_info->short_form)
 
5243
    return;
 
5244
  print_header(&cache, print_event_info, false);
 
5245
  my_b_printf(&cache, "\n#%s: file_id: %d  block_len: %d\n",
 
5246
              get_type_str(), file_id, block_len);
 
5247
}
 
5248
#endif /* MYSQL_CLIENT */
4227
5249
 
4228
5250
 
4229
5251
/*
4230
5252
  Append_block_log_event::pack_info()
4231
5253
*/
4232
5254
 
 
5255
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4233
5256
void Append_block_log_event::pack_info(Protocol *protocol)
4234
5257
{
4235
5258
  char buf[256];
4236
 
  uint32_t length;
4237
 
  length= (uint) sprintf(buf, ";file_id=%u;block_len=%u", file_id,
4238
 
                             block_len);
 
5259
  uint length;
 
5260
  length= (uint) my_sprintf(buf,
 
5261
                            (buf, ";file_id=%u;block_len=%u", file_id,
 
5262
                             block_len));
4239
5263
  protocol->store(buf, length, &my_charset_bin);
4240
5264
}
4241
5265
 
4259
5283
  int fd;
4260
5284
  int error = 1;
4261
5285
 
4262
 
  fname= my_stpcpy(proc_info, "Making temp file ");
 
5286
  fname= strmov(proc_info, "Making temp file ");
4263
5287
  slave_load_file_stem(fname, file_id, server_id, ".data");
4264
5288
  thd_proc_info(thd, proc_info);
4265
5289
  if (get_create_or_append())
4270
5294
                       MYF(MY_WME))) < 0)
4271
5295
    {
4272
5296
      rli->report(ERROR_LEVEL, my_errno,
4273
 
                  _("Error in %s event: could not create file '%s'"),
 
5297
                  "Error in %s event: could not create file '%s'",
4274
5298
                  get_type_str(), fname);
4275
5299
      goto err;
4276
5300
    }
4279
5303
                         MYF(MY_WME))) < 0)
4280
5304
  {
4281
5305
    rli->report(ERROR_LEVEL, my_errno,
4282
 
                _("Error in %s event: could not open file '%s'"),
 
5306
                "Error in %s event: could not open file '%s'",
4283
5307
                get_type_str(), fname);
4284
5308
    goto err;
4285
5309
  }
4286
 
  if (my_write(fd, (unsigned char*) block, block_len, MYF(MY_WME+MY_NABP)))
 
5310
  if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4287
5311
  {
4288
5312
    rli->report(ERROR_LEVEL, my_errno,
4289
 
                _("Error in %s event: write to '%s' failed"),
 
5313
                "Error in %s event: write to '%s' failed",
4290
5314
                get_type_str(), fname);
4291
5315
    goto err;
4292
5316
  }
4298
5322
  thd_proc_info(thd, 0);
4299
5323
  return(error);
4300
5324
}
 
5325
#endif
4301
5326
 
4302
5327
 
4303
5328
/**************************************************************************
4308
5333
  Delete_file_log_event ctor
4309
5334
*/
4310
5335
 
 
5336
#ifndef MYSQL_CLIENT
4311
5337
Delete_file_log_event::Delete_file_log_event(THD *thd_arg, const char* db_arg,
4312
5338
                                             bool using_trans)
4313
5339
  :Log_event(thd_arg, 0, using_trans), file_id(thd_arg->file_id), db(db_arg)
4314
5340
{
4315
5341
}
 
5342
#endif
4316
5343
 
4317
5344
/*
4318
5345
  Delete_file_log_event ctor
4319
5346
*/
4320
5347
 
4321
 
Delete_file_log_event::Delete_file_log_event(const char* buf, uint32_t len,
 
5348
Delete_file_log_event::Delete_file_log_event(const char* buf, uint len,
4322
5349
                                             const Format_description_log_event* description_event)
4323
5350
  :Log_event(buf, description_event),file_id(0)
4324
5351
{
4325
 
  uint8_t common_header_len= description_event->common_header_len;
4326
 
  uint8_t delete_file_header_len= description_event->post_header_len[DELETE_FILE_EVENT-1];
 
5352
  uint8 common_header_len= description_event->common_header_len;
 
5353
  uint8 delete_file_header_len= description_event->post_header_len[DELETE_FILE_EVENT-1];
4327
5354
  if (len < (uint)(common_header_len + delete_file_header_len))
4328
5355
    return;
4329
5356
  file_id= uint4korr(buf + common_header_len + DF_FILE_ID_OFFSET);
4334
5361
  Delete_file_log_event::write()
4335
5362
*/
4336
5363
 
 
5364
#ifndef MYSQL_CLIENT
4337
5365
bool Delete_file_log_event::write(IO_CACHE* file)
4338
5366
{
4339
 
 unsigned char buf[DELETE_FILE_HEADER_LEN];
 
5367
 uchar buf[DELETE_FILE_HEADER_LEN];
4340
5368
 int4store(buf + DF_FILE_ID_OFFSET, file_id);
4341
5369
 return (write_header(file, sizeof(buf)) ||
4342
5370
         my_b_safe_write(file, buf, sizeof(buf)));
4343
5371
}
4344
 
 
 
5372
#endif
 
5373
 
 
5374
 
 
5375
/*
 
5376
  Delete_file_log_event::print()
 
5377
*/
 
5378
 
 
5379
#ifdef MYSQL_CLIENT  
 
5380
void Delete_file_log_event::print(FILE* file,
 
5381
                                  PRINT_EVENT_INFO* print_event_info)
 
5382
{
 
5383
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
5384
 
 
5385
  if (print_event_info->short_form)
 
5386
    return;
 
5387
  print_header(&cache, print_event_info, false);
 
5388
  my_b_printf(&cache, "\n#Delete_file: file_id=%u\n", file_id);
 
5389
}
 
5390
#endif /* MYSQL_CLIENT */
4345
5391
 
4346
5392
/*
4347
5393
  Delete_file_log_event::pack_info()
4348
5394
*/
4349
5395
 
 
5396
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4350
5397
void Delete_file_log_event::pack_info(Protocol *protocol)
4351
5398
{
4352
5399
  char buf[64];
4353
 
  uint32_t length;
4354
 
  length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4355
 
  protocol->store(buf, (int32_t) length, &my_charset_bin);
 
5400
  uint length;
 
5401
  length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
 
5402
  protocol->store(buf, (int32) length, &my_charset_bin);
4356
5403
}
 
5404
#endif
4357
5405
 
4358
5406
/*
4359
5407
  Delete_file_log_event::do_apply_event()
4360
5408
*/
4361
5409
 
4362
 
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
 
5410
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 
5411
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((__unused__)))
4363
5412
{
4364
5413
  char fname[FN_REFLEN+10];
4365
5414
  char *ext= slave_load_file_stem(fname, file_id, server_id, ".data");
4366
5415
  (void) my_delete(fname, MYF(MY_WME));
4367
 
  my_stpcpy(ext, ".info");
 
5416
  strmov(ext, ".info");
4368
5417
  (void) my_delete(fname, MYF(MY_WME));
4369
5418
  return 0;
4370
5419
}
 
5420
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4371
5421
 
4372
5422
 
4373
5423
/**************************************************************************
4378
5428
  Execute_load_log_event ctor
4379
5429
*/
4380
5430
 
 
5431
#ifndef MYSQL_CLIENT  
4381
5432
Execute_load_log_event::Execute_load_log_event(THD *thd_arg,
4382
5433
                                               const char* db_arg,
4383
5434
                                               bool using_trans)
4384
5435
  :Log_event(thd_arg, 0, using_trans), file_id(thd_arg->file_id), db(db_arg)
4385
5436
{
4386
5437
}
 
5438
#endif
4387
5439
  
4388
5440
 
4389
5441
/*
4390
5442
  Execute_load_log_event ctor
4391
5443
*/
4392
5444
 
4393
 
Execute_load_log_event::Execute_load_log_event(const char* buf, uint32_t len,
 
5445
Execute_load_log_event::Execute_load_log_event(const char* buf, uint len,
4394
5446
                                               const Format_description_log_event* description_event)
4395
5447
  :Log_event(buf, description_event), file_id(0)
4396
5448
{
4397
 
  uint8_t common_header_len= description_event->common_header_len;
4398
 
  uint8_t exec_load_header_len= description_event->post_header_len[EXEC_LOAD_EVENT-1];
 
5449
  uint8 common_header_len= description_event->common_header_len;
 
5450
  uint8 exec_load_header_len= description_event->post_header_len[EXEC_LOAD_EVENT-1];
4399
5451
  if (len < (uint)(common_header_len+exec_load_header_len))
4400
5452
    return;
4401
5453
  file_id= uint4korr(buf + common_header_len + EL_FILE_ID_OFFSET);
4406
5458
  Execute_load_log_event::write()
4407
5459
*/
4408
5460
 
 
5461
#ifndef MYSQL_CLIENT
4409
5462
bool Execute_load_log_event::write(IO_CACHE* file)
4410
5463
{
4411
 
  unsigned char buf[EXEC_LOAD_HEADER_LEN];
 
5464
  uchar buf[EXEC_LOAD_HEADER_LEN];
4412
5465
  int4store(buf + EL_FILE_ID_OFFSET, file_id);
4413
5466
  return (write_header(file, sizeof(buf)) || 
4414
5467
          my_b_safe_write(file, buf, sizeof(buf)));
4415
5468
}
4416
 
 
 
5469
#endif
 
5470
 
 
5471
 
 
5472
/*
 
5473
  Execute_load_log_event::print()
 
5474
*/
 
5475
 
 
5476
#ifdef MYSQL_CLIENT  
 
5477
void Execute_load_log_event::print(FILE* file,
 
5478
                                   PRINT_EVENT_INFO* print_event_info)
 
5479
{
 
5480
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
5481
 
 
5482
  if (print_event_info->short_form)
 
5483
    return;
 
5484
  print_header(&cache, print_event_info, false);
 
5485
  my_b_printf(&cache, "\n#Exec_load: file_id=%d\n",
 
5486
              file_id);
 
5487
}
 
5488
#endif
4417
5489
 
4418
5490
/*
4419
5491
  Execute_load_log_event::pack_info()
4420
5492
*/
4421
5493
 
 
5494
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4422
5495
void Execute_load_log_event::pack_info(Protocol *protocol)
4423
5496
{
4424
5497
  char buf[64];
4425
 
  uint32_t length;
4426
 
  length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4427
 
  protocol->store(buf, (int32_t) length, &my_charset_bin);
 
5498
  uint length;
 
5499
  length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
 
5500
  protocol->store(buf, (int32) length, &my_charset_bin);
4428
5501
}
4429
5502
 
4430
5503
 
4448
5521
                    MYF(MY_WME|MY_NABP)))
4449
5522
  {
4450
5523
    rli->report(ERROR_LEVEL, my_errno,
4451
 
                _("Error in Exec_load event: could not open file '%s'"),
 
5524
                "Error in Exec_load event: could not open file '%s'",
4452
5525
                fname);
4453
5526
    goto err;
4454
5527
  }
4457
5530
                                                         rli->relay_log.description_event_for_exec)) ||
4458
5531
      lev->get_type_code() != NEW_LOAD_EVENT)
4459
5532
  {
4460
 
    rli->report(ERROR_LEVEL, 0,
4461
 
                _("Error in Exec_load event: "
4462
 
                  "file '%s' appears corrupted"),
4463
 
                fname);
 
5533
    rli->report(ERROR_LEVEL, 0, "Error in Exec_load event: "
 
5534
                    "file '%s' appears corrupted", fname);
4464
5535
    goto err;
4465
5536
  }
4466
5537
 
4488
5559
    if (tmp)
4489
5560
    {
4490
5561
      rli->report(ERROR_LEVEL, rli->last_error().number,
4491
 
                  _("%s. Failed executing load from '%s'"),
4492
 
                  tmp, fname);
4493
 
      free(tmp);
 
5562
                  "%s. Failed executing load from '%s'", tmp, fname);
 
5563
      my_free(tmp,MYF(0));
4494
5564
    }
4495
5565
    goto err;
4496
5566
  }
4519
5589
  return error;
4520
5590
}
4521
5591
 
 
5592
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
 
5593
 
4522
5594
 
4523
5595
/**************************************************************************
4524
5596
        Begin_load_query_log_event methods
4525
5597
**************************************************************************/
4526
5598
 
 
5599
#ifndef MYSQL_CLIENT
4527
5600
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)
 
5601
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, uchar* block_arg,
 
5602
                           uint block_len_arg, bool using_trans)
4530
5603
  :Append_block_log_event(thd_arg, db_arg, block_arg, block_len_arg,
4531
5604
                          using_trans)
4532
5605
{
4533
5606
   file_id= thd_arg->file_id= mysql_bin_log.next_file_id();
4534
5607
}
 
5608
#endif
4535
5609
 
4536
5610
 
4537
5611
Begin_load_query_log_event::
4538
 
Begin_load_query_log_event(const char* buf, uint32_t len,
 
5612
Begin_load_query_log_event(const char* buf, uint len,
4539
5613
                           const Format_description_log_event* desc_event)
4540
5614
  :Append_block_log_event(buf, len, desc_event)
4541
5615
{
4542
5616
}
4543
5617
 
4544
5618
 
 
5619
#if defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4545
5620
int Begin_load_query_log_event::get_create_or_append() const
4546
5621
{
4547
5622
  return 1; /* create the file */
4548
5623
}
4549
 
 
4550
 
 
 
5624
#endif /* defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
 
5625
 
 
5626
 
 
5627
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4551
5628
Log_event::enum_skip_reason
4552
5629
Begin_load_query_log_event::do_shall_skip(Relay_log_info *rli)
4553
5630
{
4557
5634
  */
4558
5635
  return continue_group(rli);
4559
5636
}
 
5637
#endif
4560
5638
 
4561
5639
 
4562
5640
/**************************************************************************
4564
5642
**************************************************************************/
4565
5643
 
4566
5644
 
 
5645
#ifndef MYSQL_CLIENT
4567
5646
Execute_load_query_log_event::
4568
5647
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,
 
5648
                             ulong query_length_arg, uint fn_pos_start_arg,
 
5649
                             uint fn_pos_end_arg,
4571
5650
                             enum_load_dup_handling dup_handling_arg,
4572
5651
                             bool using_trans, bool suppress_use,
4573
5652
                             THD::killed_state killed_err_arg):
4577
5656
  fn_pos_end(fn_pos_end_arg), dup_handling(dup_handling_arg)
4578
5657
{
4579
5658
}
 
5659
#endif /* !MYSQL_CLIENT */
4580
5660
 
4581
5661
 
4582
5662
Execute_load_query_log_event::
4583
 
Execute_load_query_log_event(const char* buf, uint32_t event_len,
 
5663
Execute_load_query_log_event(const char* buf, uint event_len,
4584
5664
                             const Format_description_log_event* desc_event):
4585
5665
  Query_log_event(buf, event_len, desc_event, EXECUTE_LOAD_QUERY_EVENT),
4586
5666
  file_id(0), fn_pos_start(0), fn_pos_end(0)
4608
5688
}
4609
5689
 
4610
5690
 
 
5691
#ifndef MYSQL_CLIENT
4611
5692
bool
4612
5693
Execute_load_query_log_event::write_post_header_for_derived(IO_CACHE* file)
4613
5694
{
4614
 
  unsigned char buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
 
5695
  uchar buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
4615
5696
  int4store(buf, file_id);
4616
5697
  int4store(buf + 4, fn_pos_start);
4617
5698
  int4store(buf + 4 + 4, fn_pos_end);
4618
 
  *(buf + 4 + 4 + 4)= (unsigned char) dup_handling;
 
5699
  *(buf + 4 + 4 + 4)= (uchar) dup_handling;
4619
5700
  return my_b_safe_write(file, buf, EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
4620
5701
}
4621
 
 
4622
 
 
 
5702
#endif
 
5703
 
 
5704
 
 
5705
#ifdef MYSQL_CLIENT
 
5706
void Execute_load_query_log_event::print(FILE* file,
 
5707
                                         PRINT_EVENT_INFO* print_event_info)
 
5708
{
 
5709
  print(file, print_event_info, 0);
 
5710
}
 
5711
 
 
5712
/**
 
5713
  Prints the query as LOAD DATA LOCAL and with rewritten filename.
 
5714
*/
 
5715
void Execute_load_query_log_event::print(FILE* file,
 
5716
                                         PRINT_EVENT_INFO* print_event_info,
 
5717
                                         const char *local_fname)
 
5718
{
 
5719
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
5720
 
 
5721
  print_query_header(&cache, print_event_info);
 
5722
 
 
5723
  if (local_fname)
 
5724
  {
 
5725
    my_b_write(&cache, (uchar*) query, fn_pos_start);
 
5726
    my_b_printf(&cache, " LOCAL INFILE \'");
 
5727
    my_b_printf(&cache, local_fname);
 
5728
    my_b_printf(&cache, "\'");
 
5729
    if (dup_handling == LOAD_DUP_REPLACE)
 
5730
      my_b_printf(&cache, " REPLACE");
 
5731
    my_b_printf(&cache, " INTO");
 
5732
    my_b_write(&cache, (uchar*) query + fn_pos_end, q_len-fn_pos_end);
 
5733
    my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
 
5734
  }
 
5735
  else
 
5736
  {
 
5737
    my_b_write(&cache, (uchar*) query, q_len);
 
5738
    my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
 
5739
  }
 
5740
 
 
5741
  if (!print_event_info->short_form)
 
5742
    my_b_printf(&cache, "# file_id: %d \n", file_id);
 
5743
}
 
5744
#endif
 
5745
 
 
5746
 
 
5747
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4623
5748
void Execute_load_query_log_event::pack_info(Protocol *protocol)
4624
5749
{
4625
5750
  char *buf, *pos;
4628
5753
  pos= buf;
4629
5754
  if (db && db_len)
4630
5755
  {
4631
 
    pos= my_stpcpy(buf, "use `");
 
5756
    pos= strmov(buf, "use `");
4632
5757
    memcpy(pos, db, db_len);
4633
 
    pos= my_stpcpy(pos+db_len, "`; ");
 
5758
    pos= strmov(pos+db_len, "`; ");
4634
5759
  }
4635
5760
  if (query && q_len)
4636
5761
  {
4637
5762
    memcpy(pos, query, q_len);
4638
5763
    pos+= q_len;
4639
5764
  }
4640
 
  pos= my_stpcpy(pos, " ;file_id=");
 
5765
  pos= strmov(pos, " ;file_id=");
4641
5766
  pos= int10_to_str((long) file_id, pos, 10);
4642
5767
  protocol->store(buf, pos-buf, &my_charset_bin);
4643
 
  free(buf);
 
5768
  my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
4644
5769
}
4645
5770
 
4646
5771
 
4660
5785
  if (buf == NULL)
4661
5786
  {
4662
5787
    rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
4663
 
                ER(ER_SLAVE_FATAL_ERROR),
4664
 
                _("Not enough memory"));
 
5788
                ER(ER_SLAVE_FATAL_ERROR), "Not enough memory");
4665
5789
    return 1;
4666
5790
  }
4667
5791
 
4670
5794
  p+= fn_pos_start;
4671
5795
  fname= (p= strmake(p, STRING_WITH_LEN(" INFILE \'")));
4672
5796
  p= slave_load_file_stem(p, file_id, server_id, ".data");
4673
 
  fname_end= p= strchr(p, '\0');                      // Safer than p=p+5
 
5797
  fname_end= p= strend(p);                      // Safer than p=p+5
4674
5798
  *(p++)='\'';
4675
5799
  switch (dup_handling) {
4676
5800
  case LOAD_DUP_IGNORE:
4698
5822
  if (!error)
4699
5823
    (void) my_delete(fname, MYF(MY_WME));
4700
5824
 
4701
 
  free(buf);
 
5825
  my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
4702
5826
  return error;
4703
5827
}
 
5828
#endif
4704
5829
 
4705
5830
 
4706
5831
/**************************************************************************
4720
5845
            write_str(file, line_term,  (uint) line_term_len) ||
4721
5846
            write_str(file, line_start, (uint) line_start_len) ||
4722
5847
            write_str(file, escaped,    (uint) escaped_len) ||
4723
 
            my_b_safe_write(file,(unsigned char*) &opt_flags,1));
 
5848
            my_b_safe_write(file,(uchar*) &opt_flags,1));
4724
5849
  }
4725
5850
  else
4726
5851
  {
4736
5861
    old_ex.escaped=    *escaped;
4737
5862
    old_ex.opt_flags=  opt_flags;
4738
5863
    old_ex.empty_flags=empty_flags;
4739
 
    return my_b_safe_write(file, (unsigned char*) &old_ex, sizeof(old_ex)) != 0;
 
5864
    return my_b_safe_write(file, (uchar*) &old_ex, sizeof(old_ex)) != 0;
4740
5865
  }
4741
5866
}
4742
5867
 
4796
5921
        Rows_log_event member functions
4797
5922
**************************************************************************/
4798
5923
 
4799
 
Rows_log_event::Rows_log_event(THD *thd_arg, Table *tbl_arg, ulong tid,
 
5924
#ifndef MYSQL_CLIENT
 
5925
Rows_log_event::Rows_log_event(THD *thd_arg, TABLE *tbl_arg, ulong tid,
4800
5926
                               MY_BITMAP const *cols, bool is_transactional)
4801
5927
  : Log_event(thd_arg, 0, is_transactional),
4802
5928
    m_row_count(0),
4804
5930
    m_table_id(tid),
4805
5931
    m_width(tbl_arg ? tbl_arg->s->fields : 1),
4806
5932
    m_rows_buf(0), m_rows_cur(0), m_rows_end(0), m_flags(0) 
 
5933
#ifdef HAVE_REPLICATION
4807
5934
    , m_curr_row(NULL), m_curr_row_end(NULL), m_key(NULL)
 
5935
#endif
4808
5936
{
4809
5937
  /*
4810
5938
    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
 
5939
    are null and the table id is ~0UL.  This is a temporary
4812
5940
    solution, to be able to terminate a started statement in the
4813
5941
    binary log: the extraneous events will be removed in the future.
4814
5942
   */
4815
 
  assert((tbl_arg && tbl_arg->s && tid != UINT32_MAX) || (!tbl_arg && !cols && tid == UINT32_MAX));
 
5943
  assert(tbl_arg && tbl_arg->s && tid != ~0UL ||
 
5944
              !tbl_arg && !cols && tid == ~0UL);
4816
5945
 
4817
5946
  if (thd_arg->options & OPTION_NO_FOREIGN_KEY_CHECKS)
4818
5947
      set_flags(NO_FOREIGN_KEY_CHECKS_F);
4837
5966
    m_cols.bitmap= 0;
4838
5967
  }
4839
5968
}
4840
 
 
4841
 
 
4842
 
Rows_log_event::Rows_log_event(const char *buf, uint32_t event_len,
 
5969
#endif
 
5970
 
 
5971
Rows_log_event::Rows_log_event(const char *buf, uint event_len,
4843
5972
                               Log_event_type event_type,
4844
5973
                               const Format_description_log_event
4845
5974
                               *description_event)
4846
5975
  : Log_event(buf, description_event),
4847
5976
    m_row_count(0),
 
5977
#ifndef MYSQL_CLIENT
4848
5978
    m_table(NULL),
 
5979
#endif
4849
5980
    m_table_id(0), m_rows_buf(0), m_rows_cur(0), m_rows_end(0)
 
5981
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4850
5982
    , m_curr_row(NULL), m_curr_row_end(NULL), m_key(NULL)
 
5983
#endif
4851
5984
{
4852
 
  uint8_t const common_header_len= description_event->common_header_len;
4853
 
  uint8_t const post_header_len= description_event->post_header_len[event_type-1];
 
5985
  uint8 const common_header_len= description_event->common_header_len;
 
5986
  uint8 const post_header_len= description_event->post_header_len[event_type-1];
4854
5987
 
4855
5988
  const char *post_start= buf + common_header_len;
4856
5989
  post_start+= RW_MAPID_OFFSET;
4868
6001
 
4869
6002
  m_flags= uint2korr(post_start);
4870
6003
 
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;
 
6004
  uchar const *const var_start=
 
6005
    (const uchar *)buf + common_header_len + post_header_len;
 
6006
  uchar const *const ptr_width= var_start;
 
6007
  uchar *ptr_after_width= (uchar*) ptr_width;
4875
6008
  m_width = net_field_length(&ptr_after_width);
4876
6009
  /* if bitmap_init fails, catched in is_valid() */
4877
6010
  if (likely(!bitmap_init(&m_cols,
4912
6045
    }
4913
6046
  }
4914
6047
 
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));
 
6048
  const uchar* const ptr_rows_data= (const uchar*) ptr_after_width;
 
6049
 
 
6050
  size_t const data_size= event_len - (ptr_rows_data - (const uchar *) buf);
 
6051
 
 
6052
  m_rows_buf= (uchar*) my_malloc(data_size, MYF(MY_WME));
4920
6053
  if (likely((bool)m_rows_buf))
4921
6054
  {
 
6055
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4922
6056
    m_curr_row= m_rows_buf;
 
6057
#endif
4923
6058
    m_rows_end= m_rows_buf + data_size;
4924
6059
    m_rows_cur= m_rows_end;
4925
6060
    memcpy(m_rows_buf, ptr_rows_data, data_size);
4933
6068
Rows_log_event::~Rows_log_event()
4934
6069
{
4935
6070
  if (m_cols.bitmap == m_bitbuf) // no my_malloc happened
4936
 
    m_cols.bitmap= 0; // so no free in bitmap_free
 
6071
    m_cols.bitmap= 0; // so no my_free in bitmap_free
4937
6072
  bitmap_free(&m_cols); // To pair with bitmap_init().
4938
 
  free((unsigned char*)m_rows_buf);
 
6073
  my_free((uchar*)m_rows_buf, MYF(MY_ALLOW_ZERO_PTR));
4939
6074
}
4940
6075
 
4941
6076
int Rows_log_event::get_data_size()
4942
6077
{
4943
6078
  int const type_code= get_type_code();
4944
6079
 
4945
 
  unsigned char buf[sizeof(m_width)+1];
4946
 
  unsigned char *end= net_store_length(buf, (m_width + 7) / 8);
 
6080
  uchar buf[sizeof(m_width)+1];
 
6081
  uchar *end= net_store_length(buf, (m_width + 7) / 8);
4947
6082
 
4948
6083
  int data_size= ROWS_HEADER_LEN;
4949
6084
  data_size+= no_bytes_in_map(&m_cols);
4957
6092
}
4958
6093
 
4959
6094
 
4960
 
int Rows_log_event::do_add_row_data(unsigned char *row_data, size_t length)
 
6095
#ifndef MYSQL_CLIENT
 
6096
int Rows_log_event::do_add_row_data(uchar *row_data, size_t length)
4961
6097
{
4962
6098
  /*
4963
6099
    When the table has a primary key, we would probably want, by default, to
4977
6113
  }
4978
6114
 
4979
6115
  assert(m_rows_buf <= m_rows_cur);
4980
 
  assert(!m_rows_buf || (m_rows_end && m_rows_buf <= m_rows_end));
 
6116
  assert(!m_rows_buf || m_rows_end && m_rows_buf <= m_rows_end);
4981
6117
  assert(m_rows_cur <= m_rows_end);
4982
6118
 
4983
6119
  /* The cast will always work since m_rows_cur <= m_rows_end */
4988
6124
    my_ptrdiff_t const new_alloc= 
4989
6125
        block_size * ((cur_size + length + block_size - 1) / block_size);
4990
6126
 
4991
 
    unsigned char* const new_buf= (unsigned char*)my_realloc((unsigned char*)m_rows_buf, (uint) new_alloc,
 
6127
    uchar* const new_buf= (uchar*)my_realloc((uchar*)m_rows_buf, (uint) new_alloc,
4992
6128
                                           MYF(MY_ALLOW_ZERO_PTR|MY_WME));
4993
6129
    if (unlikely(!new_buf))
4994
6130
      return(HA_ERR_OUT_OF_MEM);
5013
6149
  m_row_count++;
5014
6150
  return(0);
5015
6151
}
 
6152
#endif
5016
6153
 
 
6154
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
5017
6155
int Rows_log_event::do_apply_event(Relay_log_info const *rli)
5018
6156
{
5019
6157
  int error= 0;
5020
6158
  /*
5021
 
    If m_table_id == UINT32_MAX, then we have a dummy event that does not
 
6159
    If m_table_id == ~0UL, then we have a dummy event that does not
5022
6160
    contain any data.  In that case, we just remove all tables in the
5023
6161
    tables_to_lock list, close the thread tables, and return with
5024
6162
    success.
5025
6163
   */
5026
 
  if (m_table_id == UINT32_MAX)
 
6164
  if (m_table_id == ~0UL)
5027
6165
  {
5028
6166
    /*
5029
6167
       This one is supposed to be set: just an extra check so that
5091
6229
            Error reporting borrowed from Query_log_event with many excessive
5092
6230
            simplifications (we don't honour --slave-skip-errors)
5093
6231
          */
5094
 
          uint32_t actual_error= thd->main_da.sql_errno();
 
6232
          uint actual_error= thd->main_da.sql_errno();
5095
6233
          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")),
 
6234
                      "Error '%s' in %s event: when locking tables",
 
6235
                      (actual_error ? thd->main_da.message():
 
6236
                       "unexpected success or fatal error"),
5100
6237
                      get_type_str());
5101
6238
          thd->is_fatal_error= 1;
5102
6239
        }
5103
6240
        else
5104
6241
        {
5105
6242
          rli->report(ERROR_LEVEL, error,
5106
 
                      _("Error in %s event: when locking tables"),
 
6243
                      "Error in %s event: when locking tables",
5107
6244
                      get_type_str());
5108
6245
        }
5109
6246
        const_cast<Relay_log_info*>(rli)->clear_tables_to_lock();
5124
6261
        need to add code to assert that is the case.
5125
6262
       */
5126
6263
      thd->binlog_flush_pending_rows_event(false);
5127
 
      TableList *tables= rli->tables_to_lock;
 
6264
      TABLE_LIST *tables= rli->tables_to_lock;
5128
6265
      close_tables_for_reopen(thd, &tables);
5129
6266
 
5130
 
      uint32_t tables_count= rli->tables_to_lock_count;
 
6267
      uint tables_count= rli->tables_to_lock_count;
5131
6268
      if ((error= open_tables(thd, &tables, &tables_count, 0)))
5132
6269
      {
5133
6270
        if (thd->is_slave_error || thd->is_fatal_error)
5136
6273
            Error reporting borrowed from Query_log_event with many excessive
5137
6274
            simplifications (we don't honour --slave-skip-errors)
5138
6275
          */
5139
 
          uint32_t actual_error= thd->main_da.sql_errno();
 
6276
          uint actual_error= thd->main_da.sql_errno();
5140
6277
          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")));
 
6278
                      "Error '%s' on reopening tables",
 
6279
                      (actual_error ? thd->main_da.message() :
 
6280
                       "unexpected success or fatal error"));
5145
6281
          thd->is_slave_error= 1;
5146
6282
        }
5147
6283
        const_cast<Relay_log_info*>(rli)->clear_tables_to_lock();
5154
6290
      ensure that they still have the correct type.
5155
6291
 
5156
6292
      We can use a down cast here since we know that every table added
5157
 
      to the tables_to_lock is a RPL_TableList.
 
6293
      to the tables_to_lock is a RPL_TABLE_LIST.
5158
6294
    */
5159
6295
 
5160
6296
    {
5161
 
      RPL_TableList *ptr= rli->tables_to_lock;
5162
 
      for ( ; ptr ; ptr= static_cast<RPL_TableList*>(ptr->next_global))
 
6297
      RPL_TABLE_LIST *ptr= rli->tables_to_lock;
 
6298
      for ( ; ptr ; ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global))
5163
6299
      {
5164
6300
        if (ptr->m_tabledef.compatible_with(rli, ptr->table))
5165
6301
        {
5186
6322
      Rows_log_event, we can invalidate the query cache for the
5187
6323
      associated table.
5188
6324
     */
5189
 
    for (TableList *ptr= rli->tables_to_lock ; ptr ; ptr= ptr->next_global)
 
6325
    for (TABLE_LIST *ptr= rli->tables_to_lock ; ptr ; ptr= ptr->next_global)
5190
6326
    {
5191
6327
      const_cast<Relay_log_info*>(rli)->m_table_map.set_table(ptr->table_id, ptr->table);
5192
6328
    }
5193
6329
  }
5194
6330
 
5195
 
  Table* 
 
6331
  TABLE* 
5196
6332
    table= 
5197
6333
    m_table= const_cast<Relay_log_info*>(rli)->m_table_map.get_table(m_table_id);
5198
6334
 
5494
6630
    }
5495
6631
    else
5496
6632
      rli->report(ERROR_LEVEL, error,
5497
 
                  _("Error in %s event: commit of row events failed, "
5498
 
                    "table `%s`.`%s`"),
 
6633
                  "Error in %s event: commit of row events failed, "
 
6634
                  "table `%s`.`%s`",
5499
6635
                  get_type_str(), m_table->s->db.str,
5500
6636
                  m_table->s->table_name.str);
5501
6637
  }
5507
6643
  return(error);
5508
6644
}
5509
6645
 
 
6646
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
 
6647
 
 
6648
#ifndef MYSQL_CLIENT
5510
6649
bool Rows_log_event::write_data_header(IO_CACHE *file)
5511
6650
{
5512
 
  unsigned char buf[ROWS_HEADER_LEN];   // No need to init the buffer
5513
 
  assert(m_table_id != UINT32_MAX);
5514
 
  int6store(buf + RW_MAPID_OFFSET, (uint64_t)m_table_id);
 
6651
  uchar buf[ROWS_HEADER_LEN];   // No need to init the buffer
 
6652
  assert(m_table_id != ~0UL);
 
6653
  int6store(buf + RW_MAPID_OFFSET, (ulonglong)m_table_id);
5515
6654
  int2store(buf + RW_FLAGS_OFFSET, m_flags);
5516
6655
  return (my_b_safe_write(file, buf, ROWS_HEADER_LEN));
5517
6656
}
5522
6661
     Note that this should be the number of *bits*, not the number of
5523
6662
     bytes.
5524
6663
  */
5525
 
  unsigned char sbuf[sizeof(m_width)];
 
6664
  uchar sbuf[sizeof(m_width)];
5526
6665
  my_ptrdiff_t const data_size= m_rows_cur - m_rows_buf;
5527
6666
  bool res= false;
5528
 
  unsigned char *const sbuf_end= net_store_length(sbuf, (size_t) m_width);
 
6667
  uchar *const sbuf_end= net_store_length(sbuf, (size_t) m_width);
5529
6668
  assert(static_cast<size_t>(sbuf_end - sbuf) <= sizeof(sbuf));
5530
6669
 
5531
6670
  res= res || my_b_safe_write(file, sbuf, (size_t) (sbuf_end - sbuf));
5532
6671
 
5533
 
  res= res || my_b_safe_write(file, (unsigned char*) m_cols.bitmap,
 
6672
  res= res || my_b_safe_write(file, (uchar*) m_cols.bitmap,
5534
6673
                              no_bytes_in_map(&m_cols));
5535
6674
  /*
5536
6675
    TODO[refactor write]: Remove the "down cast" here (and elsewhere).
5537
6676
   */
5538
6677
  if (get_type_code() == UPDATE_ROWS_EVENT)
5539
6678
  {
5540
 
    res= res || my_b_safe_write(file, (unsigned char*) m_cols_ai.bitmap,
 
6679
    res= res || my_b_safe_write(file, (uchar*) m_cols_ai.bitmap,
5541
6680
                                no_bytes_in_map(&m_cols_ai));
5542
6681
  }
5543
6682
  res= res || my_b_safe_write(file, m_rows_buf, (size_t) data_size);
5545
6684
  return res;
5546
6685
 
5547
6686
}
5548
 
 
5549
 
 
 
6687
#endif
 
6688
 
 
6689
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5550
6690
void Rows_log_event::pack_info(Protocol *protocol)
5551
6691
{
5552
6692
  char buf[256];
5556
6696
                         "table_id: %lu%s", m_table_id, flagstr);
5557
6697
  protocol->store(buf, bytes, &my_charset_bin);
5558
6698
}
5559
 
 
 
6699
#endif
 
6700
 
 
6701
#ifdef MYSQL_CLIENT
 
6702
void Rows_log_event::print_helper(FILE *file,
 
6703
                                  PRINT_EVENT_INFO *print_event_info,
 
6704
                                  char const *const name)
 
6705
{
 
6706
  IO_CACHE *const head= &print_event_info->head_cache;
 
6707
  IO_CACHE *const body= &print_event_info->body_cache;
 
6708
  if (!print_event_info->short_form)
 
6709
  {
 
6710
    bool const last_stmt_event= get_flags(STMT_END_F);
 
6711
    print_header(head, print_event_info, !last_stmt_event);
 
6712
    my_b_printf(head, "\t%s: table id %lu%s\n",
 
6713
                name, m_table_id,
 
6714
                last_stmt_event ? " flags: STMT_END_F" : "");
 
6715
    print_base64(body, print_event_info, !last_stmt_event);
 
6716
  }
 
6717
 
 
6718
  if (get_flags(STMT_END_F))
 
6719
  {
 
6720
    copy_event_cache_to_file_and_reinit(head, file);
 
6721
    copy_event_cache_to_file_and_reinit(body, file);
 
6722
  }
 
6723
}
 
6724
#endif
5560
6725
 
5561
6726
/**************************************************************************
5562
6727
        Table_map_log_event member functions and support functions
5583
6748
  same as the columns for the table on the slave.
5584
6749
 
5585
6750
  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
 
6751
  string of bytes (uchar) in the binlog. A field may require 1 or more bytes
5587
6752
  to store the information. In cases where values require multiple bytes 
5588
6753
  (e.g. values > 255), the endian-safe methods are used to properly encode 
5589
6754
  the values on the master and decode them on the slave. When the field
5590
6755
  metadata values are captured on the slave, they are stored in an array of
5591
 
  type uint16_t. This allows the least number of casts to prevent casting bugs
 
6756
  type uint16. This allows the least number of casts to prevent casting bugs
5592
6757
  when the field metadata is used in comparisons of field attributes. When
5593
6758
  the field metadata is used for calculating addresses in pointer math, the
5594
 
  type used is uint32_t. 
 
6759
  type used is uint32. 
5595
6760
*/
5596
6761
 
 
6762
#if !defined(MYSQL_CLIENT)
5597
6763
/**
5598
6764
  Save the field metadata based on the real_type of the field.
5599
6765
  The metadata saved depends on the type of the field. Some fields
5625
6791
    index+= m_table->s->field[i]->save_field_metadata(&m_field_metadata[index]);
5626
6792
  return(index);
5627
6793
}
 
6794
#endif /* !defined(MYSQL_CLIENT) */
5628
6795
 
5629
6796
/*
5630
6797
  Constructor used to build an event for writing to the binary log.
5631
6798
  Mats says tbl->s lives longer than this event so it's ok to copy pointers
5632
6799
  (tbl->s->db etc) and not pointer content.
5633
6800
 */
5634
 
Table_map_log_event::Table_map_log_event(THD *thd, Table *tbl, ulong tid,
5635
 
                                         bool is_transactional __attribute__((unused)),
5636
 
                                         uint16_t flags)
 
6801
#if !defined(MYSQL_CLIENT)
 
6802
Table_map_log_event::Table_map_log_event(THD *thd, TABLE *tbl, ulong tid,
 
6803
                                         bool is_transactional __attribute__((__unused__)),
 
6804
                                         uint16 flags)
5637
6805
  : Log_event(thd, 0, true),
5638
6806
    m_table(tbl),
5639
6807
    m_dbnam(tbl->s->db.str),
5650
6818
    m_null_bits(0),
5651
6819
    m_meta_memory(NULL)
5652
6820
{
5653
 
  assert(m_table_id != UINT32_MAX);
 
6821
  assert(m_table_id != ~0UL);
5654
6822
  /*
5655
6823
    In TABLE_SHARE, "db" and "table_name" are 0-terminated (see this comment in
5656
6824
    table.cc / alloc_table_share():
5668
6836
  m_data_size+= 1 + m_colcnt;   // COLCNT and column types
5669
6837
 
5670
6838
  /* If malloc fails, caught in is_valid() */
5671
 
  if ((m_memory= (unsigned char*) my_malloc(m_colcnt, MYF(MY_WME))))
 
6839
  if ((m_memory= (uchar*) my_malloc(m_colcnt, MYF(MY_WME))))
5672
6840
  {
5673
 
    m_coltype= reinterpret_cast<unsigned char*>(m_memory);
 
6841
    m_coltype= reinterpret_cast<uchar*>(m_memory);
5674
6842
    for (unsigned int i= 0 ; i < m_table->s->fields ; ++i)
5675
6843
      m_coltype[i]= m_table->field[i]->type();
5676
6844
  }
5681
6849
    that is not on the slave and is null and thus not in the row data during
5682
6850
    replication.
5683
6851
  */
5684
 
  uint32_t num_null_bytes= (m_table->s->fields + 7) / 8;
 
6852
  uint num_null_bytes= (m_table->s->fields + 7) / 8;
5685
6853
  m_data_size+= num_null_bytes;
5686
 
  m_meta_memory= (unsigned char *)my_multi_malloc(MYF(MY_WME),
 
6854
  m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
5687
6855
                                 &m_null_bits, num_null_bytes,
5688
6856
                                 &m_field_metadata, (m_colcnt * 2),
5689
6857
                                 NULL);
5690
6858
 
5691
 
  memset(m_field_metadata, 0, (m_colcnt * 2));
 
6859
  bzero(m_field_metadata, (m_colcnt * 2));
5692
6860
 
5693
6861
  /*
5694
6862
    Create an array for the field metadata and store it.
5705
6873
  else
5706
6874
    m_data_size+= m_field_metadata_size + 1; 
5707
6875
 
5708
 
  memset(m_null_bits, 0, num_null_bytes);
 
6876
  bzero(m_null_bits, num_null_bytes);
5709
6877
  for (unsigned int i= 0 ; i < m_table->s->fields ; ++i)
5710
6878
    if (m_table->field[i]->maybe_null())
5711
6879
      m_null_bits[(i / 8)]+= 1 << (i % 8);
5712
6880
 
5713
6881
}
5714
 
 
 
6882
#endif /* !defined(MYSQL_CLIENT) */
5715
6883
 
5716
6884
/*
5717
6885
  Constructor used by slave to read the event from the binary log.
5718
6886
 */
5719
 
Table_map_log_event::Table_map_log_event(const char *buf, uint32_t event_len,
 
6887
#if defined(HAVE_REPLICATION)
 
6888
Table_map_log_event::Table_map_log_event(const char *buf, uint event_len,
5720
6889
                                         const Format_description_log_event
5721
6890
                                         *description_event)
5722
6891
 
5723
6892
  : Log_event(buf, description_event),
 
6893
#ifndef MYSQL_CLIENT
5724
6894
    m_table(NULL),
 
6895
#endif
5725
6896
    m_dbnam(NULL), m_dblen(0), m_tblnam(NULL), m_tbllen(0),
5726
6897
    m_colcnt(0), m_coltype(0),
5727
6898
    m_memory(NULL), m_table_id(ULONG_MAX), m_flags(0),
5730
6901
{
5731
6902
  unsigned int bytes_read= 0;
5732
6903
 
5733
 
  uint8_t common_header_len= description_event->common_header_len;
5734
 
  uint8_t post_header_len= description_event->post_header_len[TABLE_MAP_EVENT-1];
 
6904
  uint8 common_header_len= description_event->common_header_len;
 
6905
  uint8 post_header_len= description_event->post_header_len[TABLE_MAP_EVENT-1];
5735
6906
 
5736
6907
  /* Read the post-header */
5737
6908
  const char *post_start= buf + common_header_len;
5750
6921
    post_start+= TM_FLAGS_OFFSET;
5751
6922
  }
5752
6923
 
5753
 
  assert(m_table_id != UINT32_MAX);
 
6924
  assert(m_table_id != ~0UL);
5754
6925
 
5755
6926
  m_flags= uint2korr(post_start);
5756
6927
 
5758
6929
  const char *const vpart= buf + common_header_len + post_header_len;
5759
6930
 
5760
6931
  /* 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;
 
6932
  uchar const *const ptr_dblen= (uchar const*)vpart + 0;
 
6933
  m_dblen= *(uchar*) ptr_dblen;
5763
6934
 
5764
6935
  /* 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;
 
6936
  uchar const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
 
6937
  m_tbllen= *(uchar*) ptr_tbllen;
5767
6938
 
5768
6939
  /* 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;
 
6940
  uchar const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
 
6941
  uchar *ptr_after_colcnt= (uchar*) ptr_colcnt;
5771
6942
  m_colcnt= net_field_length(&ptr_after_colcnt);
5772
6943
 
5773
6944
  /* 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),
 
6945
  m_memory= (uchar*) my_multi_malloc(MYF(MY_WME),
5775
6946
                                     &m_dbnam, (uint) m_dblen + 1,
5776
6947
                                     &m_tblnam, (uint) m_tbllen + 1,
5777
6948
                                     &m_coltype, (uint) m_colcnt,
5778
 
                                     NULL);
 
6949
                                     NullS);
5779
6950
 
5780
6951
  if (m_memory)
5781
6952
  {
5785
6956
    memcpy(m_coltype, ptr_after_colcnt, m_colcnt);
5786
6957
 
5787
6958
    ptr_after_colcnt= ptr_after_colcnt + m_colcnt;
5788
 
    bytes_read= ptr_after_colcnt - (unsigned char *)buf;
 
6959
    bytes_read= ptr_after_colcnt - (uchar *)buf;
5789
6960
    if (bytes_read < event_len)
5790
6961
    {
5791
6962
      m_field_metadata_size= net_field_length(&ptr_after_colcnt);
5792
6963
      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),
 
6964
      uint num_null_bytes= (m_colcnt + 7) / 8;
 
6965
      m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
5795
6966
                                     &m_null_bits, num_null_bytes,
5796
6967
                                     &m_field_metadata, m_field_metadata_size,
5797
6968
                                     NULL);
5798
6969
      memcpy(m_field_metadata, ptr_after_colcnt, m_field_metadata_size);
5799
 
      ptr_after_colcnt= (unsigned char*)ptr_after_colcnt + m_field_metadata_size;
 
6970
      ptr_after_colcnt= (uchar*)ptr_after_colcnt + m_field_metadata_size;
5800
6971
      memcpy(m_null_bits, ptr_after_colcnt, num_null_bytes);
5801
6972
    }
5802
6973
  }
5803
6974
 
5804
6975
  return;
5805
6976
}
 
6977
#endif
5806
6978
 
5807
6979
Table_map_log_event::~Table_map_log_event()
5808
6980
{
5809
 
  free(m_meta_memory);
5810
 
  free(m_memory);
 
6981
  my_free(m_meta_memory, MYF(MY_ALLOW_ZERO_PTR));
 
6982
  my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));
5811
6983
}
5812
6984
 
5813
6985
/*
5821
6993
       4     Daisy-chaining RBR with SBR not possible
5822
6994
 */
5823
6995
 
 
6996
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
5824
6997
int Table_map_log_event::do_apply_event(Relay_log_info const *rli)
5825
6998
{
5826
 
  RPL_TableList *table_list;
 
6999
  RPL_TABLE_LIST *table_list;
5827
7000
  char *db_mem, *tname_mem;
5828
7001
  size_t dummy_len;
5829
7002
  void *memory;
5835
7008
  pthread_mutex_unlock(&LOCK_thread_count);
5836
7009
 
5837
7010
  if (!(memory= my_multi_malloc(MYF(MY_WME),
5838
 
                                &table_list, (uint) sizeof(RPL_TableList),
 
7011
                                &table_list, (uint) sizeof(RPL_TABLE_LIST),
5839
7012
                                &db_mem, (uint) NAME_LEN + 1,
5840
7013
                                &tname_mem, (uint) NAME_LEN + 1,
5841
 
                                NULL)))
 
7014
                                NullS)))
5842
7015
    return(HA_ERR_OUT_OF_MEM);
5843
7016
 
5844
 
  memset(table_list, 0, sizeof(*table_list));
 
7017
  bzero(table_list, sizeof(*table_list));
5845
7018
  table_list->db = db_mem;
5846
7019
  table_list->alias= table_list->table_name = tname_mem;
5847
7020
  table_list->lock_type= TL_WRITE;
5848
7021
  table_list->next_global= table_list->next_local= 0;
5849
7022
  table_list->table_id= m_table_id;
5850
7023
  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);
 
7024
  strmov(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
 
7025
  strmov(table_list->table_name, m_tblnam);
5853
7026
 
5854
7027
  int error= 0;
5855
7028
 
5856
7029
  if (!rpl_filter->db_ok(table_list->db) ||
5857
7030
      (rpl_filter->is_on() && !rpl_filter->tables_ok("", table_list)))
5858
7031
  {
5859
 
    free(memory);
 
7032
    my_free(memory, MYF(MY_WME));
5860
7033
  }
5861
7034
  else
5862
7035
  {
5883
7056
      table map.  Note that for any table that should not be
5884
7057
      replicated, a filter is needed.
5885
7058
 
5886
 
      The creation of a new TableList is used to up-cast the
5887
 
      table_list consisting of RPL_TableList items. This will work
 
7059
      The creation of a new TABLE_LIST is used to up-cast the
 
7060
      table_list consisting of RPL_TABLE_LIST items. This will work
5888
7061
      since the only case where the argument to open_tables() is
5889
7062
      changed, is when thd->lex->query_tables == table_list, i.e.,
5890
7063
      when the statement requires prelocking. Since this is not
5896
7069
      internally in the open_tables() function, hence we take a copy
5897
7070
      of the pointer to make sure that it's not lost.
5898
7071
    */
5899
 
    uint32_t count;
 
7072
    uint count;
5900
7073
    assert(thd->lex->query_tables != table_list);
5901
 
    TableList *tmp_table_list= table_list;
 
7074
    TABLE_LIST *tmp_table_list= table_list;
5902
7075
    if ((error= open_tables(thd, &tmp_table_list, &count, 0)))
5903
7076
    {
5904
7077
      if (thd->is_slave_error || thd->is_fatal_error)
5907
7080
          Error reporting borrowed from Query_log_event with many excessive
5908
7081
          simplifications (we don't honour --slave-skip-errors)
5909
7082
        */
5910
 
        uint32_t actual_error= thd->main_da.sql_errno();
 
7083
        uint actual_error= thd->main_da.sql_errno();
5911
7084
        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")),
 
7085
                    "Error '%s' on opening table `%s`.`%s`",
 
7086
                    (actual_error ? thd->main_da.message() :
 
7087
                     "unexpected success or fatal error"),
5916
7088
                    table_list->db, table_list->table_name);
5917
7089
        thd->is_slave_error= 1;
5918
7090
      }
5953
7125
  return(error);
5954
7126
 
5955
7127
err:
5956
 
  free(memory);
 
7128
  my_free(memory, MYF(MY_WME));
5957
7129
  return(error);
5958
7130
}
5959
7131
 
5973
7145
  return 0;
5974
7146
}
5975
7147
 
 
7148
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
5976
7149
 
 
7150
#ifndef MYSQL_CLIENT
5977
7151
bool Table_map_log_event::write_data_header(IO_CACHE *file)
5978
7152
{
5979
 
  assert(m_table_id != UINT32_MAX);
5980
 
  unsigned char buf[TABLE_MAP_HEADER_LEN];
5981
 
  int6store(buf + TM_MAPID_OFFSET, (uint64_t)m_table_id);
 
7153
  assert(m_table_id != ~0UL);
 
7154
  uchar buf[TABLE_MAP_HEADER_LEN];
 
7155
  int6store(buf + TM_MAPID_OFFSET, (ulonglong)m_table_id);
5982
7156
  int2store(buf + TM_FLAGS_OFFSET, m_flags);
5983
7157
  return (my_b_safe_write(file, buf, TABLE_MAP_HEADER_LEN));
5984
7158
}
5991
7165
  assert(m_dblen < 128);
5992
7166
  assert(m_tbllen < 128);
5993
7167
 
5994
 
  unsigned char const dbuf[]= { (unsigned char) m_dblen };
5995
 
  unsigned char const tbuf[]= { (unsigned char) m_tbllen };
 
7168
  uchar const dbuf[]= { (uchar) m_dblen };
 
7169
  uchar const tbuf[]= { (uchar) m_tbllen };
5996
7170
 
5997
 
  unsigned char cbuf[sizeof(m_colcnt)];
5998
 
  unsigned char *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
 
7171
  uchar cbuf[sizeof(m_colcnt)];
 
7172
  uchar *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
5999
7173
  assert(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf));
6000
7174
 
6001
7175
  /*
6002
7176
    Store the size of the field metadata.
6003
7177
  */
6004
 
  unsigned char mbuf[sizeof(m_field_metadata_size)];
6005
 
  unsigned char *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
 
7178
  uchar mbuf[sizeof(m_field_metadata_size)];
 
7179
  uchar *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
6006
7180
 
6007
7181
  return (my_b_safe_write(file, dbuf,      sizeof(dbuf)) ||
6008
 
          my_b_safe_write(file, (const unsigned char*)m_dbnam,   m_dblen+1) ||
 
7182
          my_b_safe_write(file, (const uchar*)m_dbnam,   m_dblen+1) ||
6009
7183
          my_b_safe_write(file, tbuf,      sizeof(tbuf)) ||
6010
 
          my_b_safe_write(file, (const unsigned char*)m_tblnam,  m_tbllen+1) ||
 
7184
          my_b_safe_write(file, (const uchar*)m_tblnam,  m_tbllen+1) ||
6011
7185
          my_b_safe_write(file, cbuf, (size_t) (cbuf_end - cbuf)) ||
6012
7186
          my_b_safe_write(file, m_coltype, m_colcnt) ||
6013
7187
          my_b_safe_write(file, mbuf, (size_t) (mbuf_end - mbuf)) ||
6014
7188
          my_b_safe_write(file, m_field_metadata, m_field_metadata_size),
6015
7189
          my_b_safe_write(file, m_null_bits, (m_colcnt + 7) / 8));
6016
7190
 }
 
7191
#endif
6017
7192
 
 
7193
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6018
7194
 
6019
7195
/*
6020
7196
  Print some useful information for the SHOW BINARY LOG information
6021
7197
  field.
6022
7198
 */
6023
7199
 
 
7200
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6024
7201
void Table_map_log_event::pack_info(Protocol *protocol)
6025
7202
{
6026
7203
    char buf[256];
6029
7206
                           m_table_id, m_dbnam, m_tblnam);
6030
7207
    protocol->store(buf, bytes, &my_charset_bin);
6031
7208
}
6032
 
 
 
7209
#endif
 
7210
 
 
7211
 
 
7212
#endif
 
7213
 
 
7214
 
 
7215
#ifdef MYSQL_CLIENT
 
7216
void Table_map_log_event::print(FILE * /* unused */,
 
7217
                                PRINT_EVENT_INFO *print_event_info)
 
7218
{
 
7219
  if (!print_event_info->short_form)
 
7220
  {
 
7221
    print_header(&print_event_info->head_cache, print_event_info, true);
 
7222
    my_b_printf(&print_event_info->head_cache,
 
7223
                "\tTable_map: `%s`.`%s` mapped to number %lu\n",
 
7224
                m_dbnam, m_tblnam, m_table_id);
 
7225
    print_base64(&print_event_info->body_cache, print_event_info, true);
 
7226
  }
 
7227
}
 
7228
#endif
6033
7229
 
6034
7230
/**************************************************************************
6035
7231
        Write_rows_log_event member functions
6038
7234
/*
6039
7235
  Constructor used to build an event for writing to the binary log.
6040
7236
 */
6041
 
Write_rows_log_event::Write_rows_log_event(THD *thd_arg, Table *tbl_arg,
 
7237
#if !defined(MYSQL_CLIENT)
 
7238
Write_rows_log_event::Write_rows_log_event(THD *thd_arg, TABLE *tbl_arg,
6042
7239
                                           ulong tid_arg,
6043
7240
                                           bool is_transactional)
6044
7241
  : Rows_log_event(thd_arg, tbl_arg, tid_arg, tbl_arg->write_set, is_transactional)
6045
7242
{
6046
7243
}
 
7244
#endif
6047
7245
 
6048
7246
/*
6049
7247
  Constructor used by slave to read the event from the binary log.
6050
7248
 */
6051
 
Write_rows_log_event::Write_rows_log_event(const char *buf, uint32_t event_len,
 
7249
#ifdef HAVE_REPLICATION
 
7250
Write_rows_log_event::Write_rows_log_event(const char *buf, uint event_len,
6052
7251
                                           const Format_description_log_event
6053
7252
                                           *description_event)
6054
7253
: Rows_log_event(buf, event_len, WRITE_ROWS_EVENT, description_event)
6055
7254
{
6056
7255
}
 
7256
#endif
6057
7257
 
 
7258
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6058
7259
int 
6059
7260
Write_rows_log_event::do_before_row_operations(const Slave_reporting_capability *const)
6060
7261
{
6132
7333
  return error? error : local_error;
6133
7334
}
6134
7335
 
 
7336
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6135
7337
 
6136
7338
/*
6137
7339
  Check if there are more UNIQUE keys after the given key.
6138
7340
*/
6139
7341
static int
6140
 
last_uniq_key(Table *table, uint32_t keyno)
 
7342
last_uniq_key(TABLE *table, uint keyno)
6141
7343
{
6142
7344
  while (++keyno < table->s->keys)
6143
7345
    if (table->key_info[keyno].flags & HA_NOSAME)
6211
7413
{
6212
7414
  assert(m_table != NULL && thd != NULL);
6213
7415
 
6214
 
  Table *table= m_table;  // pointer to event's table
 
7416
  TABLE *table= m_table;  // pointer to event's table
6215
7417
  int error;
6216
7418
  int keynum;
6217
7419
  auto_afree_ptr<char> key(NULL);
6228
7430
     values filled in and one flag to handle the case that the default
6229
7431
     values should be checked. Maybe these two flags can be combined.
6230
7432
  */
6231
 
  if ((error= prepare_record(table, &m_cols, m_width, true)))
 
7433
  if ((error= prepare_record(table, &m_cols, m_width,
 
7434
                             table->file->ht->db_type != DB_TYPE_NDBCLUSTER)))
6232
7435
    return(error);
6233
7436
  
6234
7437
  /* unpack row into table->record[0] */
6303
7506
        }
6304
7507
      }
6305
7508
 
6306
 
      key_copy((unsigned char*)key.get(), table->record[0], table->key_info + keynum,
 
7509
      key_copy((uchar*)key.get(), table->record[0], table->key_info + keynum,
6307
7510
               0);
6308
7511
      error= table->file->index_read_idx_map(table->record[1], keynum,
6309
 
                                             (const unsigned char*)key.get(),
 
7512
                                             (const uchar*)key.get(),
6310
7513
                                             HA_WHOLE_KEY,
6311
7514
                                             HA_READ_KEY_EXACT);
6312
7515
      if (error)
6380
7583
  return(error);
6381
7584
}
6382
7585
 
 
7586
#endif
6383
7587
 
6384
7588
int 
6385
7589
Write_rows_log_event::do_exec_row(const Relay_log_info *const rli)
6398
7602
  return error; 
6399
7603
}
6400
7604
 
 
7605
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
 
7606
 
 
7607
#ifdef MYSQL_CLIENT
 
7608
void Write_rows_log_event::print(FILE *file, PRINT_EVENT_INFO* print_event_info)
 
7609
{
 
7610
  Rows_log_event::print_helper(file, print_event_info, "Write_rows");
 
7611
}
 
7612
#endif
6401
7613
 
6402
7614
/**************************************************************************
6403
7615
        Delete_rows_log_event member functions
6404
7616
**************************************************************************/
6405
7617
 
 
7618
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6406
7619
/*
6407
7620
  Compares table->record[0] and table->record[1]
6408
7621
 
6409
7622
  Returns TRUE if different.
6410
7623
*/
6411
 
static bool record_compare(Table *table)
 
7624
static bool record_compare(TABLE *table)
6412
7625
{
6413
7626
  /*
6414
7627
    Need to set the X bit and the filler bits in both records since
6422
7635
    records. Check that the other engines also return correct records.
6423
7636
   */
6424
7637
  bool result= false;
6425
 
  unsigned char saved_x[2], saved_filler[2];
 
7638
  uchar saved_x[2], saved_filler[2];
6426
7639
 
6427
7640
  if (table->s->null_bytes > 0)
6428
7641
  {
6511
7724
{
6512
7725
  assert(m_table && m_table->in_use != NULL);
6513
7726
 
6514
 
  Table *table= m_table;
 
7727
  TABLE *table= m_table;
6515
7728
  int error;
6516
7729
 
6517
7730
  /* unpack row - missing fields get default values */
6699
7912
  return(error);
6700
7913
}
6701
7914
 
 
7915
#endif
6702
7916
 
6703
7917
/*
6704
7918
  Constructor used to build an event for writing to the binary log.
6705
7919
 */
6706
7920
 
6707
 
Delete_rows_log_event::Delete_rows_log_event(THD *thd_arg, Table *tbl_arg,
 
7921
#ifndef MYSQL_CLIENT
 
7922
Delete_rows_log_event::Delete_rows_log_event(THD *thd_arg, TABLE *tbl_arg,
6708
7923
                                             ulong tid,
6709
7924
                                             bool is_transactional)
6710
7925
  : Rows_log_event(thd_arg, tbl_arg, tid, tbl_arg->read_set, is_transactional)
6711
7926
{
6712
7927
}
 
7928
#endif /* #if !defined(MYSQL_CLIENT) */
6713
7929
 
6714
7930
/*
6715
7931
  Constructor used by slave to read the event from the binary log.
6716
7932
 */
6717
 
Delete_rows_log_event::Delete_rows_log_event(const char *buf, uint32_t event_len,
 
7933
#ifdef HAVE_REPLICATION
 
7934
Delete_rows_log_event::Delete_rows_log_event(const char *buf, uint event_len,
6718
7935
                                             const Format_description_log_event
6719
7936
                                             *description_event)
6720
7937
  : Rows_log_event(buf, event_len, DELETE_ROWS_EVENT, description_event)
6721
7938
{
6722
7939
}
 
7940
#endif
6723
7941
 
 
7942
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6724
7943
 
6725
7944
int 
6726
7945
Delete_rows_log_event::do_before_row_operations(const Slave_reporting_capability *const)
6737
7956
  if (m_table->s->keys > 0)
6738
7957
  {
6739
7958
    // Allocate buffer for key searches
6740
 
    m_key= (unsigned char*)my_malloc(m_table->key_info->key_length, MYF(MY_WME));
 
7959
    m_key= (uchar*)my_malloc(m_table->key_info->key_length, MYF(MY_WME));
6741
7960
    if (!m_key)
6742
7961
      return HA_ERR_OUT_OF_MEM;
6743
7962
  }
6751
7970
{
6752
7971
  /*error= ToDo:find out what this should really be, this triggers close_scan in nbd, returning error?*/
6753
7972
  m_table->file->ha_index_or_rnd_end();
6754
 
  free(m_key);
 
7973
  my_free(m_key, MYF(MY_ALLOW_ZERO_PTR));
6755
7974
  m_key= NULL;
6756
7975
 
6757
7976
  return error;
6772
7991
  return error;
6773
7992
}
6774
7993
 
 
7994
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
 
7995
 
 
7996
#ifdef MYSQL_CLIENT
 
7997
void Delete_rows_log_event::print(FILE *file,
 
7998
                                  PRINT_EVENT_INFO* print_event_info)
 
7999
{
 
8000
  Rows_log_event::print_helper(file, print_event_info, "Delete_rows");
 
8001
}
 
8002
#endif
 
8003
 
6775
8004
 
6776
8005
/**************************************************************************
6777
8006
        Update_rows_log_event member functions
6780
8009
/*
6781
8010
  Constructor used to build an event for writing to the binary log.
6782
8011
 */
6783
 
Update_rows_log_event::Update_rows_log_event(THD *thd_arg, Table *tbl_arg,
 
8012
#if !defined(MYSQL_CLIENT)
 
8013
Update_rows_log_event::Update_rows_log_event(THD *thd_arg, TABLE *tbl_arg,
6784
8014
                                             ulong tid,
6785
8015
                                             bool is_transactional)
6786
8016
: Rows_log_event(thd_arg, tbl_arg, tid, tbl_arg->read_set, is_transactional)
6804
8034
    }
6805
8035
  }
6806
8036
}
 
8037
#endif /* !defined(MYSQL_CLIENT) */
6807
8038
 
6808
8039
 
6809
8040
Update_rows_log_event::~Update_rows_log_event()
6810
8041
{
6811
8042
  if (m_cols_ai.bitmap == m_bitbuf_ai) // no my_malloc happened
6812
 
    m_cols_ai.bitmap= 0; // so no free in bitmap_free
 
8043
    m_cols_ai.bitmap= 0; // so no my_free in bitmap_free
6813
8044
  bitmap_free(&m_cols_ai); // To pair with bitmap_init().
6814
8045
}
6815
8046
 
6817
8048
/*
6818
8049
  Constructor used by slave to read the event from the binary log.
6819
8050
 */
6820
 
Update_rows_log_event::Update_rows_log_event(const char *buf, uint32_t event_len,
 
8051
#ifdef HAVE_REPLICATION
 
8052
Update_rows_log_event::Update_rows_log_event(const char *buf, uint event_len,
6821
8053
                                             const
6822
8054
                                             Format_description_log_event
6823
8055
                                             *description_event)
6824
8056
  : Rows_log_event(buf, event_len, UPDATE_ROWS_EVENT, description_event)
6825
8057
{
6826
8058
}
 
8059
#endif
6827
8060
 
 
8061
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6828
8062
 
6829
8063
int 
6830
8064
Update_rows_log_event::do_before_row_operations(const Slave_reporting_capability *const)
6832
8066
  if (m_table->s->keys > 0)
6833
8067
  {
6834
8068
    // Allocate buffer for key searches
6835
 
    m_key= (unsigned char*)my_malloc(m_table->key_info->key_length, MYF(MY_WME));
 
8069
    m_key= (uchar*)my_malloc(m_table->key_info->key_length, MYF(MY_WME));
6836
8070
    if (!m_key)
6837
8071
      return HA_ERR_OUT_OF_MEM;
6838
8072
  }
6848
8082
{
6849
8083
  /*error= ToDo:find out what this should really be, this triggers close_scan in nbd, returning error?*/
6850
8084
  m_table->file->ha_index_or_rnd_end();
6851
 
  free(m_key); // Free for multi_malloc
 
8085
  my_free(m_key, MYF(MY_ALLOW_ZERO_PTR)); // Free for multi_malloc
6852
8086
  m_key= NULL;
6853
8087
 
6854
8088
  return error;
6903
8137
  return error;
6904
8138
}
6905
8139
 
6906
 
 
6907
 
Incident_log_event::Incident_log_event(const char *buf, uint32_t event_len,
 
8140
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
 
8141
 
 
8142
#ifdef MYSQL_CLIENT
 
8143
void Update_rows_log_event::print(FILE *file,
 
8144
                                  PRINT_EVENT_INFO* print_event_info)
 
8145
{
 
8146
  Rows_log_event::print_helper(file, print_event_info, "Update_rows");
 
8147
}
 
8148
#endif
 
8149
 
 
8150
 
 
8151
Incident_log_event::Incident_log_event(const char *buf, uint event_len,
6908
8152
                                       const Format_description_log_event *descr_event)
6909
8153
  : Log_event(buf, descr_event)
6910
8154
{
6911
 
  uint8_t const common_header_len=
 
8155
  uint8 const common_header_len=
6912
8156
    descr_event->common_header_len;
6913
 
  uint8_t const post_header_len=
 
8157
  uint8 const post_header_len=
6914
8158
    descr_event->post_header_len[INCIDENT_EVENT-1];
6915
8159
 
6916
8160
  m_incident= static_cast<Incident>(uint2korr(buf + common_header_len));
6917
8161
  char const *ptr= buf + common_header_len + post_header_len;
6918
8162
  char const *const str_end= buf + event_len;
6919
 
  uint8_t len= 0;                   // Assignment to keep compiler happy
 
8163
  uint8 len= 0;                   // Assignment to keep compiler happy
6920
8164
  const char *str= NULL;          // Assignment to keep compiler happy
6921
8165
  read_str(&ptr, str_end, &str, &len);
6922
8166
  m_message.str= const_cast<char*>(str);
6945
8189
}
6946
8190
 
6947
8191
 
 
8192
#ifndef MYSQL_CLIENT
6948
8193
void Incident_log_event::pack_info(Protocol *protocol)
6949
8194
{
6950
8195
  char buf[256];
6957
8202
                    m_incident, description(), m_message.str);
6958
8203
  protocol->store(buf, bytes, &my_charset_bin);
6959
8204
}
6960
 
 
6961
 
 
 
8205
#endif
 
8206
 
 
8207
 
 
8208
#ifdef MYSQL_CLIENT
 
8209
void
 
8210
Incident_log_event::print(FILE *file,
 
8211
                          PRINT_EVENT_INFO *print_event_info)
 
8212
{
 
8213
  if (print_event_info->short_form)
 
8214
    return;
 
8215
 
 
8216
  Write_on_release_cache cache(&print_event_info->head_cache, file);
 
8217
  print_header(&cache, print_event_info, false);
 
8218
  my_b_printf(&cache, "\n# Incident: %s", description());
 
8219
}
 
8220
#endif
 
8221
 
 
8222
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6962
8223
int
6963
8224
Incident_log_event::do_apply_event(Relay_log_info const *rli)
6964
8225
{
6968
8229
              m_message.length > 0 ? m_message.str : "<none>");
6969
8230
  return(1);
6970
8231
}
6971
 
 
 
8232
#endif
6972
8233
 
6973
8234
bool
6974
8235
Incident_log_event::write_data_header(IO_CACHE *file)
6975
8236
{
6976
 
  unsigned char buf[sizeof(int16_t)];
6977
 
  int2store(buf, (int16_t) m_incident);
 
8237
  uchar buf[sizeof(int16)];
 
8238
  int2store(buf, (int16) m_incident);
6978
8239
  return(my_b_safe_write(file, buf, sizeof(buf)));
6979
8240
}
6980
8241
 
6984
8245
  return(write_str(file, m_message.str, m_message.length));
6985
8246
}
6986
8247
 
6987
 
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint32_t event_len,
 
8248
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
 
8249
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint event_len,
6988
8250
                    const Format_description_log_event* description_event)
6989
8251
  :Log_event(buf, description_event)
6990
8252
{
6991
 
  uint8_t header_size= description_event->common_header_len;
 
8253
  uint8 header_size= description_event->common_header_len;
6992
8254
  ident_len = event_len - header_size;
6993
8255
  set_if_smaller(ident_len,FN_REFLEN-1);
6994
8256
  log_ident= buf + header_size;
6995
8257
}
 
8258
#endif
 
8259
 
 
8260
 
 
8261
#ifdef MYSQL_CLIENT
 
8262
/**
 
8263
  The default values for these variables should be values that are
 
8264
  *incorrect*, i.e., values that cannot occur in an event.  This way,
 
8265
  they will always be printed for the first event.
 
8266
*/
 
8267
st_print_event_info::st_print_event_info()
 
8268
  :flags2_inited(0), sql_mode_inited(0),
 
8269
   auto_increment_increment(0),auto_increment_offset(0), charset_inited(0),
 
8270
   lc_time_names_number(~0),
 
8271
   charset_database_number(ILLEGAL_CHARSET_INFO_NUMBER),
 
8272
   thread_id(0), thread_id_printed(false),
 
8273
   base64_output_mode(BASE64_OUTPUT_UNSPEC), printed_fd_event(false)
 
8274
{
 
8275
  /*
 
8276
    Currently we only use static PRINT_EVENT_INFO objects, so zeroed at
 
8277
    program's startup, but these explicit bzero() is for the day someone
 
8278
    creates dynamic instances.
 
8279
  */
 
8280
  bzero(db, sizeof(db));
 
8281
  bzero(charset, sizeof(charset));
 
8282
  bzero(time_zone_str, sizeof(time_zone_str));
 
8283
  delimiter[0]= ';';
 
8284
  delimiter[1]= 0;
 
8285
  myf const flags = MYF(MY_WME | MY_NABP);
 
8286
  open_cached_file(&head_cache, NULL, NULL, 0, flags);
 
8287
  open_cached_file(&body_cache, NULL, NULL, 0, flags);
 
8288
}
 
8289
#endif