~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/log_event.h

  • Committer: Monty Taylor
  • Date: 2008-07-01 14:33:36 UTC
  • mto: (28.1.12 backport_patch)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: monty@inaugust.com-20080701143336-8uihm7dhpu92rt0q
Somehow missed moving password.c. Duh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
/**
21
17
  @addtogroup Replication
29
25
*/
30
26
 
31
27
 
32
 
#ifndef DRIZZLED_LOG_EVENT_H
33
 
#define DRIZZLED_LOG_EVENT_H
34
 
 
35
 
 
36
 
#include <string>
37
 
#include <mysys/my_bitmap.h>
 
28
#ifndef _log_event_h
 
29
#define _log_event_h
 
30
 
 
31
#if defined(USE_PRAGMA_INTERFACE) && !defined(MYSQL_CLIENT)
 
32
#pragma interface                       /* gcc class implementation */
 
33
#endif
 
34
 
 
35
#include <my_bitmap.h>
38
36
#include "rpl_constants.h"
 
37
#ifndef MYSQL_CLIENT
39
38
#include "rpl_record.h"
40
39
#include "rpl_reporting.h"
41
 
 
42
 
#include <drizzled/sql_string.h>       /* append_query_string() needs String declaration */
 
40
#endif
43
41
 
44
42
/**
45
43
   Either assert or return an error.
50
48
   @param COND   Condition to check
51
49
   @param ERRNO  Error number to return in non-debug builds
52
50
*/
53
 
#define ASSERT_OR_RETURN_ERROR(COND, ERRNO) \
54
 
  assert(COND)
 
51
#ifdef DBUG_OFF
 
52
#define ASSERT_OR_RETURN_ERROR(COND, ERRNO) \
 
53
  do { if (!(COND)) return ERRNO; } while (0)
 
54
#else
 
55
#define ASSERT_OR_RETURN_ERROR(COND, ERRNO) \
 
56
  DBUG_ASSERT(COND)
 
57
#endif
55
58
 
56
59
#define LOG_READ_EOF    -1
57
60
#define LOG_READ_BOGUS  -2
155
158
  const char* line_start;
156
159
  const char* escaped;
157
160
  int cached_new_format;
158
 
  uint8_t field_term_len,enclosed_len,line_term_len,line_start_len, escaped_len;
 
161
  uint8 field_term_len,enclosed_len,line_term_len,line_start_len, escaped_len;
159
162
  char opt_flags;
160
163
  char empty_flags;
161
164
 
162
 
  /* store in new format even if old is possible */
 
165
  // store in new format even if old is possible
163
166
  void force_new_format() { cached_new_format = 1;}
164
167
  int data_size()
165
168
  {
209
212
   event's ID, LOG_EVENT_HEADER_LEN will be something like 26, but
210
213
   LOG_EVENT_MINIMAL_HEADER_LEN will remain 19.
211
214
*/
212
 
#define LOG_EVENT_MINIMAL_HEADER_LEN (uint8_t)19
 
215
#define LOG_EVENT_MINIMAL_HEADER_LEN 19
213
216
 
214
217
/* event-specific post-header sizes */
215
218
// where 3.23, 4.x and 5.0 agree
372
375
#define BINLOG_MAGIC        "\xfe\x62\x69\x6e"
373
376
 
374
377
/*
 
378
  The 2 flags below were useless :
 
379
  - the first one was never set
 
380
  - the second one was set in all Rotate events on the master, but not used for
 
381
  anything useful.
 
382
  So they are now removed and their place may later be reused for other
 
383
  flags. Then one must remember that Rotate events in 4.x have
 
384
  LOG_EVENT_FORCED_ROTATE_F set, so one should not rely on the value of the
 
385
  replacing flag when reading a Rotate event.
 
386
  I keep the defines here just to remember what they were.
 
387
*/
 
388
#ifdef TO_BE_REMOVED
 
389
#define LOG_EVENT_TIME_F            0x1
 
390
#define LOG_EVENT_FORCED_ROTATE_F   0x2
 
391
#endif
 
392
 
 
393
/*
375
394
   This flag only makes sense for Format_description_log_event. It is set
376
395
   when the event is written, and *reset* when a binlog file is
377
396
   closed (yes, it's the only case when MySQL modifies already written
398
417
/**
399
418
  @def LOG_EVENT_THREAD_SPECIFIC_F
400
419
 
401
 
  If the query depends on the thread (for example: TEMPORARY Table).
 
420
  If the query depends on the thread (for example: TEMPORARY TABLE).
402
421
  Currently this is used by mysqlbinlog to know it must print
403
422
  SET @@PSEUDO_THREAD_ID=xx; before the query (it would not hurt to print it
404
423
  for every query but this would be slow).
453
472
 
454
473
/* Shouldn't be defined before */
455
474
#define EXPECTED_OPTIONS \
456
 
  ((1U << 14) | (1U << 26) | (1U << 27) | (1U << 19))
 
475
  ((ULL(1) << 14) | (ULL(1) << 26) | (ULL(1) << 27) | (ULL(1) << 19))
457
476
 
458
477
#if OPTIONS_WRITTEN_TO_BIN_LOG != EXPECTED_OPTIONS
459
478
#error OPTIONS_WRITTEN_TO_BIN_LOG must NOT change their values!
545
564
};
546
565
 
547
566
 
 
567
#ifndef MYSQL_CLIENT
548
568
class String;
549
 
class DRIZZLE_BIN_LOG;
 
569
class MYSQL_BIN_LOG;
550
570
class THD;
 
571
#endif
551
572
 
552
573
class Format_description_log_event;
553
574
class Relay_log_info;
554
575
 
 
576
#ifdef MYSQL_CLIENT
 
577
enum enum_base64_output_mode {
 
578
  BASE64_OUTPUT_NEVER= 0,
 
579
  BASE64_OUTPUT_AUTO= 1,
 
580
  BASE64_OUTPUT_ALWAYS= 2,
 
581
  BASE64_OUTPUT_UNSPEC= 3,
 
582
  /* insert new output modes here */
 
583
  BASE64_OUTPUT_MODE_COUNT
 
584
};
 
585
 
 
586
/*
 
587
  A structure for mysqlbinlog to know how to print events
 
588
 
 
589
  This structure is passed to the event's print() methods,
 
590
 
 
591
  There are two types of settings stored here:
 
592
  1. Last db, flags2, sql_mode etc comes from the last printed event.
 
593
     They are stored so that only the necessary USE and SET commands
 
594
     are printed.
 
595
  2. Other information on how to print the events, e.g. short_form,
 
596
     hexdump_from.  These are not dependent on the last event.
 
597
*/
 
598
typedef struct st_print_event_info
 
599
{
 
600
  /*
 
601
    Settings for database, sql_mode etc that comes from the last event
 
602
    that was printed.  We cache these so that we don't have to print
 
603
    them if they are unchanged.
 
604
  */
 
605
  // TODO: have the last catalog here ??
 
606
  char db[FN_REFLEN+1]; // TODO: make this a LEX_STRING when thd->db is
 
607
  bool flags2_inited;
 
608
  uint32 flags2;
 
609
  bool sql_mode_inited;
 
610
  ulong sql_mode;               /* must be same as THD.variables.sql_mode */
 
611
  ulong auto_increment_increment, auto_increment_offset;
 
612
  bool charset_inited;
 
613
  char charset[6]; // 3 variables, each of them storable in 2 bytes
 
614
  char time_zone_str[MAX_TIME_ZONE_NAME_LENGTH];
 
615
  uint lc_time_names_number;
 
616
  uint charset_database_number;
 
617
  uint thread_id;
 
618
  bool thread_id_printed;
 
619
 
 
620
  st_print_event_info();
 
621
 
 
622
  ~st_print_event_info() {
 
623
    close_cached_file(&head_cache);
 
624
    close_cached_file(&body_cache);
 
625
  }
 
626
  bool init_ok() /* tells if construction was successful */
 
627
    { return my_b_inited(&head_cache) && my_b_inited(&body_cache); }
 
628
 
 
629
 
 
630
  /* Settings on how to print the events */
 
631
  bool short_form;
 
632
  enum_base64_output_mode base64_output_mode;
 
633
  /*
 
634
    This is set whenever a Format_description_event is printed.
 
635
    Later, when an event is printed in base64, this flag is tested: if
 
636
    no Format_description_event has been seen, it is unsafe to print
 
637
    the base64 event, so an error message is generated.
 
638
  */
 
639
  bool printed_fd_event;
 
640
  my_off_t hexdump_from;
 
641
  uint8 common_header_len;
 
642
  char delimiter[16];
 
643
 
 
644
  /*
 
645
     These two caches are used by the row-based replication events to
 
646
     collect the header information and the main body of the events
 
647
     making up a statement.
 
648
   */
 
649
  IO_CACHE head_cache;
 
650
  IO_CACHE body_cache;
 
651
} PRINT_EVENT_INFO;
 
652
#endif
 
653
 
555
654
/**
556
655
  the struct aggregates two paramenters that identify an event
557
656
  uniquely in scope of communication of a particular master and slave couple.
744
843
    sees the offset of the BEGIN, which is logical as rollback may
745
844
    occur), except the COMMIT query which has its real offset.
746
845
  */
747
 
  off_t log_pos;
 
846
  my_off_t log_pos;
748
847
  /*
749
848
     A temp buffer for read_log_event; it is later analysed according to the
750
849
     event's type, and its content is distributed in the event-specific fields.
768
867
    The master's server id (is preserved in the relay log; used to
769
868
    prevent from infinite loops in circular replication).
770
869
  */
771
 
  uint32_t server_id;
 
870
  uint32 server_id;
772
871
 
773
872
  /**
774
873
    Some 16 flags. See the definitions above for LOG_EVENT_TIME_F,
775
874
    LOG_EVENT_FORCED_ROTATE_F, LOG_EVENT_THREAD_SPECIFIC_F, and
776
875
    LOG_EVENT_SUPPRESS_USE_F for notes.
777
876
  */
778
 
  uint16_t flags;
 
877
  uint16 flags;
779
878
 
780
879
  bool cache_stmt;
781
880
 
785
884
  */
786
885
  ulong slave_exec_mode;
787
886
 
 
887
#ifndef MYSQL_CLIENT
788
888
  THD* thd;
789
889
 
790
890
  Log_event();
791
 
  Log_event(THD* thd_arg, uint16_t flags_arg, bool cache_stmt);
 
891
  Log_event(THD* thd_arg, uint16 flags_arg, bool cache_stmt);
792
892
  /*
793
893
    read_log_event() functions read an event from a binlog or relay
794
894
    log; used by SHOW BINLOG EVENTS, the binlog_dump thread on the
812
912
    EVENTS.
813
913
  */
814
914
  static void init_show_field_list(List<Item>* field_list);
 
915
#ifdef HAVE_REPLICATION
815
916
  int net_send(Protocol *protocol, const char* log_name, my_off_t pos);
816
917
 
817
918
  /*
821
922
 
822
923
  virtual void pack_info(Protocol *protocol);
823
924
 
 
925
#endif /* HAVE_REPLICATION */
824
926
  virtual const char* get_db()
825
927
  {
826
928
    return thd ? thd->db : 0;
827
929
  }
 
930
#else
 
931
  Log_event() : temp_buf(0) {}
 
932
    /* avoid having to link mysqlbinlog against libpthread */
 
933
  static Log_event* read_log_event(IO_CACHE* file,
 
934
                                   const Format_description_log_event
 
935
                                   *description_event);
 
936
  /* print*() functions are used by mysqlbinlog */
 
937
  virtual void print(FILE* file, PRINT_EVENT_INFO* print_event_info) = 0;
 
938
  void print_timestamp(IO_CACHE* file, time_t *ts = 0);
 
939
  void print_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
 
940
                    bool is_more);
 
941
  void print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
 
942
                    bool is_more);
 
943
#endif
828
944
 
829
945
  static void *operator new(size_t size)
830
946
  {
831
947
    return (void*) my_malloc((uint)size, MYF(MY_WME|MY_FAE));
832
948
  }
833
949
 
834
 
  static void operator delete(void *ptr,
835
 
                              size_t size __attribute__((unused)))
 
950
  static void operator delete(void *ptr, size_t size)
836
951
  {
837
 
    free((unsigned char*) ptr);
 
952
    my_free((uchar*) ptr, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
838
953
  }
839
954
 
840
955
  /* Placement version of the above operators */
841
956
  static void *operator new(size_t, void* ptr) { return ptr; }
842
957
  static void operator delete(void*, void*) { }
843
958
 
 
959
#ifndef MYSQL_CLIENT
844
960
  bool write_header(IO_CACHE* file, ulong data_length);
845
961
  virtual bool write(IO_CACHE* file)
846
962
  {
848
964
            write_data_header(file) ||
849
965
            write_data_body(file));
850
966
  }
851
 
  virtual bool write_data_header(IO_CACHE* file __attribute__((unused)))
 
967
  virtual bool write_data_header(IO_CACHE* file)
852
968
  { return 0; }
853
969
  virtual bool write_data_body(IO_CACHE* file __attribute__((unused)))
854
970
  { return 0; }
863
979
      return tmp_thd->start_time;
864
980
    return my_time(0);
865
981
  }
 
982
#endif
866
983
  virtual Log_event_type get_type_code() = 0;
867
984
  virtual bool is_valid() const = 0;
868
985
  virtual bool is_artificial_event() { return 0; }
875
992
  {
876
993
    if (temp_buf)
877
994
    {
878
 
      free(temp_buf);
 
995
      my_free(temp_buf, MYF(0));
879
996
      temp_buf = 0;
880
997
    }
881
998
  }
884
1001
    is calculated during write()
885
1002
  */
886
1003
  virtual int get_data_size() { return 0;}
887
 
  static Log_event* read_log_event(const char* buf, uint32_t event_len,
 
1004
  static Log_event* read_log_event(const char* buf, uint event_len,
888
1005
                                   const char **error,
889
1006
                                   const Format_description_log_event
890
1007
                                   *description_event);
899
1016
 
900
1017
  /* Return start of query time or current time */
901
1018
 
 
1019
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
902
1020
public:
903
1021
 
904
1022
  /**
975
1093
    @retval 0     Event applied successfully
976
1094
    @retval errno Error code if event application failed
977
1095
  */
978
 
  virtual int do_apply_event(Relay_log_info const *rli __attribute__((unused)))
 
1096
  virtual int do_apply_event(Relay_log_info const *rli)
979
1097
  {
980
1098
    return 0;                /* Default implementation does nothing */
981
1099
  }
1037
1155
     non-zero. The caller shall decrease the counter by one.
1038
1156
   */
1039
1157
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
1158
#endif
1040
1159
};
1041
1160
 
1042
1161
 
1387
1506
    we pass it with q_len, so we would not have to call strlen()
1388
1507
    otherwise, set it to 0, in which case, we compute it with strlen()
1389
1508
  */
1390
 
  uint32_t q_len;
1391
 
  uint32_t db_len;
1392
 
  uint16_t error_code;
 
1509
  uint32 q_len;
 
1510
  uint32 db_len;
 
1511
  uint16 error_code;
1393
1512
  ulong thread_id;
1394
1513
  /*
1395
1514
    For events created by Query_log_event::do_apply_event (and
1404
1523
    concerned) from here.
1405
1524
  */
1406
1525
 
1407
 
  uint32_t catalog_len;                 // <= 255 char; 0 means uninited
 
1526
  uint catalog_len;                     // <= 255 char; 0 means uninited
1408
1527
 
1409
1528
  /*
1410
1529
    We want to be able to store a variable number of N-bit status vars:
1426
1545
    Query_log_event, so automatically benefit from the work already done for
1427
1546
    status variables in Query_log_event.
1428
1547
 */
1429
 
  uint16_t status_vars_len;
 
1548
  uint16 status_vars_len;
1430
1549
 
1431
1550
  /*
1432
1551
    'flags2' is a second set of flags (on top of those in Log_event), for
1441
1560
  bool sql_mode_inited;
1442
1561
  bool charset_inited;
1443
1562
 
1444
 
  uint32_t flags2;
 
1563
  uint32 flags2;
1445
1564
  /* In connections sql_mode is 32 bits now but will be 64 bits soon */
1446
1565
  ulong sql_mode;
1447
1566
  ulong auto_increment_increment, auto_increment_offset;
1448
1567
  char charset[6];
1449
 
  uint32_t time_zone_len; /* 0 means uninited */
 
1568
  uint time_zone_len; /* 0 means uninited */
1450
1569
  const char *time_zone_str;
1451
 
  uint32_t lc_time_names_number; /* 0 means en_US */
1452
 
  uint32_t charset_database_number;
 
1570
  uint lc_time_names_number; /* 0 means en_US */
 
1571
  uint charset_database_number;
1453
1572
 
 
1573
#ifndef MYSQL_CLIENT
1454
1574
 
1455
1575
  Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length,
1456
1576
                  bool using_trans, bool suppress_use,
1457
1577
                  THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
1458
1578
  const char* get_db() { return db; }
 
1579
#ifdef HAVE_REPLICATION
1459
1580
  void pack_info(Protocol* protocol);
 
1581
#endif /* HAVE_REPLICATION */
 
1582
#else
 
1583
  void print_query_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info);
 
1584
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
1585
#endif
1460
1586
 
1461
1587
  Query_log_event();
1462
 
  Query_log_event(const char* buf, uint32_t event_len,
 
1588
  Query_log_event(const char* buf, uint event_len,
1463
1589
                  const Format_description_log_event *description_event,
1464
1590
                  Log_event_type event_type);
1465
1591
  ~Query_log_event()
1466
1592
  {
1467
1593
    if (data_buf)
1468
 
      free((unsigned char*) data_buf);
 
1594
      my_free((uchar*) data_buf, MYF(0));
1469
1595
  }
1470
1596
  Log_event_type get_type_code() { return QUERY_EVENT; }
 
1597
#ifndef MYSQL_CLIENT
1471
1598
  bool write(IO_CACHE* file);
1472
 
  virtual bool write_post_header_for_derived(IO_CACHE* file __attribute__((unused)))
1473
 
  { return false; }
 
1599
  virtual bool write_post_header_for_derived(IO_CACHE* file) { return FALSE; }
 
1600
#endif
1474
1601
  bool is_valid() const { return query != 0; }
1475
1602
 
1476
1603
  /*
1481
1608
  /* Writes derived event-specific part of post header. */
1482
1609
 
1483
1610
public:        /* !!! Public in this patch to allow old usage */
 
1611
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1484
1612
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
1485
1613
  virtual int do_apply_event(Relay_log_info const *rli);
1486
1614
  virtual int do_update_pos(Relay_log_info *rli);
1487
1615
 
1488
1616
  int do_apply_event(Relay_log_info const *rli,
1489
1617
                       const char *query_arg,
1490
 
                       uint32_t q_len_arg);
 
1618
                       uint32 q_len_arg);
 
1619
#endif /* HAVE_REPLICATION */
1491
1620
};
1492
1621
 
1493
1622
 
 
1623
#ifdef HAVE_REPLICATION
 
1624
 
1494
1625
/**
1495
1626
  @class Slave_log_event
1496
1627
 
1539
1670
  </tr>
1540
1671
  </table>
1541
1672
*/
1542
 
 
1543
1673
class Slave_log_event: public Log_event
1544
1674
{
1545
1675
protected:
1546
1676
  char* mem_pool;
1547
 
  void init_from_mem_pool();
 
1677
  void init_from_mem_pool(int data_size);
1548
1678
public:
1549
 
  off_t master_pos;
1550
 
  std::string master_host;
1551
 
  std::string master_log;
1552
 
  uint16_t master_port;
 
1679
  my_off_t master_pos;
 
1680
  char* master_host;
 
1681
  char* master_log;
 
1682
  int master_host_len;
 
1683
  int master_log_len;
 
1684
  uint16 master_port;
1553
1685
 
 
1686
#ifndef MYSQL_CLIENT
1554
1687
  Slave_log_event(THD* thd_arg, Relay_log_info* rli);
1555
1688
  void pack_info(Protocol* protocol);
 
1689
#else
 
1690
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
1691
#endif
1556
1692
 
1557
 
  Slave_log_event(const char* buf, uint32_t event_len);
 
1693
  Slave_log_event(const char* buf, uint event_len);
1558
1694
  ~Slave_log_event();
1559
1695
  int get_data_size();
1560
 
  bool is_valid() const { return master_host.length() != 0; }
 
1696
  bool is_valid() const { return master_host != 0; }
1561
1697
  Log_event_type get_type_code() { return SLAVE_EVENT; }
 
1698
#ifndef MYSQL_CLIENT
1562
1699
  bool write(IO_CACHE* file);
 
1700
#endif
1563
1701
 
1564
1702
private:
 
1703
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1565
1704
  virtual int do_apply_event(Relay_log_info const* rli);
 
1705
#endif
1566
1706
};
1567
1707
 
 
1708
#endif /* HAVE_REPLICATION */
 
1709
 
1568
1710
 
1569
1711
/**
1570
1712
  @class Load_log_event
1576
1718
   (1)    USE db;
1577
1719
   (2)    LOAD DATA [LOCAL] INFILE 'file_name'
1578
1720
   (3)    [REPLACE | IGNORE]
1579
 
   (4)    INTO Table 'table_name'
 
1721
   (4)    INTO TABLE 'table_name'
1580
1722
   (5)    [FIELDS
1581
1723
   (6)      [TERMINATED BY 'field_term']
1582
1724
   (7)      [[OPTIONALLY] ENCLOSED BY 'enclosed']
1768
1910
class Load_log_event: public Log_event
1769
1911
{
1770
1912
private:
1771
 
  uint32_t get_query_buffer_length();
 
1913
  uint get_query_buffer_length();
1772
1914
  void print_query(bool need_db, char *buf, char **end,
1773
1915
                   char **fn_start, char **fn_end);
1774
1916
protected:
1779
1921
public:
1780
1922
  ulong thread_id;
1781
1923
  ulong slave_proxy_id;
1782
 
  uint32_t table_name_len;
 
1924
  uint32 table_name_len;
1783
1925
  /*
1784
1926
    No need to have a catalog, as these events can only come from 4.x.
1785
1927
    TODO: this may become false if Dmitri pushes his new LOAD DATA INFILE in
1786
1928
    5.0 only (not in 4.x).
1787
1929
  */
1788
 
  uint32_t db_len;
1789
 
  uint32_t fname_len;
1790
 
  uint32_t num_fields;
 
1930
  uint32 db_len;
 
1931
  uint32 fname_len;
 
1932
  uint32 num_fields;
1791
1933
  const char* fields;
1792
 
  const unsigned char* field_lens;
1793
 
  uint32_t field_block_len;
 
1934
  const uchar* field_lens;
 
1935
  uint32 field_block_len;
1794
1936
 
1795
1937
  const char* table_name;
1796
1938
  const char* db;
1797
1939
  const char* fname;
1798
 
  uint32_t skip_lines;
 
1940
  uint32 skip_lines;
1799
1941
  sql_ex_info sql_ex;
1800
1942
  bool local_fname;
1801
1943
 
1802
1944
  /* fname doesn't point to memory inside Log_event::temp_buf  */
1803
 
  void set_fname_outside_temp_buf(const char *afname, uint32_t alen)
 
1945
  void set_fname_outside_temp_buf(const char *afname, uint alen)
1804
1946
  {
1805
1947
    fname= afname;
1806
1948
    fname_len= alen;
1807
 
    local_fname= true;
 
1949
    local_fname= TRUE;
1808
1950
  }
1809
1951
  /* fname doesn't point to memory inside Log_event::temp_buf  */
1810
1952
  int  check_fname_outside_temp_buf()
1812
1954
    return local_fname;
1813
1955
  }
1814
1956
 
 
1957
#ifndef MYSQL_CLIENT
1815
1958
  String field_lens_buf;
1816
1959
  String fields_buf;
1817
1960
 
1822
1965
  void set_fields(const char* db, List<Item> &fields_arg,
1823
1966
                  Name_resolution_context *context);
1824
1967
  const char* get_db() { return db; }
 
1968
#ifdef HAVE_REPLICATION
1825
1969
  void pack_info(Protocol* protocol);
 
1970
#endif /* HAVE_REPLICATION */
 
1971
#else
 
1972
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
1973
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info, bool commented);
 
1974
#endif
1826
1975
 
1827
1976
  /*
1828
1977
    Note that for all the events related to LOAD DATA (Load_log_event,
1830
1979
    logging of LOAD DATA is going to be changed in 4.1 or 5.0, this is only used
1831
1980
    for the common_header_len (post_header_len will not be changed).
1832
1981
  */
1833
 
  Load_log_event(const char* buf, uint32_t event_len,
 
1982
  Load_log_event(const char* buf, uint event_len,
1834
1983
                 const Format_description_log_event* description_event);
1835
1984
  ~Load_log_event()
1836
1985
  {}
1838
1987
  {
1839
1988
    return sql_ex.new_format() ? NEW_LOAD_EVENT: LOAD_EVENT;
1840
1989
  }
 
1990
#ifndef MYSQL_CLIENT
1841
1991
  bool write_data_header(IO_CACHE* file);
1842
1992
  bool write_data_body(IO_CACHE* file);
 
1993
#endif
1843
1994
  bool is_valid() const { return table_name != 0; }
1844
1995
  int get_data_size()
1845
1996
  {
1849
2000
  }
1850
2001
 
1851
2002
public:        /* !!! Public in this patch to allow old usage */
 
2003
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1852
2004
  virtual int do_apply_event(Relay_log_info const* rli)
1853
2005
  {
1854
2006
    return do_apply_event(thd->slave_net,rli,0);
1856
2008
 
1857
2009
  int do_apply_event(NET *net, Relay_log_info const *rli,
1858
2010
                     bool use_rli_only_for_errors);
 
2011
#endif
1859
2012
};
1860
2013
 
1861
2014
extern char server_version[SERVER_VERSION_LENGTH];
1901
2054
     fixed.
1902
2055
  */
1903
2056
  time_t created;
1904
 
  uint16_t binlog_version;
 
2057
  uint16 binlog_version;
1905
2058
  char server_version[ST_SERVER_VER_LEN];
1906
2059
  /*
1907
2060
    artifical_event is 1 in the case where this is a generated event that
1915
2068
  */
1916
2069
  bool dont_set_created;
1917
2070
 
 
2071
#ifndef MYSQL_CLIENT
1918
2072
  Start_log_event_v3();
 
2073
#ifdef HAVE_REPLICATION
1919
2074
  void pack_info(Protocol* protocol);
 
2075
#endif /* HAVE_REPLICATION */
 
2076
#else
 
2077
  Start_log_event_v3() {}
 
2078
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2079
#endif
1920
2080
 
1921
2081
  Start_log_event_v3(const char* buf,
1922
2082
                     const Format_description_log_event* description_event);
1923
2083
  ~Start_log_event_v3() {}
1924
2084
  Log_event_type get_type_code() { return START_EVENT_V3;}
 
2085
#ifndef MYSQL_CLIENT
1925
2086
  bool write(IO_CACHE* file);
 
2087
#endif
1926
2088
  bool is_valid() const { return 1; }
1927
2089
  int get_data_size()
1928
2090
  {
1931
2093
  virtual bool is_artificial_event() { return artificial_event; }
1932
2094
 
1933
2095
protected:
 
2096
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1934
2097
  virtual int do_apply_event(Relay_log_info const *rli);
1935
2098
  virtual enum_skip_reason do_shall_skip(Relay_log_info*)
1936
2099
  {
1943
2106
    else
1944
2107
      return Log_event::EVENT_SKIP_NOT;
1945
2108
  }
 
2109
#endif
1946
2110
};
1947
2111
 
1948
2112
 
1965
2129
     LOG_EVENT_HEADER_LEN), except FORMAT_DESCRIPTION_EVENT and ROTATE_EVENT
1966
2130
     (those have a header of size LOG_EVENT_MINIMAL_HEADER_LEN).
1967
2131
  */
1968
 
  uint8_t common_header_len;
1969
 
  uint8_t number_of_event_types;
 
2132
  uint8 common_header_len;
 
2133
  uint8 number_of_event_types;
1970
2134
  /* The list of post-headers' lengthes */
1971
 
  uint8_t *post_header_len;
1972
 
  unsigned char server_version_split[3];
1973
 
  const uint8_t *event_type_permutation;
 
2135
  uint8 *post_header_len;
 
2136
  uchar server_version_split[3];
 
2137
  const uint8 *event_type_permutation;
1974
2138
 
1975
 
  Format_description_log_event(uint8_t binlog_ver, const char* server_ver=0);
1976
 
  Format_description_log_event(const char* buf, uint32_t event_len,
 
2139
  Format_description_log_event(uint8 binlog_ver, const char* server_ver=0);
 
2140
  Format_description_log_event(const char* buf, uint event_len,
1977
2141
                               const Format_description_log_event
1978
2142
                               *description_event);
1979
2143
  ~Format_description_log_event()
1980
2144
  {
1981
 
    free((unsigned char*)post_header_len);
 
2145
    my_free((uchar*)post_header_len, MYF(MY_ALLOW_ZERO_PTR));
1982
2146
  }
1983
2147
  Log_event_type get_type_code() { return FORMAT_DESCRIPTION_EVENT;}
 
2148
#ifndef MYSQL_CLIENT
1984
2149
  bool write(IO_CACHE* file);
 
2150
#endif
1985
2151
  bool is_valid() const
1986
2152
  {
1987
2153
    return ((common_header_len >= ((binlog_version==1) ? OLD_HEADER_LEN :
2001
2167
  void calc_server_version_split();
2002
2168
 
2003
2169
protected:
 
2170
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2004
2171
  virtual int do_apply_event(Relay_log_info const *rli);
2005
2172
  virtual int do_update_pos(Relay_log_info *rli);
2006
2173
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2174
#endif
2007
2175
};
2008
2176
 
2009
2177
 
2047
2215
class Intvar_log_event: public Log_event
2048
2216
{
2049
2217
public:
2050
 
  uint64_t val;
2051
 
  unsigned char type;
 
2218
  ulonglong val;
 
2219
  uchar type;
2052
2220
 
2053
 
  Intvar_log_event(THD* thd_arg,unsigned char type_arg, uint64_t val_arg)
 
2221
#ifndef MYSQL_CLIENT
 
2222
  Intvar_log_event(THD* thd_arg,uchar type_arg, ulonglong val_arg)
2054
2223
    :Log_event(thd_arg,0,0),val(val_arg),type(type_arg)
2055
2224
  {}
 
2225
#ifdef HAVE_REPLICATION
2056
2226
  void pack_info(Protocol* protocol);
 
2227
#endif /* HAVE_REPLICATION */
 
2228
#else
 
2229
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2230
#endif
2057
2231
 
2058
2232
  Intvar_log_event(const char* buf,
2059
2233
                   const Format_description_log_event *description_event);
2061
2235
  Log_event_type get_type_code() { return INTVAR_EVENT;}
2062
2236
  const char* get_var_type_name();
2063
2237
  int get_data_size() { return  9; /* sizeof(type) + sizeof(val) */;}
 
2238
#ifndef MYSQL_CLIENT
2064
2239
  bool write(IO_CACHE* file);
 
2240
#endif
2065
2241
  bool is_valid() const { return 1; }
2066
2242
 
2067
2243
private:
 
2244
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2068
2245
  virtual int do_apply_event(Relay_log_info const *rli);
2069
2246
  virtual int do_update_pos(Relay_log_info *rli);
2070
2247
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2248
#endif
2071
2249
};
2072
2250
 
2073
2251
 
2112
2290
class Rand_log_event: public Log_event
2113
2291
{
2114
2292
 public:
2115
 
  uint64_t seed1;
2116
 
  uint64_t seed2;
 
2293
  ulonglong seed1;
 
2294
  ulonglong seed2;
2117
2295
 
2118
 
  Rand_log_event(THD* thd_arg, uint64_t seed1_arg, uint64_t seed2_arg)
 
2296
#ifndef MYSQL_CLIENT
 
2297
  Rand_log_event(THD* thd_arg, ulonglong seed1_arg, ulonglong seed2_arg)
2119
2298
    :Log_event(thd_arg,0,0),seed1(seed1_arg),seed2(seed2_arg)
2120
2299
  {}
 
2300
#ifdef HAVE_REPLICATION
2121
2301
  void pack_info(Protocol* protocol);
 
2302
#endif /* HAVE_REPLICATION */
 
2303
#else
 
2304
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2305
#endif
2122
2306
 
2123
2307
  Rand_log_event(const char* buf,
2124
2308
                 const Format_description_log_event *description_event);
2125
2309
  ~Rand_log_event() {}
2126
2310
  Log_event_type get_type_code() { return RAND_EVENT;}
2127
 
  int get_data_size() { return 16; /* sizeof(uint64_t) * 2*/ }
 
2311
  int get_data_size() { return 16; /* sizeof(ulonglong) * 2*/ }
 
2312
#ifndef MYSQL_CLIENT
2128
2313
  bool write(IO_CACHE* file);
 
2314
#endif
2129
2315
  bool is_valid() const { return 1; }
2130
2316
 
2131
2317
private:
 
2318
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2132
2319
  virtual int do_apply_event(Relay_log_info const *rli);
2133
2320
  virtual int do_update_pos(Relay_log_info *rli);
2134
2321
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2322
#endif
2135
2323
};
2136
2324
 
2137
2325
/**
2142
2330
 
2143
2331
  @section Xid_log_event_binary_format Binary Format  
2144
2332
*/
 
2333
#ifdef MYSQL_CLIENT
 
2334
typedef ulonglong my_xid; // this line is the same as in handler.h
 
2335
#endif
 
2336
 
2145
2337
class Xid_log_event: public Log_event
2146
2338
{
2147
2339
 public:
2148
2340
   my_xid xid;
2149
2341
 
 
2342
#ifndef MYSQL_CLIENT
2150
2343
  Xid_log_event(THD* thd_arg, my_xid x): Log_event(thd_arg,0,0), xid(x) {}
 
2344
#ifdef HAVE_REPLICATION
2151
2345
  void pack_info(Protocol* protocol);
 
2346
#endif /* HAVE_REPLICATION */
 
2347
#else
 
2348
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2349
#endif
2152
2350
 
2153
2351
  Xid_log_event(const char* buf,
2154
2352
                const Format_description_log_event *description_event);
2155
2353
  ~Xid_log_event() {}
2156
2354
  Log_event_type get_type_code() { return XID_EVENT;}
2157
2355
  int get_data_size() { return sizeof(xid); }
 
2356
#ifndef MYSQL_CLIENT
2158
2357
  bool write(IO_CACHE* file);
 
2358
#endif
2159
2359
  bool is_valid() const { return 1; }
2160
2360
 
2161
2361
private:
 
2362
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2162
2363
  virtual int do_apply_event(Relay_log_info const *rli);
2163
2364
  enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2365
#endif
2164
2366
};
2165
2367
 
2166
2368
/**
2176
2378
{
2177
2379
public:
2178
2380
  char *name;
2179
 
  uint32_t name_len;
 
2381
  uint name_len;
2180
2382
  char *val;
2181
2383
  ulong val_len;
2182
2384
  Item_result type;
2183
 
  uint32_t charset_number;
 
2385
  uint charset_number;
2184
2386
  bool is_null;
2185
 
  User_var_log_event(THD* thd_arg __attribute__((unused)),
2186
 
                     char *name_arg, uint32_t name_len_arg,
 
2387
#ifndef MYSQL_CLIENT
 
2388
  User_var_log_event(THD* thd_arg, char *name_arg, uint name_len_arg,
2187
2389
                     char *val_arg, ulong val_len_arg, Item_result type_arg,
2188
 
                     uint32_t charset_number_arg)
 
2390
                     uint charset_number_arg)
2189
2391
    :Log_event(), name(name_arg), name_len(name_len_arg), val(val_arg),
2190
2392
    val_len(val_len_arg), type(type_arg), charset_number(charset_number_arg)
2191
2393
    { is_null= !val; }
2192
2394
  void pack_info(Protocol* protocol);
 
2395
#else
 
2396
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2397
#endif
2193
2398
 
2194
2399
  User_var_log_event(const char* buf,
2195
2400
                     const Format_description_log_event *description_event);
2196
2401
  ~User_var_log_event() {}
2197
2402
  Log_event_type get_type_code() { return USER_VAR_EVENT;}
 
2403
#ifndef MYSQL_CLIENT
2198
2404
  bool write(IO_CACHE* file);
 
2405
#endif
2199
2406
  bool is_valid() const { return 1; }
2200
2407
 
2201
2408
private:
 
2409
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2202
2410
  virtual int do_apply_event(Relay_log_info const *rli);
2203
2411
  virtual int do_update_pos(Relay_log_info *rli);
2204
2412
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2413
#endif
2205
2414
};
2206
2415
 
2207
2416
 
2216
2425
class Stop_log_event: public Log_event
2217
2426
{
2218
2427
public:
 
2428
#ifndef MYSQL_CLIENT
2219
2429
  Stop_log_event() :Log_event()
2220
2430
  {}
 
2431
#else
 
2432
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2433
#endif
2221
2434
 
2222
2435
  Stop_log_event(const char* buf,
2223
2436
                 const Format_description_log_event *description_event):
2228
2441
  bool is_valid() const { return 1; }
2229
2442
 
2230
2443
private:
 
2444
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2231
2445
  virtual int do_update_pos(Relay_log_info *rli);
2232
 
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli __attribute__((unused)))
 
2446
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli)
2233
2447
  {
2234
2448
    /*
2235
2449
      Events from ourself should be skipped, but they should not
2240
2454
    else
2241
2455
      return Log_event::EVENT_SKIP_NOT;
2242
2456
  }
 
2457
#endif
2243
2458
};
2244
2459
 
2245
2460
/**
2298
2513
    DUP_NAME= 2 // if constructor should dup the string argument
2299
2514
  };
2300
2515
  const char* new_log_ident;
2301
 
  uint64_t pos;
2302
 
  uint32_t ident_len;
2303
 
  uint32_t flags;
 
2516
  ulonglong pos;
 
2517
  uint ident_len;
 
2518
  uint flags;
 
2519
#ifndef MYSQL_CLIENT
2304
2520
  Rotate_log_event(const char* new_log_ident_arg,
2305
 
                   uint32_t ident_len_arg,
2306
 
                   uint64_t pos_arg, uint32_t flags);
 
2521
                   uint ident_len_arg,
 
2522
                   ulonglong pos_arg, uint flags);
 
2523
#ifdef HAVE_REPLICATION
2307
2524
  void pack_info(Protocol* protocol);
 
2525
#endif /* HAVE_REPLICATION */
 
2526
#else
 
2527
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2528
#endif
2308
2529
 
2309
 
  Rotate_log_event(const char* buf, uint32_t event_len,
 
2530
  Rotate_log_event(const char* buf, uint event_len,
2310
2531
                   const Format_description_log_event* description_event);
2311
2532
  ~Rotate_log_event()
2312
2533
  {
2313
2534
    if (flags & DUP_NAME)
2314
 
      free((unsigned char*) new_log_ident);
 
2535
      my_free((uchar*) new_log_ident, MYF(MY_ALLOW_ZERO_PTR));
2315
2536
  }
2316
2537
  Log_event_type get_type_code() { return ROTATE_EVENT;}
2317
2538
  int get_data_size() { return  ident_len + ROTATE_HEADER_LEN;}
2318
2539
  bool is_valid() const { return new_log_ident != 0; }
 
2540
#ifndef MYSQL_CLIENT
2319
2541
  bool write(IO_CACHE* file);
 
2542
#endif
2320
2543
 
2321
2544
private:
 
2545
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2322
2546
  virtual int do_update_pos(Relay_log_info *rli);
2323
2547
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2548
#endif
2324
2549
};
2325
2550
 
2326
2551
 
2342
2567
  */
2343
2568
  bool fake_base;
2344
2569
public:
2345
 
  unsigned char* block;
 
2570
  uchar* block;
2346
2571
  const char *event_buf;
2347
 
  uint32_t block_len;
2348
 
  uint32_t file_id;
 
2572
  uint block_len;
 
2573
  uint file_id;
2349
2574
  bool inited_from_old;
2350
2575
 
 
2576
#ifndef MYSQL_CLIENT
2351
2577
  Create_file_log_event(THD* thd, sql_exchange* ex, const char* db_arg,
2352
2578
                        const char* table_name_arg,
2353
2579
                        List<Item>& fields_arg,
2354
2580
                        enum enum_duplicates handle_dup, bool ignore,
2355
 
                        unsigned char* block_arg, uint32_t block_len_arg,
 
2581
                        uchar* block_arg, uint block_len_arg,
2356
2582
                        bool using_trans);
 
2583
#ifdef HAVE_REPLICATION
2357
2584
  void pack_info(Protocol* protocol);
 
2585
#endif /* HAVE_REPLICATION */
 
2586
#else
 
2587
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2588
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
 
2589
             bool enable_local);
 
2590
#endif
2358
2591
 
2359
 
  Create_file_log_event(const char* buf, uint32_t event_len,
 
2592
  Create_file_log_event(const char* buf, uint event_len,
2360
2593
                        const Format_description_log_event* description_event);
2361
2594
  ~Create_file_log_event()
2362
2595
  {
2363
 
    free((char*) event_buf);
 
2596
    my_free((char*) event_buf, MYF(MY_ALLOW_ZERO_PTR));
2364
2597
  }
2365
2598
 
2366
2599
  Log_event_type get_type_code()
2374
2607
            4 + 1 + block_len);
2375
2608
  }
2376
2609
  bool is_valid() const { return inited_from_old || block != 0; }
 
2610
#ifndef MYSQL_CLIENT
2377
2611
  bool write_data_header(IO_CACHE* file);
2378
2612
  bool write_data_body(IO_CACHE* file);
2379
2613
  /*
2381
2615
    write it as Load event - used on the slave
2382
2616
  */
2383
2617
  bool write_base(IO_CACHE* file);
 
2618
#endif
2384
2619
 
2385
2620
private:
 
2621
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2386
2622
  virtual int do_apply_event(Relay_log_info const *rli);
 
2623
#endif
2387
2624
};
2388
2625
 
2389
2626
 
2396
2633
class Append_block_log_event: public Log_event
2397
2634
{
2398
2635
public:
2399
 
  unsigned char* block;
2400
 
  uint32_t block_len;
2401
 
  uint32_t file_id;
 
2636
  uchar* block;
 
2637
  uint block_len;
 
2638
  uint file_id;
2402
2639
  /*
2403
2640
    'db' is filled when the event is created in mysql_load() (the
2404
2641
    event needs to have a 'db' member to be well filtered by
2412
2649
  */
2413
2650
  const char* db;
2414
2651
 
2415
 
  Append_block_log_event(THD* thd, const char* db_arg, unsigned char* block_arg,
2416
 
                         uint32_t block_len_arg, bool using_trans);
 
2652
#ifndef MYSQL_CLIENT
 
2653
  Append_block_log_event(THD* thd, const char* db_arg, uchar* block_arg,
 
2654
                         uint block_len_arg, bool using_trans);
 
2655
#ifdef HAVE_REPLICATION
2417
2656
  void pack_info(Protocol* protocol);
2418
2657
  virtual int get_create_or_append() const;
 
2658
#endif /* HAVE_REPLICATION */
 
2659
#else
 
2660
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2661
#endif
2419
2662
 
2420
 
  Append_block_log_event(const char* buf, uint32_t event_len,
 
2663
  Append_block_log_event(const char* buf, uint event_len,
2421
2664
                         const Format_description_log_event
2422
2665
                         *description_event);
2423
2666
  ~Append_block_log_event() {}
2424
2667
  Log_event_type get_type_code() { return APPEND_BLOCK_EVENT;}
2425
2668
  int get_data_size() { return  block_len + APPEND_BLOCK_HEADER_LEN ;}
2426
2669
  bool is_valid() const { return block != 0; }
 
2670
#ifndef MYSQL_CLIENT
2427
2671
  bool write(IO_CACHE* file);
2428
2672
  const char* get_db() { return db; }
 
2673
#endif
2429
2674
 
2430
2675
private:
 
2676
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2431
2677
  virtual int do_apply_event(Relay_log_info const *rli);
 
2678
#endif
2432
2679
};
2433
2680
 
2434
2681
 
2441
2688
class Delete_file_log_event: public Log_event
2442
2689
{
2443
2690
public:
2444
 
  uint32_t file_id;
 
2691
  uint file_id;
2445
2692
  const char* db; /* see comment in Append_block_log_event */
2446
2693
 
 
2694
#ifndef MYSQL_CLIENT
2447
2695
  Delete_file_log_event(THD* thd, const char* db_arg, bool using_trans);
 
2696
#ifdef HAVE_REPLICATION
2448
2697
  void pack_info(Protocol* protocol);
 
2698
#endif /* HAVE_REPLICATION */
 
2699
#else
 
2700
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2701
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
 
2702
             bool enable_local);
 
2703
#endif
2449
2704
 
2450
 
  Delete_file_log_event(const char* buf, uint32_t event_len,
 
2705
  Delete_file_log_event(const char* buf, uint event_len,
2451
2706
                        const Format_description_log_event* description_event);
2452
2707
  ~Delete_file_log_event() {}
2453
2708
  Log_event_type get_type_code() { return DELETE_FILE_EVENT;}
2454
2709
  int get_data_size() { return DELETE_FILE_HEADER_LEN ;}
2455
2710
  bool is_valid() const { return file_id != 0; }
 
2711
#ifndef MYSQL_CLIENT
2456
2712
  bool write(IO_CACHE* file);
2457
2713
  const char* get_db() { return db; }
 
2714
#endif
2458
2715
 
2459
2716
private:
 
2717
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2460
2718
  virtual int do_apply_event(Relay_log_info const *rli);
 
2719
#endif
2461
2720
};
2462
2721
 
2463
2722
 
2470
2729
class Execute_load_log_event: public Log_event
2471
2730
{
2472
2731
public:
2473
 
  uint32_t file_id;
 
2732
  uint file_id;
2474
2733
  const char* db; /* see comment in Append_block_log_event */
2475
2734
 
 
2735
#ifndef MYSQL_CLIENT
2476
2736
  Execute_load_log_event(THD* thd, const char* db_arg, bool using_trans);
 
2737
#ifdef HAVE_REPLICATION
2477
2738
  void pack_info(Protocol* protocol);
 
2739
#endif /* HAVE_REPLICATION */
 
2740
#else
 
2741
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2742
#endif
2478
2743
 
2479
 
  Execute_load_log_event(const char* buf, uint32_t event_len,
 
2744
  Execute_load_log_event(const char* buf, uint event_len,
2480
2745
                         const Format_description_log_event
2481
2746
                         *description_event);
2482
2747
  ~Execute_load_log_event() {}
2483
2748
  Log_event_type get_type_code() { return EXEC_LOAD_EVENT;}
2484
2749
  int get_data_size() { return  EXEC_LOAD_HEADER_LEN ;}
2485
2750
  bool is_valid() const { return file_id != 0; }
 
2751
#ifndef MYSQL_CLIENT
2486
2752
  bool write(IO_CACHE* file);
2487
2753
  const char* get_db() { return db; }
 
2754
#endif
2488
2755
 
2489
2756
private:
 
2757
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2490
2758
  virtual int do_apply_event(Relay_log_info const *rli);
 
2759
#endif
2491
2760
};
2492
2761
 
2493
2762
 
2503
2772
class Begin_load_query_log_event: public Append_block_log_event
2504
2773
{
2505
2774
public:
 
2775
#ifndef MYSQL_CLIENT
2506
2776
  Begin_load_query_log_event(THD* thd_arg, const char *db_arg,
2507
 
                             unsigned char* block_arg, uint32_t block_len_arg,
 
2777
                             uchar* block_arg, uint block_len_arg,
2508
2778
                             bool using_trans);
 
2779
#ifdef HAVE_REPLICATION
2509
2780
  Begin_load_query_log_event(THD* thd);
2510
2781
  int get_create_or_append() const;
2511
 
  Begin_load_query_log_event(const char* buf, uint32_t event_len,
 
2782
#endif /* HAVE_REPLICATION */
 
2783
#endif
 
2784
  Begin_load_query_log_event(const char* buf, uint event_len,
2512
2785
                             const Format_description_log_event
2513
2786
                             *description_event);
2514
2787
  ~Begin_load_query_log_event() {}
2515
2788
  Log_event_type get_type_code() { return BEGIN_LOAD_QUERY_EVENT; }
2516
2789
private:
 
2790
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2517
2791
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2792
#endif
2518
2793
};
2519
2794
 
2520
2795
 
2536
2811
class Execute_load_query_log_event: public Query_log_event
2537
2812
{
2538
2813
public:
2539
 
  uint32_t file_id;       // file_id of temporary file
2540
 
  uint32_t fn_pos_start;  // pointer to the part of the query that should
 
2814
  uint file_id;       // file_id of temporary file
 
2815
  uint fn_pos_start;  // pointer to the part of the query that should
2541
2816
                      // be substituted
2542
 
  uint32_t fn_pos_end;    // pointer to the end of this part of query
 
2817
  uint fn_pos_end;    // pointer to the end of this part of query
2543
2818
  /*
2544
2819
    We have to store type of duplicate handling explicitly, because
2545
2820
    for LOAD DATA it also depends on LOCAL option. And this part
2548
2823
  */
2549
2824
  enum_load_dup_handling dup_handling;
2550
2825
 
 
2826
#ifndef MYSQL_CLIENT
2551
2827
  Execute_load_query_log_event(THD* thd, const char* query_arg,
2552
 
                               ulong query_length, uint32_t fn_pos_start_arg,
2553
 
                               uint32_t fn_pos_end_arg,
 
2828
                               ulong query_length, uint fn_pos_start_arg,
 
2829
                               uint fn_pos_end_arg,
2554
2830
                               enum_load_dup_handling dup_handling_arg,
2555
2831
                               bool using_trans, bool suppress_use,
2556
2832
                               THD::killed_state
2557
2833
                               killed_err_arg= THD::KILLED_NO_VALUE);
 
2834
#ifdef HAVE_REPLICATION
2558
2835
  void pack_info(Protocol* protocol);
2559
 
  Execute_load_query_log_event(const char* buf, uint32_t event_len,
 
2836
#endif /* HAVE_REPLICATION */
 
2837
#else
 
2838
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2839
  /* Prints the query as LOAD DATA LOCAL and with rewritten filename */
 
2840
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
 
2841
             const char *local_fname);
 
2842
#endif
 
2843
  Execute_load_query_log_event(const char* buf, uint event_len,
2560
2844
                               const Format_description_log_event
2561
2845
                               *description_event);
2562
2846
  ~Execute_load_query_log_event() {}
2565
2849
  bool is_valid() const { return Query_log_event::is_valid() && file_id != 0; }
2566
2850
 
2567
2851
  ulong get_post_header_size_for_derived();
 
2852
#ifndef MYSQL_CLIENT
2568
2853
  bool write_post_header_for_derived(IO_CACHE* file);
 
2854
#endif
2569
2855
 
2570
2856
private:
 
2857
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2571
2858
  virtual int do_apply_event(Relay_log_info const *rli);
2572
 
};
2573
 
 
2574
 
 
2575
 
char *str_to_hex(char *to, const char *from, uint32_t len);
 
2859
#endif
 
2860
};
 
2861
 
 
2862
 
 
2863
#ifdef MYSQL_CLIENT
 
2864
/**
 
2865
  @class Unknown_log_event
 
2866
 
 
2867
  @section Unknown_log_event_binary_format Binary Format
 
2868
*/
 
2869
class Unknown_log_event: public Log_event
 
2870
{
 
2871
public:
 
2872
  /*
 
2873
    Even if this is an unknown event, we still pass description_event to
 
2874
    Log_event's ctor, this way we can extract maximum information from the
 
2875
    event's header (the unique ID for example).
 
2876
  */
 
2877
  Unknown_log_event(const char* buf,
 
2878
                    const Format_description_log_event *description_event):
 
2879
    Log_event(buf, description_event)
 
2880
  {}
 
2881
  ~Unknown_log_event() {}
 
2882
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2883
  Log_event_type get_type_code() { return UNKNOWN_EVENT;}
 
2884
  bool is_valid() const { return 1; }
 
2885
};
 
2886
#endif
 
2887
char *str_to_hex(char *to, const char *from, uint len);
2576
2888
 
2577
2889
/**
2578
2890
  @class Table_map_log_event
2701
3013
  </tr>
2702
3014
 
2703
3015
  <tr>
2704
 
    <td>DRIZZLE_TYPE_TINY</td><td>1</td>
2705
 
    <td>0</td>
2706
 
    <td>No column metadata.</td>
2707
 
  </tr>
2708
 
 
2709
 
  <tr>
2710
 
    <td>DRIZZLE_TYPE_SHORT</td><td>2</td>
2711
 
    <td>0</td>
2712
 
    <td>No column metadata.</td>
2713
 
  </tr>
2714
 
 
2715
 
  <tr>
2716
 
    <td>DRIZZLE_TYPE_LONG</td><td>3</td>
2717
 
    <td>0</td>
2718
 
    <td>No column metadata.</td>
2719
 
  </tr>
2720
 
 
2721
 
  <tr>
2722
 
    <td>DRIZZLE_TYPE_DOUBLE</td><td>5</td>
 
3016
    <td>MYSQL_TYPE_DECIMAL</td><td>0</td>
 
3017
    <td>0</td>
 
3018
    <td>No column metadata.</td>
 
3019
  </tr>
 
3020
 
 
3021
  <tr>
 
3022
    <td>MYSQL_TYPE_TINY</td><td>1</td>
 
3023
    <td>0</td>
 
3024
    <td>No column metadata.</td>
 
3025
  </tr>
 
3026
 
 
3027
  <tr>
 
3028
    <td>MYSQL_TYPE_SHORT</td><td>2</td>
 
3029
    <td>0</td>
 
3030
    <td>No column metadata.</td>
 
3031
  </tr>
 
3032
 
 
3033
  <tr>
 
3034
    <td>MYSQL_TYPE_LONG</td><td>3</td>
 
3035
    <td>0</td>
 
3036
    <td>No column metadata.</td>
 
3037
  </tr>
 
3038
 
 
3039
  <tr>
 
3040
    <td>MYSQL_TYPE_FLOAT</td><td>4</td>
 
3041
    <td>1 byte</td>
 
3042
    <td>1 byte unsigned integer, representing the "pack_length", which
 
3043
    is equal to sizeof(float) on the server from which the event
 
3044
    originates.</td>
 
3045
  </tr>
 
3046
 
 
3047
  <tr>
 
3048
    <td>MYSQL_TYPE_DOUBLE</td><td>5</td>
2723
3049
    <td>1 byte</td>
2724
3050
    <td>1 byte unsigned integer, representing the "pack_length", which
2725
3051
    is equal to sizeof(double) on the server from which the event
2727
3053
  </tr>
2728
3054
 
2729
3055
  <tr>
2730
 
    <td>DRIZZLE_TYPE_NULL</td><td>6</td>
2731
 
    <td>0</td>
2732
 
    <td>No column metadata.</td>
2733
 
  </tr>
2734
 
 
2735
 
  <tr>
2736
 
    <td>DRIZZLE_TYPE_TIMESTAMP</td><td>7</td>
2737
 
    <td>0</td>
2738
 
    <td>No column metadata.</td>
2739
 
  </tr>
2740
 
 
2741
 
  <tr>
2742
 
    <td>DRIZZLE_TYPE_LONGLONG</td><td>8</td>
2743
 
    <td>0</td>
2744
 
    <td>No column metadata.</td>
2745
 
  </tr>
2746
 
 
2747
 
  <tr>
2748
 
    <td>DRIZZLE_TYPE_DATE</td><td>10</td>
2749
 
    <td>0</td>
2750
 
    <td>No column metadata.</td>
2751
 
  </tr>
2752
 
 
2753
 
  <tr>
2754
 
    <td>DRIZZLE_TYPE_TIME</td><td>11</td>
2755
 
    <td>0</td>
2756
 
    <td>No column metadata.</td>
2757
 
  </tr>
2758
 
 
2759
 
  <tr>
2760
 
    <td>DRIZZLE_TYPE_DATETIME</td><td>12</td>
2761
 
    <td>0</td>
2762
 
    <td>No column metadata.</td>
2763
 
  </tr>
2764
 
 
2765
 
  <tr>
2766
 
    <td>DRIZZLE_TYPE_YEAR</td><td>13</td>
2767
 
    <td>0</td>
2768
 
    <td>No column metadata.</td>
2769
 
  </tr>
2770
 
 
2771
 
  <tr>
2772
 
    <td><i>DRIZZLE_TYPE_NEWDATE</i></td><td><i>14</i></td>
 
3056
    <td>MYSQL_TYPE_NULL</td><td>6</td>
 
3057
    <td>0</td>
 
3058
    <td>No column metadata.</td>
 
3059
  </tr>
 
3060
 
 
3061
  <tr>
 
3062
    <td>MYSQL_TYPE_TIMESTAMP</td><td>7</td>
 
3063
    <td>0</td>
 
3064
    <td>No column metadata.</td>
 
3065
  </tr>
 
3066
 
 
3067
  <tr>
 
3068
    <td>MYSQL_TYPE_LONGLONG</td><td>8</td>
 
3069
    <td>0</td>
 
3070
    <td>No column metadata.</td>
 
3071
  </tr>
 
3072
 
 
3073
  <tr>
 
3074
    <td>MYSQL_TYPE_INT24</td><td>9</td>
 
3075
    <td>0</td>
 
3076
    <td>No column metadata.</td>
 
3077
  </tr>
 
3078
 
 
3079
  <tr>
 
3080
    <td>MYSQL_TYPE_DATE</td><td>10</td>
 
3081
    <td>0</td>
 
3082
    <td>No column metadata.</td>
 
3083
  </tr>
 
3084
 
 
3085
  <tr>
 
3086
    <td>MYSQL_TYPE_TIME</td><td>11</td>
 
3087
    <td>0</td>
 
3088
    <td>No column metadata.</td>
 
3089
  </tr>
 
3090
 
 
3091
  <tr>
 
3092
    <td>MYSQL_TYPE_DATETIME</td><td>12</td>
 
3093
    <td>0</td>
 
3094
    <td>No column metadata.</td>
 
3095
  </tr>
 
3096
 
 
3097
  <tr>
 
3098
    <td>MYSQL_TYPE_YEAR</td><td>13</td>
 
3099
    <td>0</td>
 
3100
    <td>No column metadata.</td>
 
3101
  </tr>
 
3102
 
 
3103
  <tr>
 
3104
    <td><i>MYSQL_TYPE_NEWDATE</i></td><td><i>14</i></td>
2773
3105
    <td>&ndash;</td>
2774
3106
    <td><i>This enumeration value is only used internally and cannot
2775
3107
    exist in a binlog.</i></td>
2776
3108
  </tr>
2777
3109
 
2778
3110
  <tr>
2779
 
    <td>DRIZZLE_TYPE_VARCHAR</td><td>15</td>
 
3111
    <td>MYSQL_TYPE_VARCHAR</td><td>15</td>
2780
3112
    <td>2 bytes</td>
2781
3113
    <td>2 byte unsigned integer representing the maximum length of
2782
3114
    the string.</td>
2783
3115
  </tr>
2784
3116
 
2785
3117
  <tr>
2786
 
    <td>DRIZZLE_TYPE_NEWDECIMAL</td><td>246</td>
 
3118
    <td>MYSQL_TYPE_BIT</td><td>16</td>
 
3119
    <td>2 bytes</td>
 
3120
    <td>A 1 byte unsigned int representing the length in bits of the
 
3121
    bitfield (0 to 64), followed by a 1 byte unsigned int
 
3122
    representing the number of bytes occupied by the bitfield.  The
 
3123
    number of bytes is either int((length+7)/8) or int(length/8).</td>
 
3124
  </tr>
 
3125
 
 
3126
  <tr>
 
3127
    <td>MYSQL_TYPE_NEWDECIMAL</td><td>246</td>
2787
3128
    <td>2 bytes</td>
2788
3129
    <td>A 1 byte unsigned int representing the precision, followed
2789
3130
    by a 1 byte unsigned int representing the number of decimals.</td>
2790
3131
  </tr>
2791
3132
 
2792
3133
  <tr>
2793
 
    <td><i>DRIZZLE_TYPE_ENUM</i></td><td><i>247</i></td>
2794
 
    <td>&ndash;</td>
2795
 
    <td><i>This enumeration value is only used internally and cannot
2796
 
    exist in a binlog.</i></td>
2797
 
  </tr>
2798
 
 
2799
 
  <tr>
2800
 
    <td><i>DRIZZLE_TYPE_SET</i></td><td><i>248</i></td>
2801
 
    <td>&ndash;</td>
2802
 
    <td><i>This enumeration value is only used internally and cannot
2803
 
    exist in a binlog.</i></td>
2804
 
  </tr>
2805
 
 
2806
 
  <tr>
2807
 
    <td>DRIZZLE_TYPE_BLOB</td><td>252</td>
 
3134
    <td><i>MYSQL_TYPE_ENUM</i></td><td><i>247</i></td>
 
3135
    <td>&ndash;</td>
 
3136
    <td><i>This enumeration value is only used internally and cannot
 
3137
    exist in a binlog.</i></td>
 
3138
  </tr>
 
3139
 
 
3140
  <tr>
 
3141
    <td><i>MYSQL_TYPE_SET</i></td><td><i>248</i></td>
 
3142
    <td>&ndash;</td>
 
3143
    <td><i>This enumeration value is only used internally and cannot
 
3144
    exist in a binlog.</i></td>
 
3145
  </tr>
 
3146
 
 
3147
  <tr>
 
3148
    <td>MYSQL_TYPE_TINY_BLOB</td><td>249</td>
 
3149
    <td>&ndash;</td>
 
3150
    <td><i>This enumeration value is only used internally and cannot
 
3151
    exist in a binlog.</i></td>
 
3152
  </tr>
 
3153
 
 
3154
  <tr>
 
3155
    <td><i>MYSQL_TYPE_MEDIUM_BLOB</i></td><td><i>250</i></td>
 
3156
    <td>&ndash;</td>
 
3157
    <td><i>This enumeration value is only used internally and cannot
 
3158
    exist in a binlog.</i></td>
 
3159
  </tr>
 
3160
 
 
3161
  <tr>
 
3162
    <td><i>MYSQL_TYPE_LONG_BLOB</i></td><td><i>251</i></td>
 
3163
    <td>&ndash;</td>
 
3164
    <td><i>This enumeration value is only used internally and cannot
 
3165
    exist in a binlog.</i></td>
 
3166
  </tr>
 
3167
 
 
3168
  <tr>
 
3169
    <td>MYSQL_TYPE_BLOB</td><td>252</td>
2808
3170
    <td>1 byte</td>
2809
3171
    <td>The pack length, i.e., the number of bytes needed to represent
2810
3172
    the length of the blob: 1, 2, 3, or 4.</td>
2811
3173
  </tr>
2812
3174
 
2813
3175
  <tr>
2814
 
    <td>DRIZZLE_TYPE_STRING</td><td>254</td>
2815
 
    <td>2 bytes</td>
2816
 
    <td>The first byte is always DRIZZLE_TYPE_VAR_STRING (i.e., 253).
 
3176
    <td>MYSQL_TYPE_VAR_STRING</td><td>253</td>
 
3177
    <td>2 bytes</td>
 
3178
    <td>This is used to store both strings and enumeration values.
 
3179
    The first byte is a enumeration value storing the <i>real
 
3180
    type</i>, which may be either MYSQL_TYPE_VAR_STRING or
 
3181
    MYSQL_TYPE_ENUM.  The second byte is a 1 byte unsigned integer
 
3182
    representing the field size, i.e., the number of bytes needed to
 
3183
    store the length of the string.</td>
 
3184
  </tr>
 
3185
 
 
3186
  <tr>
 
3187
    <td>MYSQL_TYPE_STRING</td><td>254</td>
 
3188
    <td>2 bytes</td>
 
3189
    <td>The first byte is always MYSQL_TYPE_VAR_STRING (i.e., 253).
2817
3190
    The second byte is the field size, i.e., the number of bytes in
2818
3191
    the representation of size of the string: 3 or 4.</td>
2819
3192
  </tr>
2820
3193
 
 
3194
  <tr>
 
3195
    <td>MYSQL_TYPE_GEOMETRY</td><td>255</td>
 
3196
    <td>1 byte</td>
 
3197
    <td>The pack length, i.e., the number of bytes needed to represent
 
3198
    the length of the geometry: 1, 2, 3, or 4.</td>
 
3199
  </tr>
 
3200
 
2821
3201
  </table>
2822
3202
*/
2823
3203
class Table_map_log_event : public Log_event
2853
3233
    ENUM_FLAG_COUNT
2854
3234
  };
2855
3235
 
2856
 
  typedef uint16_t flag_set;
 
3236
  typedef uint16 flag_set;
2857
3237
 
2858
3238
  /* Special constants representing sets of flags */
2859
3239
  enum 
2865
3245
  void clear_flags(flag_set flag) { m_flags &= ~flag; }
2866
3246
  flag_set get_flags(flag_set flag) const { return m_flags & flag; }
2867
3247
 
2868
 
  Table_map_log_event(THD *thd, Table *tbl, ulong tid, 
2869
 
                      bool is_transactional, uint16_t flags);
2870
 
  Table_map_log_event(const char *buf, uint32_t event_len, 
 
3248
#ifndef MYSQL_CLIENT
 
3249
  Table_map_log_event(THD *thd, TABLE *tbl, ulong tid, 
 
3250
                      bool is_transactional, uint16 flags);
 
3251
#endif
 
3252
#ifdef HAVE_REPLICATION
 
3253
  Table_map_log_event(const char *buf, uint event_len, 
2871
3254
                      const Format_description_log_event *description_event);
 
3255
#endif
2872
3256
 
2873
3257
  ~Table_map_log_event();
2874
3258
 
2876
3260
  virtual bool is_valid() const { return m_memory != NULL; /* we check malloc */ }
2877
3261
 
2878
3262
  virtual int get_data_size() { return m_data_size; } 
 
3263
#ifndef MYSQL_CLIENT
2879
3264
  virtual int save_field_metadata();
2880
3265
  virtual bool write_data_header(IO_CACHE *file);
2881
3266
  virtual bool write_data_body(IO_CACHE *file);
2882
3267
  virtual const char *get_db() { return m_dbnam; }
 
3268
#endif
 
3269
 
 
3270
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2883
3271
  virtual void pack_info(Protocol *protocol);
 
3272
#endif
 
3273
 
 
3274
#ifdef MYSQL_CLIENT
 
3275
  virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 
3276
#endif
 
3277
 
2884
3278
 
2885
3279
private:
 
3280
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2886
3281
  virtual int do_apply_event(Relay_log_info const *rli);
2887
3282
  virtual int do_update_pos(Relay_log_info *rli);
2888
3283
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
3284
#endif
2889
3285
 
2890
 
  Table         *m_table;
 
3286
#ifndef MYSQL_CLIENT
 
3287
  TABLE         *m_table;
 
3288
#endif
2891
3289
  char const    *m_dbnam;
2892
3290
  size_t         m_dblen;
2893
3291
  char const    *m_tblnam;
2894
3292
  size_t         m_tbllen;
2895
3293
  ulong          m_colcnt;
2896
 
  unsigned char         *m_coltype;
 
3294
  uchar         *m_coltype;
2897
3295
 
2898
 
  unsigned char         *m_memory;
 
3296
  uchar         *m_memory;
2899
3297
  ulong          m_table_id;
2900
3298
  flag_set       m_flags;
2901
3299
 
2902
3300
  size_t         m_data_size;
2903
3301
 
2904
 
  unsigned char          *m_field_metadata;        // buffer for field metadata
 
3302
  uchar          *m_field_metadata;        // buffer for field metadata
2905
3303
  /*
2906
3304
    The size of field metadata buffer set by calling save_field_metadata()
2907
3305
  */
2908
3306
  ulong          m_field_metadata_size;   
2909
 
  unsigned char         *m_null_bits;
2910
 
  unsigned char         *m_meta_memory;
 
3307
  uchar         *m_null_bits;
 
3308
  uchar         *m_meta_memory;
2911
3309
};
2912
3310
 
2913
3311
 
2967
3365
    COMPLETE_ROWS_F = (1U << 3)
2968
3366
  };
2969
3367
 
2970
 
  typedef uint16_t flag_set;
 
3368
  typedef uint16 flag_set;
2971
3369
 
2972
3370
  /* Special constants representing sets of flags */
2973
3371
  enum 
2981
3379
  void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; }
2982
3380
  flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; }
2983
3381
 
 
3382
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2984
3383
  virtual void pack_info(Protocol *protocol);
2985
 
 
2986
 
  int add_row_data(unsigned char *data, size_t length)
 
3384
#endif
 
3385
 
 
3386
#ifdef MYSQL_CLIENT
 
3387
  /* not for direct call, each derived has its own ::print() */
 
3388
  virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info)= 0;
 
3389
#endif
 
3390
 
 
3391
#ifndef MYSQL_CLIENT
 
3392
  int add_row_data(uchar *data, size_t length)
2987
3393
  {
2988
3394
    return do_add_row_data(data,length); 
2989
3395
  }
 
3396
#endif
2990
3397
 
2991
3398
  /* Member functions to implement superclass interface */
2992
3399
  virtual int get_data_size();
2995
3402
  size_t get_width() const          { return m_width; }
2996
3403
  ulong get_table_id() const        { return m_table_id; }
2997
3404
 
 
3405
#ifndef MYSQL_CLIENT
2998
3406
  virtual bool write_data_header(IO_CACHE *file);
2999
3407
  virtual bool write_data_body(IO_CACHE *file);
3000
3408
  virtual const char *get_db() { return m_table->s->db.str; }
 
3409
#endif
3001
3410
  /*
3002
3411
    Check that malloc() succeeded in allocating memory for the rows
3003
3412
    buffer and the COLS vector. Checking that an Update_rows_log_event
3009
3418
    return m_rows_buf && m_cols.bitmap;
3010
3419
  }
3011
3420
 
3012
 
  uint32_t     m_row_count;         /* The number of rows added to the event */
 
3421
  uint     m_row_count;         /* The number of rows added to the event */
3013
3422
 
3014
3423
protected:
3015
3424
  /* 
3016
3425
     The constructors are protected since you're supposed to inherit
3017
3426
     this class, not create instances of this class.
3018
3427
  */
3019
 
  Rows_log_event(THD*, Table*, ulong table_id, 
 
3428
#ifndef MYSQL_CLIENT
 
3429
  Rows_log_event(THD*, TABLE*, ulong table_id, 
3020
3430
                 MY_BITMAP const *cols, bool is_transactional);
3021
 
  Rows_log_event(const char *row_data, uint32_t event_len, 
 
3431
#endif
 
3432
  Rows_log_event(const char *row_data, uint event_len, 
3022
3433
                 Log_event_type event_type,
3023
3434
                 const Format_description_log_event *description_event);
3024
3435
 
3025
 
  virtual int do_add_row_data(unsigned char *data, size_t length);
3026
 
 
3027
 
  Table *m_table;               /* The table the rows belong to */
 
3436
#ifdef MYSQL_CLIENT
 
3437
  void print_helper(FILE *, PRINT_EVENT_INFO *, char const *const name);
 
3438
#endif
 
3439
 
 
3440
#ifndef MYSQL_CLIENT
 
3441
  virtual int do_add_row_data(uchar *data, size_t length);
 
3442
#endif
 
3443
 
 
3444
#ifndef MYSQL_CLIENT
 
3445
  TABLE *m_table;               /* The table the rows belong to */
 
3446
#endif
3028
3447
  ulong       m_table_id;       /* Table ID */
3029
3448
  MY_BITMAP   m_cols;           /* Bitmap denoting columns available */
3030
3449
  ulong       m_width;          /* The width of the columns bitmap */
3040
3459
  ulong       m_master_reclength; /* Length of record on master side */
3041
3460
 
3042
3461
  /* Bit buffers in the same memory as the class */
3043
 
  uint32_t    m_bitbuf[128/(sizeof(uint32_t)*8)];
3044
 
  uint32_t    m_bitbuf_ai[128/(sizeof(uint32_t)*8)];
 
3462
  uint32    m_bitbuf[128/(sizeof(uint32)*8)];
 
3463
  uint32    m_bitbuf_ai[128/(sizeof(uint32)*8)];
3045
3464
 
3046
 
  unsigned char    *m_rows_buf;         /* The rows in packed format */
3047
 
  unsigned char    *m_rows_cur;         /* One-after the end of the data */
3048
 
  unsigned char    *m_rows_end;         /* One-after the end of the allocated space */
 
3465
  uchar    *m_rows_buf;         /* The rows in packed format */
 
3466
  uchar    *m_rows_cur;         /* One-after the end of the data */
 
3467
  uchar    *m_rows_end;         /* One-after the end of the allocated space */
3049
3468
 
3050
3469
  flag_set m_flags;             /* Flags for row-level events */
3051
3470
 
3052
3471
  /* helper functions */
3053
3472
 
3054
 
  const unsigned char *m_curr_row;     /* Start of the row being processed */
3055
 
  const unsigned char *m_curr_row_end; /* One-after the end of the current row */
3056
 
  unsigned char    *m_key;      /* Buffer to keep key value during searches */
 
3473
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
 
3474
  const uchar *m_curr_row;     /* Start of the row being processed */
 
3475
  const uchar *m_curr_row_end; /* One-after the end of the current row */
 
3476
  uchar    *m_key;      /* Buffer to keep key value during searches */
3057
3477
 
3058
3478
  int find_row(const Relay_log_info *const);
3059
3479
  int write_row(const Relay_log_info *const, const bool);
3062
3482
  int unpack_current_row(const Relay_log_info *const rli,
3063
3483
                         MY_BITMAP const *cols)
3064
3484
  { 
3065
 
    assert(m_table);
 
3485
    DBUG_ASSERT(m_table);
3066
3486
    ASSERT_OR_RETURN_ERROR(m_curr_row < m_rows_end, HA_ERR_CORRUPT_EVENT);
3067
3487
    int const result= ::unpack_row(rli, m_table, m_width, m_curr_row, cols,
3068
3488
                                   &m_curr_row_end, &m_master_reclength);
3071
3491
    ASSERT_OR_RETURN_ERROR(m_curr_row_end <= m_rows_end, HA_ERR_CORRUPT_EVENT);
3072
3492
    return result;
3073
3493
  }
 
3494
#endif
3074
3495
 
3075
3496
private:
3076
3497
 
 
3498
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3077
3499
  virtual int do_apply_event(Relay_log_info const *rli);
3078
3500
  virtual int do_update_pos(Relay_log_info *rli);
3079
3501
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
3128
3550
      
3129
3551
  */
3130
3552
  virtual int do_exec_row(const Relay_log_info *const rli) = 0;
 
3553
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
3131
3554
 
3132
3555
  friend class Old_rows_log_event;
3133
3556
};
3150
3573
    TYPE_CODE = WRITE_ROWS_EVENT
3151
3574
  };
3152
3575
 
3153
 
  Write_rows_log_event(THD*, Table*, ulong table_id, 
 
3576
#if !defined(MYSQL_CLIENT)
 
3577
  Write_rows_log_event(THD*, TABLE*, ulong table_id, 
3154
3578
                       bool is_transactional);
3155
 
  Write_rows_log_event(const char *buf, uint32_t event_len, 
 
3579
#endif
 
3580
#ifdef HAVE_REPLICATION
 
3581
  Write_rows_log_event(const char *buf, uint event_len, 
3156
3582
                       const Format_description_log_event *description_event);
3157
 
  static bool binlog_row_logging_function(THD *thd, Table *table,
 
3583
#endif
 
3584
#if !defined(MYSQL_CLIENT) 
 
3585
  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3158
3586
                                          bool is_transactional,
3159
 
                                          const unsigned char *before_record
 
3587
                                          const uchar *before_record
3160
3588
                                          __attribute__((unused)),
3161
 
                                          const unsigned char *after_record)
 
3589
                                          const uchar *after_record)
3162
3590
  {
3163
3591
    return thd->binlog_write_row(table, is_transactional, after_record);
3164
3592
  }
 
3593
#endif
3165
3594
 
3166
3595
private:
3167
3596
  virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3168
3597
 
 
3598
#ifdef MYSQL_CLIENT
 
3599
  void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 
3600
#endif
 
3601
 
 
3602
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3169
3603
  virtual int do_before_row_operations(const Slave_reporting_capability *const);
3170
3604
  virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3171
3605
  virtual int do_exec_row(const Relay_log_info *const);
 
3606
#endif
3172
3607
};
3173
3608
 
3174
3609
 
3193
3628
    TYPE_CODE = UPDATE_ROWS_EVENT
3194
3629
  };
3195
3630
 
3196
 
  Update_rows_log_event(THD*, Table*, ulong table_id,
 
3631
#ifndef MYSQL_CLIENT
 
3632
  Update_rows_log_event(THD*, TABLE*, ulong table_id,
3197
3633
                        bool is_transactional);
3198
3634
 
3199
3635
  void init(MY_BITMAP const *cols);
 
3636
#endif
3200
3637
 
3201
3638
  virtual ~Update_rows_log_event();
3202
3639
 
3203
 
  Update_rows_log_event(const char *buf, uint32_t event_len, 
 
3640
#ifdef HAVE_REPLICATION
 
3641
  Update_rows_log_event(const char *buf, uint event_len, 
3204
3642
                        const Format_description_log_event *description_event);
 
3643
#endif
3205
3644
 
3206
 
  static bool binlog_row_logging_function(THD *thd, Table *table,
 
3645
#if !defined(MYSQL_CLIENT) 
 
3646
  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3207
3647
                                          bool is_transactional,
3208
 
                                          const unsigned char *before_record,
3209
 
                                          const unsigned char *after_record)
 
3648
                                          const uchar *before_record,
 
3649
                                          const uchar *after_record)
3210
3650
  {
3211
3651
    return thd->binlog_update_row(table, is_transactional,
3212
3652
                                  before_record, after_record);
3213
3653
  }
 
3654
#endif
3214
3655
 
3215
3656
  virtual bool is_valid() const
3216
3657
  {
3220
3661
protected:
3221
3662
  virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3222
3663
 
 
3664
#ifdef MYSQL_CLIENT
 
3665
  void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 
3666
#endif
 
3667
 
 
3668
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3223
3669
  virtual int do_before_row_operations(const Slave_reporting_capability *const);
3224
3670
  virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3225
3671
  virtual int do_exec_row(const Relay_log_info *const);
 
3672
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
3226
3673
};
3227
3674
 
3228
3675
/**
3254
3701
    TYPE_CODE = DELETE_ROWS_EVENT
3255
3702
  };
3256
3703
 
3257
 
  Delete_rows_log_event(THD*, Table*, ulong, 
 
3704
#ifndef MYSQL_CLIENT
 
3705
  Delete_rows_log_event(THD*, TABLE*, ulong, 
3258
3706
                        bool is_transactional);
3259
 
  Delete_rows_log_event(const char *buf, uint32_t event_len, 
 
3707
#endif
 
3708
#ifdef HAVE_REPLICATION
 
3709
  Delete_rows_log_event(const char *buf, uint event_len, 
3260
3710
                        const Format_description_log_event *description_event);
3261
 
  static bool binlog_row_logging_function(THD *thd, Table *table,
 
3711
#endif
 
3712
#if !defined(MYSQL_CLIENT) 
 
3713
  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3262
3714
                                          bool is_transactional,
3263
 
                                          const unsigned char *before_record,
3264
 
                                          const unsigned char *after_record
 
3715
                                          const uchar *before_record,
 
3716
                                          const uchar *after_record
3265
3717
                                          __attribute__((unused)))
3266
3718
  {
3267
3719
    return thd->binlog_delete_row(table, is_transactional, before_record);
3268
3720
  }
 
3721
#endif
3269
3722
  
3270
3723
protected:
3271
3724
  virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3272
3725
 
 
3726
#ifdef MYSQL_CLIENT
 
3727
  void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 
3728
#endif
 
3729
 
 
3730
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3273
3731
  virtual int do_before_row_operations(const Slave_reporting_capability *const);
3274
3732
  virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3275
3733
  virtual int do_exec_row(const Relay_log_info *const);
 
3734
#endif
3276
3735
};
3277
3736
 
3278
3737
 
3314
3773
*/
3315
3774
class Incident_log_event : public Log_event {
3316
3775
public:
 
3776
#ifndef MYSQL_CLIENT
3317
3777
  Incident_log_event(THD *thd_arg, Incident incident)
3318
 
    : Log_event(thd_arg, 0, false), m_incident(incident)
 
3778
    : Log_event(thd_arg, 0, FALSE), m_incident(incident)
3319
3779
  {
 
3780
    DBUG_ENTER("Incident_log_event::Incident_log_event");
 
3781
    DBUG_PRINT("enter", ("m_incident: %d", m_incident));
3320
3782
    m_message.str= NULL;                    /* Just as a precaution */
3321
3783
    m_message.length= 0;
3322
 
    return;
 
3784
    DBUG_VOID_RETURN;
3323
3785
  }
3324
3786
 
3325
3787
  Incident_log_event(THD *thd_arg, Incident incident, LEX_STRING const msg)
3326
 
    : Log_event(thd_arg, 0, false), m_incident(incident)
 
3788
    : Log_event(thd_arg, 0, FALSE), m_incident(incident)
3327
3789
  {
 
3790
    DBUG_ENTER("Incident_log_event::Incident_log_event");
 
3791
    DBUG_PRINT("enter", ("m_incident: %d", m_incident));
3328
3792
    m_message= msg;
3329
 
    return;
 
3793
    DBUG_VOID_RETURN;
3330
3794
  }
 
3795
#endif
3331
3796
 
 
3797
#ifndef MYSQL_CLIENT
3332
3798
  void pack_info(Protocol*);
 
3799
#endif
3333
3800
 
3334
 
  Incident_log_event(const char *buf, uint32_t event_len,
 
3801
  Incident_log_event(const char *buf, uint event_len,
3335
3802
                     const Format_description_log_event *descr_event);
3336
3803
 
3337
3804
  virtual ~Incident_log_event();
3338
3805
 
 
3806
#ifdef MYSQL_CLIENT
 
3807
  virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 
3808
#endif
 
3809
 
 
3810
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3339
3811
  virtual int do_apply_event(Relay_log_info const *rli);
 
3812
#endif
3340
3813
 
3341
3814
  virtual bool write_data_header(IO_CACHE *file);
3342
3815
  virtual bool write_data_body(IO_CACHE *file);
3355
3828
  LEX_STRING m_message;
3356
3829
};
3357
3830
 
3358
 
int append_query_string(const CHARSET_INFO * const csinfo,
3359
 
                        String const *from, String *to);
3360
 
 
3361
3831
static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache,
3362
3832
                                                       FILE *file)
3363
3833
{
3364
3834
  return         
3365
3835
    my_b_copy_to_file(cache, file) ||
3366
 
    reinit_io_cache(cache, WRITE_CACHE, 0, false, true);
 
3836
    reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE);
3367
3837
}
3368
3838
 
 
3839
#ifndef MYSQL_CLIENT
3369
3840
/*****************************************************************************
3370
3841
 
3371
3842
  Heartbeat Log Event class
3384
3855
class Heartbeat_log_event: public Log_event
3385
3856
{
3386
3857
public:
3387
 
  Heartbeat_log_event(const char* buf, uint32_t event_len,
 
3858
  Heartbeat_log_event(const char* buf, uint event_len,
3388
3859
                      const Format_description_log_event* description_event);
3389
3860
  Log_event_type get_type_code() { return HEARTBEAT_LOG_EVENT; }
3390
3861
  bool is_valid() const
3393
3864
              log_pos >= BIN_LOG_HEADER_SIZE);
3394
3865
    }
3395
3866
  const char * get_log_ident() { return log_ident; }
3396
 
  uint32_t get_ident_len() { return ident_len; }
 
3867
  uint get_ident_len() { return ident_len; }
3397
3868
  
3398
3869
private:
3399
3870
  const char* log_ident;
3400
 
  uint32_t ident_len;
 
3871
  uint ident_len;
3401
3872
};
 
3873
#endif
3402
3874
 
3403
3875
/**
3404
3876
  @} (end of group Replication)
3405
3877
*/
3406
3878
 
3407
 
#endif /* DRIZZLED_LOG_EVENT_H */
 
3879
#endif /* _log_event_h */