~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/log_event.h

  • Committer: Monty Taylor
  • Date: 2008-07-05 11:20:18 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: monty@inaugust.com-20080705112018-fr12kkmgphtu7m29
Changes so that removal of duplicate curr_dir from my_sys.h work.

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
#else
 
41
#include "my_decimal.h"
 
42
#endif
43
43
 
44
44
/**
45
45
   Either assert or return an error.
50
50
   @param COND   Condition to check
51
51
   @param ERRNO  Error number to return in non-debug builds
52
52
*/
53
 
#define ASSERT_OR_RETURN_ERROR(COND, ERRNO) \
54
 
  assert(COND)
 
53
#ifdef DBUG_OFF
 
54
#define ASSERT_OR_RETURN_ERROR(COND, ERRNO) \
 
55
  do { if (!(COND)) return ERRNO; } while (0)
 
56
#else
 
57
#define ASSERT_OR_RETURN_ERROR(COND, ERRNO) \
 
58
  DBUG_ASSERT(COND)
 
59
#endif
55
60
 
56
61
#define LOG_READ_EOF    -1
57
62
#define LOG_READ_BOGUS  -2
155
160
  const char* line_start;
156
161
  const char* escaped;
157
162
  int cached_new_format;
158
 
  uint8_t field_term_len,enclosed_len,line_term_len,line_start_len, escaped_len;
 
163
  uint8 field_term_len,enclosed_len,line_term_len,line_start_len, escaped_len;
159
164
  char opt_flags;
160
165
  char empty_flags;
161
166
 
162
 
  /* store in new format even if old is possible */
 
167
  // store in new format even if old is possible
163
168
  void force_new_format() { cached_new_format = 1;}
164
169
  int data_size()
165
170
  {
209
214
   event's ID, LOG_EVENT_HEADER_LEN will be something like 26, but
210
215
   LOG_EVENT_MINIMAL_HEADER_LEN will remain 19.
211
216
*/
212
 
#define LOG_EVENT_MINIMAL_HEADER_LEN (uint8_t)19
 
217
#define LOG_EVENT_MINIMAL_HEADER_LEN 19
213
218
 
214
219
/* event-specific post-header sizes */
215
220
// where 3.23, 4.x and 5.0 agree
398
403
/**
399
404
  @def LOG_EVENT_THREAD_SPECIFIC_F
400
405
 
401
 
  If the query depends on the thread (for example: TEMPORARY Table).
 
406
  If the query depends on the thread (for example: TEMPORARY TABLE).
402
407
  Currently this is used by mysqlbinlog to know it must print
403
408
  SET @@PSEUDO_THREAD_ID=xx; before the query (it would not hurt to print it
404
409
  for every query but this would be slow).
453
458
 
454
459
/* Shouldn't be defined before */
455
460
#define EXPECTED_OPTIONS \
456
 
  ((1U << 14) | (1U << 26) | (1U << 27) | (1U << 19))
 
461
  ((ULL(1) << 14) | (ULL(1) << 26) | (ULL(1) << 27) | (ULL(1) << 19))
457
462
 
458
463
#if OPTIONS_WRITTEN_TO_BIN_LOG != EXPECTED_OPTIONS
459
464
#error OPTIONS_WRITTEN_TO_BIN_LOG must NOT change their values!
545
550
};
546
551
 
547
552
 
 
553
#ifndef MYSQL_CLIENT
548
554
class String;
549
 
class DRIZZLE_BIN_LOG;
 
555
class MYSQL_BIN_LOG;
550
556
class THD;
 
557
#endif
551
558
 
552
559
class Format_description_log_event;
553
560
class Relay_log_info;
554
561
 
 
562
#ifdef MYSQL_CLIENT
 
563
enum enum_base64_output_mode {
 
564
  BASE64_OUTPUT_NEVER= 0,
 
565
  BASE64_OUTPUT_AUTO= 1,
 
566
  BASE64_OUTPUT_ALWAYS= 2,
 
567
  BASE64_OUTPUT_UNSPEC= 3,
 
568
  /* insert new output modes here */
 
569
  BASE64_OUTPUT_MODE_COUNT
 
570
};
 
571
 
 
572
/*
 
573
  A structure for mysqlbinlog to know how to print events
 
574
 
 
575
  This structure is passed to the event's print() methods,
 
576
 
 
577
  There are two types of settings stored here:
 
578
  1. Last db, flags2, sql_mode etc comes from the last printed event.
 
579
     They are stored so that only the necessary USE and SET commands
 
580
     are printed.
 
581
  2. Other information on how to print the events, e.g. short_form,
 
582
     hexdump_from.  These are not dependent on the last event.
 
583
*/
 
584
typedef struct st_print_event_info
 
585
{
 
586
  /*
 
587
    Settings for database, sql_mode etc that comes from the last event
 
588
    that was printed.  We cache these so that we don't have to print
 
589
    them if they are unchanged.
 
590
  */
 
591
  // TODO: have the last catalog here ??
 
592
  char db[FN_REFLEN+1]; // TODO: make this a LEX_STRING when thd->db is
 
593
  bool flags2_inited;
 
594
  uint32 flags2;
 
595
  bool sql_mode_inited;
 
596
  ulong sql_mode;               /* must be same as THD.variables.sql_mode */
 
597
  ulong auto_increment_increment, auto_increment_offset;
 
598
  bool charset_inited;
 
599
  char charset[6]; // 3 variables, each of them storable in 2 bytes
 
600
  char time_zone_str[MAX_TIME_ZONE_NAME_LENGTH];
 
601
  uint lc_time_names_number;
 
602
  uint charset_database_number;
 
603
  uint thread_id;
 
604
  bool thread_id_printed;
 
605
 
 
606
  st_print_event_info();
 
607
 
 
608
  ~st_print_event_info() {
 
609
    close_cached_file(&head_cache);
 
610
    close_cached_file(&body_cache);
 
611
  }
 
612
  bool init_ok() /* tells if construction was successful */
 
613
    { return my_b_inited(&head_cache) && my_b_inited(&body_cache); }
 
614
 
 
615
 
 
616
  /* Settings on how to print the events */
 
617
  bool short_form;
 
618
  enum_base64_output_mode base64_output_mode;
 
619
  /*
 
620
    This is set whenever a Format_description_event is printed.
 
621
    Later, when an event is printed in base64, this flag is tested: if
 
622
    no Format_description_event has been seen, it is unsafe to print
 
623
    the base64 event, so an error message is generated.
 
624
  */
 
625
  bool printed_fd_event;
 
626
  my_off_t hexdump_from;
 
627
  uint8 common_header_len;
 
628
  char delimiter[16];
 
629
 
 
630
  /*
 
631
     These two caches are used by the row-based replication events to
 
632
     collect the header information and the main body of the events
 
633
     making up a statement.
 
634
   */
 
635
  IO_CACHE head_cache;
 
636
  IO_CACHE body_cache;
 
637
} PRINT_EVENT_INFO;
 
638
#endif
 
639
 
555
640
/**
556
641
  the struct aggregates two paramenters that identify an event
557
642
  uniquely in scope of communication of a particular master and slave couple.
744
829
    sees the offset of the BEGIN, which is logical as rollback may
745
830
    occur), except the COMMIT query which has its real offset.
746
831
  */
747
 
  off_t log_pos;
 
832
  my_off_t log_pos;
748
833
  /*
749
834
     A temp buffer for read_log_event; it is later analysed according to the
750
835
     event's type, and its content is distributed in the event-specific fields.
768
853
    The master's server id (is preserved in the relay log; used to
769
854
    prevent from infinite loops in circular replication).
770
855
  */
771
 
  uint32_t server_id;
 
856
  uint32 server_id;
772
857
 
773
858
  /**
774
859
    Some 16 flags. See the definitions above for LOG_EVENT_TIME_F,
775
860
    LOG_EVENT_FORCED_ROTATE_F, LOG_EVENT_THREAD_SPECIFIC_F, and
776
861
    LOG_EVENT_SUPPRESS_USE_F for notes.
777
862
  */
778
 
  uint16_t flags;
 
863
  uint16 flags;
779
864
 
780
865
  bool cache_stmt;
781
866
 
785
870
  */
786
871
  ulong slave_exec_mode;
787
872
 
 
873
#ifndef MYSQL_CLIENT
788
874
  THD* thd;
789
875
 
790
876
  Log_event();
791
 
  Log_event(THD* thd_arg, uint16_t flags_arg, bool cache_stmt);
 
877
  Log_event(THD* thd_arg, uint16 flags_arg, bool cache_stmt);
792
878
  /*
793
879
    read_log_event() functions read an event from a binlog or relay
794
880
    log; used by SHOW BINLOG EVENTS, the binlog_dump thread on the
812
898
    EVENTS.
813
899
  */
814
900
  static void init_show_field_list(List<Item>* field_list);
 
901
#ifdef HAVE_REPLICATION
815
902
  int net_send(Protocol *protocol, const char* log_name, my_off_t pos);
816
903
 
817
904
  /*
821
908
 
822
909
  virtual void pack_info(Protocol *protocol);
823
910
 
 
911
#endif /* HAVE_REPLICATION */
824
912
  virtual const char* get_db()
825
913
  {
826
914
    return thd ? thd->db : 0;
827
915
  }
 
916
#else
 
917
  Log_event() : temp_buf(0) {}
 
918
    /* avoid having to link mysqlbinlog against libpthread */
 
919
  static Log_event* read_log_event(IO_CACHE* file,
 
920
                                   const Format_description_log_event
 
921
                                   *description_event);
 
922
  /* print*() functions are used by mysqlbinlog */
 
923
  virtual void print(FILE* file, PRINT_EVENT_INFO* print_event_info) = 0;
 
924
  void print_timestamp(IO_CACHE* file, time_t *ts = 0);
 
925
  void print_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
 
926
                    bool is_more);
 
927
  void print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
 
928
                    bool is_more);
 
929
#endif
828
930
 
829
931
  static void *operator new(size_t size)
830
932
  {
832
934
  }
833
935
 
834
936
  static void operator delete(void *ptr,
835
 
                              size_t size __attribute__((unused)))
 
937
                              size_t size __attribute__((__unused__)))
836
938
  {
837
 
    free((unsigned char*) ptr);
 
939
    my_free((uchar*) ptr, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
838
940
  }
839
941
 
840
942
  /* Placement version of the above operators */
841
943
  static void *operator new(size_t, void* ptr) { return ptr; }
842
944
  static void operator delete(void*, void*) { }
843
945
 
 
946
#ifndef MYSQL_CLIENT
844
947
  bool write_header(IO_CACHE* file, ulong data_length);
845
948
  virtual bool write(IO_CACHE* file)
846
949
  {
848
951
            write_data_header(file) ||
849
952
            write_data_body(file));
850
953
  }
851
 
  virtual bool write_data_header(IO_CACHE* file __attribute__((unused)))
 
954
  virtual bool write_data_header(IO_CACHE* file)
852
955
  { return 0; }
853
956
  virtual bool write_data_body(IO_CACHE* file __attribute__((unused)))
854
957
  { return 0; }
863
966
      return tmp_thd->start_time;
864
967
    return my_time(0);
865
968
  }
 
969
#endif
866
970
  virtual Log_event_type get_type_code() = 0;
867
971
  virtual bool is_valid() const = 0;
868
972
  virtual bool is_artificial_event() { return 0; }
875
979
  {
876
980
    if (temp_buf)
877
981
    {
878
 
      free(temp_buf);
 
982
      my_free(temp_buf, MYF(0));
879
983
      temp_buf = 0;
880
984
    }
881
985
  }
884
988
    is calculated during write()
885
989
  */
886
990
  virtual int get_data_size() { return 0;}
887
 
  static Log_event* read_log_event(const char* buf, uint32_t event_len,
 
991
  static Log_event* read_log_event(const char* buf, uint event_len,
888
992
                                   const char **error,
889
993
                                   const Format_description_log_event
890
994
                                   *description_event);
899
1003
 
900
1004
  /* Return start of query time or current time */
901
1005
 
 
1006
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
902
1007
public:
903
1008
 
904
1009
  /**
975
1080
    @retval 0     Event applied successfully
976
1081
    @retval errno Error code if event application failed
977
1082
  */
978
 
  virtual int do_apply_event(Relay_log_info const *rli __attribute__((unused)))
 
1083
  virtual int do_apply_event(Relay_log_info const *rli)
979
1084
  {
980
1085
    return 0;                /* Default implementation does nothing */
981
1086
  }
1037
1142
     non-zero. The caller shall decrease the counter by one.
1038
1143
   */
1039
1144
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
1145
#endif
1040
1146
};
1041
1147
 
1042
1148
 
1387
1493
    we pass it with q_len, so we would not have to call strlen()
1388
1494
    otherwise, set it to 0, in which case, we compute it with strlen()
1389
1495
  */
1390
 
  uint32_t q_len;
1391
 
  uint32_t db_len;
1392
 
  uint16_t error_code;
 
1496
  uint32 q_len;
 
1497
  uint32 db_len;
 
1498
  uint16 error_code;
1393
1499
  ulong thread_id;
1394
1500
  /*
1395
1501
    For events created by Query_log_event::do_apply_event (and
1404
1510
    concerned) from here.
1405
1511
  */
1406
1512
 
1407
 
  uint32_t catalog_len;                 // <= 255 char; 0 means uninited
 
1513
  uint catalog_len;                     // <= 255 char; 0 means uninited
1408
1514
 
1409
1515
  /*
1410
1516
    We want to be able to store a variable number of N-bit status vars:
1426
1532
    Query_log_event, so automatically benefit from the work already done for
1427
1533
    status variables in Query_log_event.
1428
1534
 */
1429
 
  uint16_t status_vars_len;
 
1535
  uint16 status_vars_len;
1430
1536
 
1431
1537
  /*
1432
1538
    'flags2' is a second set of flags (on top of those in Log_event), for
1441
1547
  bool sql_mode_inited;
1442
1548
  bool charset_inited;
1443
1549
 
1444
 
  uint32_t flags2;
 
1550
  uint32 flags2;
1445
1551
  /* In connections sql_mode is 32 bits now but will be 64 bits soon */
1446
1552
  ulong sql_mode;
1447
1553
  ulong auto_increment_increment, auto_increment_offset;
1448
1554
  char charset[6];
1449
 
  uint32_t time_zone_len; /* 0 means uninited */
 
1555
  uint time_zone_len; /* 0 means uninited */
1450
1556
  const char *time_zone_str;
1451
 
  uint32_t lc_time_names_number; /* 0 means en_US */
1452
 
  uint32_t charset_database_number;
 
1557
  uint lc_time_names_number; /* 0 means en_US */
 
1558
  uint charset_database_number;
1453
1559
 
 
1560
#ifndef MYSQL_CLIENT
1454
1561
 
1455
1562
  Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length,
1456
1563
                  bool using_trans, bool suppress_use,
1457
1564
                  THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
1458
1565
  const char* get_db() { return db; }
 
1566
#ifdef HAVE_REPLICATION
1459
1567
  void pack_info(Protocol* protocol);
 
1568
#endif /* HAVE_REPLICATION */
 
1569
#else
 
1570
  void print_query_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info);
 
1571
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
1572
#endif
1460
1573
 
1461
1574
  Query_log_event();
1462
 
  Query_log_event(const char* buf, uint32_t event_len,
 
1575
  Query_log_event(const char* buf, uint event_len,
1463
1576
                  const Format_description_log_event *description_event,
1464
1577
                  Log_event_type event_type);
1465
1578
  ~Query_log_event()
1466
1579
  {
1467
1580
    if (data_buf)
1468
 
      free((unsigned char*) data_buf);
 
1581
      my_free((uchar*) data_buf, MYF(0));
1469
1582
  }
1470
1583
  Log_event_type get_type_code() { return QUERY_EVENT; }
 
1584
#ifndef MYSQL_CLIENT
1471
1585
  bool write(IO_CACHE* file);
1472
 
  virtual bool write_post_header_for_derived(IO_CACHE* file __attribute__((unused)))
1473
 
  { return false; }
 
1586
  virtual bool write_post_header_for_derived(IO_CACHE* file) { return FALSE; }
 
1587
#endif
1474
1588
  bool is_valid() const { return query != 0; }
1475
1589
 
1476
1590
  /*
1481
1595
  /* Writes derived event-specific part of post header. */
1482
1596
 
1483
1597
public:        /* !!! Public in this patch to allow old usage */
 
1598
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1484
1599
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
1485
1600
  virtual int do_apply_event(Relay_log_info const *rli);
1486
1601
  virtual int do_update_pos(Relay_log_info *rli);
1487
1602
 
1488
1603
  int do_apply_event(Relay_log_info const *rli,
1489
1604
                       const char *query_arg,
1490
 
                       uint32_t q_len_arg);
 
1605
                       uint32 q_len_arg);
 
1606
#endif /* HAVE_REPLICATION */
1491
1607
};
1492
1608
 
1493
1609
 
 
1610
#ifdef HAVE_REPLICATION
 
1611
 
1494
1612
/**
1495
1613
  @class Slave_log_event
1496
1614
 
1539
1657
  </tr>
1540
1658
  </table>
1541
1659
*/
1542
 
 
1543
1660
class Slave_log_event: public Log_event
1544
1661
{
1545
1662
protected:
1546
1663
  char* mem_pool;
1547
 
  void init_from_mem_pool();
 
1664
  void init_from_mem_pool(int data_size);
1548
1665
public:
1549
 
  off_t master_pos;
1550
 
  std::string master_host;
1551
 
  std::string master_log;
1552
 
  uint16_t master_port;
 
1666
  my_off_t master_pos;
 
1667
  char* master_host;
 
1668
  char* master_log;
 
1669
  int master_host_len;
 
1670
  int master_log_len;
 
1671
  uint16 master_port;
1553
1672
 
 
1673
#ifndef MYSQL_CLIENT
1554
1674
  Slave_log_event(THD* thd_arg, Relay_log_info* rli);
1555
1675
  void pack_info(Protocol* protocol);
 
1676
#else
 
1677
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
1678
#endif
1556
1679
 
1557
 
  Slave_log_event(const char* buf, uint32_t event_len);
 
1680
  Slave_log_event(const char* buf, uint event_len);
1558
1681
  ~Slave_log_event();
1559
1682
  int get_data_size();
1560
 
  bool is_valid() const { return master_host.length() != 0; }
 
1683
  bool is_valid() const { return master_host != 0; }
1561
1684
  Log_event_type get_type_code() { return SLAVE_EVENT; }
 
1685
#ifndef MYSQL_CLIENT
1562
1686
  bool write(IO_CACHE* file);
 
1687
#endif
1563
1688
 
1564
1689
private:
 
1690
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1565
1691
  virtual int do_apply_event(Relay_log_info const* rli);
 
1692
#endif
1566
1693
};
1567
1694
 
 
1695
#endif /* HAVE_REPLICATION */
 
1696
 
1568
1697
 
1569
1698
/**
1570
1699
  @class Load_log_event
1576
1705
   (1)    USE db;
1577
1706
   (2)    LOAD DATA [LOCAL] INFILE 'file_name'
1578
1707
   (3)    [REPLACE | IGNORE]
1579
 
   (4)    INTO Table 'table_name'
 
1708
   (4)    INTO TABLE 'table_name'
1580
1709
   (5)    [FIELDS
1581
1710
   (6)      [TERMINATED BY 'field_term']
1582
1711
   (7)      [[OPTIONALLY] ENCLOSED BY 'enclosed']
1768
1897
class Load_log_event: public Log_event
1769
1898
{
1770
1899
private:
1771
 
  uint32_t get_query_buffer_length();
 
1900
  uint get_query_buffer_length();
1772
1901
  void print_query(bool need_db, char *buf, char **end,
1773
1902
                   char **fn_start, char **fn_end);
1774
1903
protected:
1779
1908
public:
1780
1909
  ulong thread_id;
1781
1910
  ulong slave_proxy_id;
1782
 
  uint32_t table_name_len;
 
1911
  uint32 table_name_len;
1783
1912
  /*
1784
1913
    No need to have a catalog, as these events can only come from 4.x.
1785
1914
    TODO: this may become false if Dmitri pushes his new LOAD DATA INFILE in
1786
1915
    5.0 only (not in 4.x).
1787
1916
  */
1788
 
  uint32_t db_len;
1789
 
  uint32_t fname_len;
1790
 
  uint32_t num_fields;
 
1917
  uint32 db_len;
 
1918
  uint32 fname_len;
 
1919
  uint32 num_fields;
1791
1920
  const char* fields;
1792
 
  const unsigned char* field_lens;
1793
 
  uint32_t field_block_len;
 
1921
  const uchar* field_lens;
 
1922
  uint32 field_block_len;
1794
1923
 
1795
1924
  const char* table_name;
1796
1925
  const char* db;
1797
1926
  const char* fname;
1798
 
  uint32_t skip_lines;
 
1927
  uint32 skip_lines;
1799
1928
  sql_ex_info sql_ex;
1800
1929
  bool local_fname;
1801
1930
 
1802
1931
  /* fname doesn't point to memory inside Log_event::temp_buf  */
1803
 
  void set_fname_outside_temp_buf(const char *afname, uint32_t alen)
 
1932
  void set_fname_outside_temp_buf(const char *afname, uint alen)
1804
1933
  {
1805
1934
    fname= afname;
1806
1935
    fname_len= alen;
1807
 
    local_fname= true;
 
1936
    local_fname= TRUE;
1808
1937
  }
1809
1938
  /* fname doesn't point to memory inside Log_event::temp_buf  */
1810
1939
  int  check_fname_outside_temp_buf()
1812
1941
    return local_fname;
1813
1942
  }
1814
1943
 
 
1944
#ifndef MYSQL_CLIENT
1815
1945
  String field_lens_buf;
1816
1946
  String fields_buf;
1817
1947
 
1822
1952
  void set_fields(const char* db, List<Item> &fields_arg,
1823
1953
                  Name_resolution_context *context);
1824
1954
  const char* get_db() { return db; }
 
1955
#ifdef HAVE_REPLICATION
1825
1956
  void pack_info(Protocol* protocol);
 
1957
#endif /* HAVE_REPLICATION */
 
1958
#else
 
1959
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
1960
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info, bool commented);
 
1961
#endif
1826
1962
 
1827
1963
  /*
1828
1964
    Note that for all the events related to LOAD DATA (Load_log_event,
1830
1966
    logging of LOAD DATA is going to be changed in 4.1 or 5.0, this is only used
1831
1967
    for the common_header_len (post_header_len will not be changed).
1832
1968
  */
1833
 
  Load_log_event(const char* buf, uint32_t event_len,
 
1969
  Load_log_event(const char* buf, uint event_len,
1834
1970
                 const Format_description_log_event* description_event);
1835
1971
  ~Load_log_event()
1836
1972
  {}
1838
1974
  {
1839
1975
    return sql_ex.new_format() ? NEW_LOAD_EVENT: LOAD_EVENT;
1840
1976
  }
 
1977
#ifndef MYSQL_CLIENT
1841
1978
  bool write_data_header(IO_CACHE* file);
1842
1979
  bool write_data_body(IO_CACHE* file);
 
1980
#endif
1843
1981
  bool is_valid() const { return table_name != 0; }
1844
1982
  int get_data_size()
1845
1983
  {
1849
1987
  }
1850
1988
 
1851
1989
public:        /* !!! Public in this patch to allow old usage */
 
1990
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1852
1991
  virtual int do_apply_event(Relay_log_info const* rli)
1853
1992
  {
1854
1993
    return do_apply_event(thd->slave_net,rli,0);
1856
1995
 
1857
1996
  int do_apply_event(NET *net, Relay_log_info const *rli,
1858
1997
                     bool use_rli_only_for_errors);
 
1998
#endif
1859
1999
};
1860
2000
 
1861
2001
extern char server_version[SERVER_VERSION_LENGTH];
1901
2041
     fixed.
1902
2042
  */
1903
2043
  time_t created;
1904
 
  uint16_t binlog_version;
 
2044
  uint16 binlog_version;
1905
2045
  char server_version[ST_SERVER_VER_LEN];
1906
2046
  /*
1907
2047
    artifical_event is 1 in the case where this is a generated event that
1915
2055
  */
1916
2056
  bool dont_set_created;
1917
2057
 
 
2058
#ifndef MYSQL_CLIENT
1918
2059
  Start_log_event_v3();
 
2060
#ifdef HAVE_REPLICATION
1919
2061
  void pack_info(Protocol* protocol);
 
2062
#endif /* HAVE_REPLICATION */
 
2063
#else
 
2064
  Start_log_event_v3() {}
 
2065
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2066
#endif
1920
2067
 
1921
2068
  Start_log_event_v3(const char* buf,
1922
2069
                     const Format_description_log_event* description_event);
1923
2070
  ~Start_log_event_v3() {}
1924
2071
  Log_event_type get_type_code() { return START_EVENT_V3;}
 
2072
#ifndef MYSQL_CLIENT
1925
2073
  bool write(IO_CACHE* file);
 
2074
#endif
1926
2075
  bool is_valid() const { return 1; }
1927
2076
  int get_data_size()
1928
2077
  {
1931
2080
  virtual bool is_artificial_event() { return artificial_event; }
1932
2081
 
1933
2082
protected:
 
2083
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1934
2084
  virtual int do_apply_event(Relay_log_info const *rli);
1935
2085
  virtual enum_skip_reason do_shall_skip(Relay_log_info*)
1936
2086
  {
1943
2093
    else
1944
2094
      return Log_event::EVENT_SKIP_NOT;
1945
2095
  }
 
2096
#endif
1946
2097
};
1947
2098
 
1948
2099
 
1965
2116
     LOG_EVENT_HEADER_LEN), except FORMAT_DESCRIPTION_EVENT and ROTATE_EVENT
1966
2117
     (those have a header of size LOG_EVENT_MINIMAL_HEADER_LEN).
1967
2118
  */
1968
 
  uint8_t common_header_len;
1969
 
  uint8_t number_of_event_types;
 
2119
  uint8 common_header_len;
 
2120
  uint8 number_of_event_types;
1970
2121
  /* 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;
 
2122
  uint8 *post_header_len;
 
2123
  uchar server_version_split[3];
 
2124
  const uint8 *event_type_permutation;
1974
2125
 
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,
 
2126
  Format_description_log_event(uint8 binlog_ver, const char* server_ver=0);
 
2127
  Format_description_log_event(const char* buf, uint event_len,
1977
2128
                               const Format_description_log_event
1978
2129
                               *description_event);
1979
2130
  ~Format_description_log_event()
1980
2131
  {
1981
 
    free((unsigned char*)post_header_len);
 
2132
    my_free((uchar*)post_header_len, MYF(MY_ALLOW_ZERO_PTR));
1982
2133
  }
1983
2134
  Log_event_type get_type_code() { return FORMAT_DESCRIPTION_EVENT;}
 
2135
#ifndef MYSQL_CLIENT
1984
2136
  bool write(IO_CACHE* file);
 
2137
#endif
1985
2138
  bool is_valid() const
1986
2139
  {
1987
2140
    return ((common_header_len >= ((binlog_version==1) ? OLD_HEADER_LEN :
2001
2154
  void calc_server_version_split();
2002
2155
 
2003
2156
protected:
 
2157
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2004
2158
  virtual int do_apply_event(Relay_log_info const *rli);
2005
2159
  virtual int do_update_pos(Relay_log_info *rli);
2006
2160
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2161
#endif
2007
2162
};
2008
2163
 
2009
2164
 
2047
2202
class Intvar_log_event: public Log_event
2048
2203
{
2049
2204
public:
2050
 
  uint64_t val;
2051
 
  unsigned char type;
 
2205
  ulonglong val;
 
2206
  uchar type;
2052
2207
 
2053
 
  Intvar_log_event(THD* thd_arg,unsigned char type_arg, uint64_t val_arg)
 
2208
#ifndef MYSQL_CLIENT
 
2209
  Intvar_log_event(THD* thd_arg,uchar type_arg, ulonglong val_arg)
2054
2210
    :Log_event(thd_arg,0,0),val(val_arg),type(type_arg)
2055
2211
  {}
 
2212
#ifdef HAVE_REPLICATION
2056
2213
  void pack_info(Protocol* protocol);
 
2214
#endif /* HAVE_REPLICATION */
 
2215
#else
 
2216
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2217
#endif
2057
2218
 
2058
2219
  Intvar_log_event(const char* buf,
2059
2220
                   const Format_description_log_event *description_event);
2061
2222
  Log_event_type get_type_code() { return INTVAR_EVENT;}
2062
2223
  const char* get_var_type_name();
2063
2224
  int get_data_size() { return  9; /* sizeof(type) + sizeof(val) */;}
 
2225
#ifndef MYSQL_CLIENT
2064
2226
  bool write(IO_CACHE* file);
 
2227
#endif
2065
2228
  bool is_valid() const { return 1; }
2066
2229
 
2067
2230
private:
 
2231
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2068
2232
  virtual int do_apply_event(Relay_log_info const *rli);
2069
2233
  virtual int do_update_pos(Relay_log_info *rli);
2070
2234
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2235
#endif
2071
2236
};
2072
2237
 
2073
2238
 
2112
2277
class Rand_log_event: public Log_event
2113
2278
{
2114
2279
 public:
2115
 
  uint64_t seed1;
2116
 
  uint64_t seed2;
 
2280
  ulonglong seed1;
 
2281
  ulonglong seed2;
2117
2282
 
2118
 
  Rand_log_event(THD* thd_arg, uint64_t seed1_arg, uint64_t seed2_arg)
 
2283
#ifndef MYSQL_CLIENT
 
2284
  Rand_log_event(THD* thd_arg, ulonglong seed1_arg, ulonglong seed2_arg)
2119
2285
    :Log_event(thd_arg,0,0),seed1(seed1_arg),seed2(seed2_arg)
2120
2286
  {}
 
2287
#ifdef HAVE_REPLICATION
2121
2288
  void pack_info(Protocol* protocol);
 
2289
#endif /* HAVE_REPLICATION */
 
2290
#else
 
2291
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2292
#endif
2122
2293
 
2123
2294
  Rand_log_event(const char* buf,
2124
2295
                 const Format_description_log_event *description_event);
2125
2296
  ~Rand_log_event() {}
2126
2297
  Log_event_type get_type_code() { return RAND_EVENT;}
2127
 
  int get_data_size() { return 16; /* sizeof(uint64_t) * 2*/ }
 
2298
  int get_data_size() { return 16; /* sizeof(ulonglong) * 2*/ }
 
2299
#ifndef MYSQL_CLIENT
2128
2300
  bool write(IO_CACHE* file);
 
2301
#endif
2129
2302
  bool is_valid() const { return 1; }
2130
2303
 
2131
2304
private:
 
2305
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2132
2306
  virtual int do_apply_event(Relay_log_info const *rli);
2133
2307
  virtual int do_update_pos(Relay_log_info *rli);
2134
2308
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2309
#endif
2135
2310
};
2136
2311
 
2137
2312
/**
2142
2317
 
2143
2318
  @section Xid_log_event_binary_format Binary Format  
2144
2319
*/
 
2320
#ifdef MYSQL_CLIENT
 
2321
typedef ulonglong my_xid; // this line is the same as in handler.h
 
2322
#endif
 
2323
 
2145
2324
class Xid_log_event: public Log_event
2146
2325
{
2147
2326
 public:
2148
2327
   my_xid xid;
2149
2328
 
 
2329
#ifndef MYSQL_CLIENT
2150
2330
  Xid_log_event(THD* thd_arg, my_xid x): Log_event(thd_arg,0,0), xid(x) {}
 
2331
#ifdef HAVE_REPLICATION
2151
2332
  void pack_info(Protocol* protocol);
 
2333
#endif /* HAVE_REPLICATION */
 
2334
#else
 
2335
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2336
#endif
2152
2337
 
2153
2338
  Xid_log_event(const char* buf,
2154
2339
                const Format_description_log_event *description_event);
2155
2340
  ~Xid_log_event() {}
2156
2341
  Log_event_type get_type_code() { return XID_EVENT;}
2157
2342
  int get_data_size() { return sizeof(xid); }
 
2343
#ifndef MYSQL_CLIENT
2158
2344
  bool write(IO_CACHE* file);
 
2345
#endif
2159
2346
  bool is_valid() const { return 1; }
2160
2347
 
2161
2348
private:
 
2349
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2162
2350
  virtual int do_apply_event(Relay_log_info const *rli);
2163
2351
  enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2352
#endif
2164
2353
};
2165
2354
 
2166
2355
/**
2176
2365
{
2177
2366
public:
2178
2367
  char *name;
2179
 
  uint32_t name_len;
 
2368
  uint name_len;
2180
2369
  char *val;
2181
2370
  ulong val_len;
2182
2371
  Item_result type;
2183
 
  uint32_t charset_number;
 
2372
  uint charset_number;
2184
2373
  bool is_null;
2185
 
  User_var_log_event(THD* thd_arg __attribute__((unused)),
2186
 
                     char *name_arg, uint32_t name_len_arg,
 
2374
#ifndef MYSQL_CLIENT
 
2375
  User_var_log_event(THD* thd_arg, char *name_arg, uint name_len_arg,
2187
2376
                     char *val_arg, ulong val_len_arg, Item_result type_arg,
2188
 
                     uint32_t charset_number_arg)
 
2377
                     uint charset_number_arg)
2189
2378
    :Log_event(), name(name_arg), name_len(name_len_arg), val(val_arg),
2190
2379
    val_len(val_len_arg), type(type_arg), charset_number(charset_number_arg)
2191
2380
    { is_null= !val; }
2192
2381
  void pack_info(Protocol* protocol);
 
2382
#else
 
2383
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2384
#endif
2193
2385
 
2194
2386
  User_var_log_event(const char* buf,
2195
2387
                     const Format_description_log_event *description_event);
2196
2388
  ~User_var_log_event() {}
2197
2389
  Log_event_type get_type_code() { return USER_VAR_EVENT;}
 
2390
#ifndef MYSQL_CLIENT
2198
2391
  bool write(IO_CACHE* file);
 
2392
#endif
2199
2393
  bool is_valid() const { return 1; }
2200
2394
 
2201
2395
private:
 
2396
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2202
2397
  virtual int do_apply_event(Relay_log_info const *rli);
2203
2398
  virtual int do_update_pos(Relay_log_info *rli);
2204
2399
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2400
#endif
2205
2401
};
2206
2402
 
2207
2403
 
2216
2412
class Stop_log_event: public Log_event
2217
2413
{
2218
2414
public:
 
2415
#ifndef MYSQL_CLIENT
2219
2416
  Stop_log_event() :Log_event()
2220
2417
  {}
 
2418
#else
 
2419
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2420
#endif
2221
2421
 
2222
2422
  Stop_log_event(const char* buf,
2223
2423
                 const Format_description_log_event *description_event):
2228
2428
  bool is_valid() const { return 1; }
2229
2429
 
2230
2430
private:
 
2431
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2231
2432
  virtual int do_update_pos(Relay_log_info *rli);
2232
 
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli __attribute__((unused)))
 
2433
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli)
2233
2434
  {
2234
2435
    /*
2235
2436
      Events from ourself should be skipped, but they should not
2240
2441
    else
2241
2442
      return Log_event::EVENT_SKIP_NOT;
2242
2443
  }
 
2444
#endif
2243
2445
};
2244
2446
 
2245
2447
/**
2298
2500
    DUP_NAME= 2 // if constructor should dup the string argument
2299
2501
  };
2300
2502
  const char* new_log_ident;
2301
 
  uint64_t pos;
2302
 
  uint32_t ident_len;
2303
 
  uint32_t flags;
 
2503
  ulonglong pos;
 
2504
  uint ident_len;
 
2505
  uint flags;
 
2506
#ifndef MYSQL_CLIENT
2304
2507
  Rotate_log_event(const char* new_log_ident_arg,
2305
 
                   uint32_t ident_len_arg,
2306
 
                   uint64_t pos_arg, uint32_t flags);
 
2508
                   uint ident_len_arg,
 
2509
                   ulonglong pos_arg, uint flags);
 
2510
#ifdef HAVE_REPLICATION
2307
2511
  void pack_info(Protocol* protocol);
 
2512
#endif /* HAVE_REPLICATION */
 
2513
#else
 
2514
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2515
#endif
2308
2516
 
2309
 
  Rotate_log_event(const char* buf, uint32_t event_len,
 
2517
  Rotate_log_event(const char* buf, uint event_len,
2310
2518
                   const Format_description_log_event* description_event);
2311
2519
  ~Rotate_log_event()
2312
2520
  {
2313
2521
    if (flags & DUP_NAME)
2314
 
      free((unsigned char*) new_log_ident);
 
2522
      my_free((uchar*) new_log_ident, MYF(MY_ALLOW_ZERO_PTR));
2315
2523
  }
2316
2524
  Log_event_type get_type_code() { return ROTATE_EVENT;}
2317
2525
  int get_data_size() { return  ident_len + ROTATE_HEADER_LEN;}
2318
2526
  bool is_valid() const { return new_log_ident != 0; }
 
2527
#ifndef MYSQL_CLIENT
2319
2528
  bool write(IO_CACHE* file);
 
2529
#endif
2320
2530
 
2321
2531
private:
 
2532
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2322
2533
  virtual int do_update_pos(Relay_log_info *rli);
2323
2534
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2535
#endif
2324
2536
};
2325
2537
 
2326
2538
 
2342
2554
  */
2343
2555
  bool fake_base;
2344
2556
public:
2345
 
  unsigned char* block;
 
2557
  uchar* block;
2346
2558
  const char *event_buf;
2347
 
  uint32_t block_len;
2348
 
  uint32_t file_id;
 
2559
  uint block_len;
 
2560
  uint file_id;
2349
2561
  bool inited_from_old;
2350
2562
 
 
2563
#ifndef MYSQL_CLIENT
2351
2564
  Create_file_log_event(THD* thd, sql_exchange* ex, const char* db_arg,
2352
2565
                        const char* table_name_arg,
2353
2566
                        List<Item>& fields_arg,
2354
2567
                        enum enum_duplicates handle_dup, bool ignore,
2355
 
                        unsigned char* block_arg, uint32_t block_len_arg,
 
2568
                        uchar* block_arg, uint block_len_arg,
2356
2569
                        bool using_trans);
 
2570
#ifdef HAVE_REPLICATION
2357
2571
  void pack_info(Protocol* protocol);
 
2572
#endif /* HAVE_REPLICATION */
 
2573
#else
 
2574
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2575
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
 
2576
             bool enable_local);
 
2577
#endif
2358
2578
 
2359
 
  Create_file_log_event(const char* buf, uint32_t event_len,
 
2579
  Create_file_log_event(const char* buf, uint event_len,
2360
2580
                        const Format_description_log_event* description_event);
2361
2581
  ~Create_file_log_event()
2362
2582
  {
2363
 
    free((char*) event_buf);
 
2583
    my_free((char*) event_buf, MYF(MY_ALLOW_ZERO_PTR));
2364
2584
  }
2365
2585
 
2366
2586
  Log_event_type get_type_code()
2374
2594
            4 + 1 + block_len);
2375
2595
  }
2376
2596
  bool is_valid() const { return inited_from_old || block != 0; }
 
2597
#ifndef MYSQL_CLIENT
2377
2598
  bool write_data_header(IO_CACHE* file);
2378
2599
  bool write_data_body(IO_CACHE* file);
2379
2600
  /*
2381
2602
    write it as Load event - used on the slave
2382
2603
  */
2383
2604
  bool write_base(IO_CACHE* file);
 
2605
#endif
2384
2606
 
2385
2607
private:
 
2608
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2386
2609
  virtual int do_apply_event(Relay_log_info const *rli);
 
2610
#endif
2387
2611
};
2388
2612
 
2389
2613
 
2396
2620
class Append_block_log_event: public Log_event
2397
2621
{
2398
2622
public:
2399
 
  unsigned char* block;
2400
 
  uint32_t block_len;
2401
 
  uint32_t file_id;
 
2623
  uchar* block;
 
2624
  uint block_len;
 
2625
  uint file_id;
2402
2626
  /*
2403
2627
    'db' is filled when the event is created in mysql_load() (the
2404
2628
    event needs to have a 'db' member to be well filtered by
2412
2636
  */
2413
2637
  const char* db;
2414
2638
 
2415
 
  Append_block_log_event(THD* thd, const char* db_arg, unsigned char* block_arg,
2416
 
                         uint32_t block_len_arg, bool using_trans);
 
2639
#ifndef MYSQL_CLIENT
 
2640
  Append_block_log_event(THD* thd, const char* db_arg, uchar* block_arg,
 
2641
                         uint block_len_arg, bool using_trans);
 
2642
#ifdef HAVE_REPLICATION
2417
2643
  void pack_info(Protocol* protocol);
2418
2644
  virtual int get_create_or_append() const;
 
2645
#endif /* HAVE_REPLICATION */
 
2646
#else
 
2647
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2648
#endif
2419
2649
 
2420
 
  Append_block_log_event(const char* buf, uint32_t event_len,
 
2650
  Append_block_log_event(const char* buf, uint event_len,
2421
2651
                         const Format_description_log_event
2422
2652
                         *description_event);
2423
2653
  ~Append_block_log_event() {}
2424
2654
  Log_event_type get_type_code() { return APPEND_BLOCK_EVENT;}
2425
2655
  int get_data_size() { return  block_len + APPEND_BLOCK_HEADER_LEN ;}
2426
2656
  bool is_valid() const { return block != 0; }
 
2657
#ifndef MYSQL_CLIENT
2427
2658
  bool write(IO_CACHE* file);
2428
2659
  const char* get_db() { return db; }
 
2660
#endif
2429
2661
 
2430
2662
private:
 
2663
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2431
2664
  virtual int do_apply_event(Relay_log_info const *rli);
 
2665
#endif
2432
2666
};
2433
2667
 
2434
2668
 
2441
2675
class Delete_file_log_event: public Log_event
2442
2676
{
2443
2677
public:
2444
 
  uint32_t file_id;
 
2678
  uint file_id;
2445
2679
  const char* db; /* see comment in Append_block_log_event */
2446
2680
 
 
2681
#ifndef MYSQL_CLIENT
2447
2682
  Delete_file_log_event(THD* thd, const char* db_arg, bool using_trans);
 
2683
#ifdef HAVE_REPLICATION
2448
2684
  void pack_info(Protocol* protocol);
 
2685
#endif /* HAVE_REPLICATION */
 
2686
#else
 
2687
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2688
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
 
2689
             bool enable_local);
 
2690
#endif
2449
2691
 
2450
 
  Delete_file_log_event(const char* buf, uint32_t event_len,
 
2692
  Delete_file_log_event(const char* buf, uint event_len,
2451
2693
                        const Format_description_log_event* description_event);
2452
2694
  ~Delete_file_log_event() {}
2453
2695
  Log_event_type get_type_code() { return DELETE_FILE_EVENT;}
2454
2696
  int get_data_size() { return DELETE_FILE_HEADER_LEN ;}
2455
2697
  bool is_valid() const { return file_id != 0; }
 
2698
#ifndef MYSQL_CLIENT
2456
2699
  bool write(IO_CACHE* file);
2457
2700
  const char* get_db() { return db; }
 
2701
#endif
2458
2702
 
2459
2703
private:
 
2704
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2460
2705
  virtual int do_apply_event(Relay_log_info const *rli);
 
2706
#endif
2461
2707
};
2462
2708
 
2463
2709
 
2470
2716
class Execute_load_log_event: public Log_event
2471
2717
{
2472
2718
public:
2473
 
  uint32_t file_id;
 
2719
  uint file_id;
2474
2720
  const char* db; /* see comment in Append_block_log_event */
2475
2721
 
 
2722
#ifndef MYSQL_CLIENT
2476
2723
  Execute_load_log_event(THD* thd, const char* db_arg, bool using_trans);
 
2724
#ifdef HAVE_REPLICATION
2477
2725
  void pack_info(Protocol* protocol);
 
2726
#endif /* HAVE_REPLICATION */
 
2727
#else
 
2728
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2729
#endif
2478
2730
 
2479
 
  Execute_load_log_event(const char* buf, uint32_t event_len,
 
2731
  Execute_load_log_event(const char* buf, uint event_len,
2480
2732
                         const Format_description_log_event
2481
2733
                         *description_event);
2482
2734
  ~Execute_load_log_event() {}
2483
2735
  Log_event_type get_type_code() { return EXEC_LOAD_EVENT;}
2484
2736
  int get_data_size() { return  EXEC_LOAD_HEADER_LEN ;}
2485
2737
  bool is_valid() const { return file_id != 0; }
 
2738
#ifndef MYSQL_CLIENT
2486
2739
  bool write(IO_CACHE* file);
2487
2740
  const char* get_db() { return db; }
 
2741
#endif
2488
2742
 
2489
2743
private:
 
2744
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2490
2745
  virtual int do_apply_event(Relay_log_info const *rli);
 
2746
#endif
2491
2747
};
2492
2748
 
2493
2749
 
2503
2759
class Begin_load_query_log_event: public Append_block_log_event
2504
2760
{
2505
2761
public:
 
2762
#ifndef MYSQL_CLIENT
2506
2763
  Begin_load_query_log_event(THD* thd_arg, const char *db_arg,
2507
 
                             unsigned char* block_arg, uint32_t block_len_arg,
 
2764
                             uchar* block_arg, uint block_len_arg,
2508
2765
                             bool using_trans);
 
2766
#ifdef HAVE_REPLICATION
2509
2767
  Begin_load_query_log_event(THD* thd);
2510
2768
  int get_create_or_append() const;
2511
 
  Begin_load_query_log_event(const char* buf, uint32_t event_len,
 
2769
#endif /* HAVE_REPLICATION */
 
2770
#endif
 
2771
  Begin_load_query_log_event(const char* buf, uint event_len,
2512
2772
                             const Format_description_log_event
2513
2773
                             *description_event);
2514
2774
  ~Begin_load_query_log_event() {}
2515
2775
  Log_event_type get_type_code() { return BEGIN_LOAD_QUERY_EVENT; }
2516
2776
private:
 
2777
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2517
2778
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
2779
#endif
2518
2780
};
2519
2781
 
2520
2782
 
2536
2798
class Execute_load_query_log_event: public Query_log_event
2537
2799
{
2538
2800
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
 
2801
  uint file_id;       // file_id of temporary file
 
2802
  uint fn_pos_start;  // pointer to the part of the query that should
2541
2803
                      // be substituted
2542
 
  uint32_t fn_pos_end;    // pointer to the end of this part of query
 
2804
  uint fn_pos_end;    // pointer to the end of this part of query
2543
2805
  /*
2544
2806
    We have to store type of duplicate handling explicitly, because
2545
2807
    for LOAD DATA it also depends on LOCAL option. And this part
2548
2810
  */
2549
2811
  enum_load_dup_handling dup_handling;
2550
2812
 
 
2813
#ifndef MYSQL_CLIENT
2551
2814
  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,
 
2815
                               ulong query_length, uint fn_pos_start_arg,
 
2816
                               uint fn_pos_end_arg,
2554
2817
                               enum_load_dup_handling dup_handling_arg,
2555
2818
                               bool using_trans, bool suppress_use,
2556
2819
                               THD::killed_state
2557
2820
                               killed_err_arg= THD::KILLED_NO_VALUE);
 
2821
#ifdef HAVE_REPLICATION
2558
2822
  void pack_info(Protocol* protocol);
2559
 
  Execute_load_query_log_event(const char* buf, uint32_t event_len,
 
2823
#endif /* HAVE_REPLICATION */
 
2824
#else
 
2825
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2826
  /* Prints the query as LOAD DATA LOCAL and with rewritten filename */
 
2827
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
 
2828
             const char *local_fname);
 
2829
#endif
 
2830
  Execute_load_query_log_event(const char* buf, uint event_len,
2560
2831
                               const Format_description_log_event
2561
2832
                               *description_event);
2562
2833
  ~Execute_load_query_log_event() {}
2565
2836
  bool is_valid() const { return Query_log_event::is_valid() && file_id != 0; }
2566
2837
 
2567
2838
  ulong get_post_header_size_for_derived();
 
2839
#ifndef MYSQL_CLIENT
2568
2840
  bool write_post_header_for_derived(IO_CACHE* file);
 
2841
#endif
2569
2842
 
2570
2843
private:
 
2844
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2571
2845
  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);
 
2846
#endif
 
2847
};
 
2848
 
 
2849
 
 
2850
#ifdef MYSQL_CLIENT
 
2851
/**
 
2852
  @class Unknown_log_event
 
2853
 
 
2854
  @section Unknown_log_event_binary_format Binary Format
 
2855
*/
 
2856
class Unknown_log_event: public Log_event
 
2857
{
 
2858
public:
 
2859
  /*
 
2860
    Even if this is an unknown event, we still pass description_event to
 
2861
    Log_event's ctor, this way we can extract maximum information from the
 
2862
    event's header (the unique ID for example).
 
2863
  */
 
2864
  Unknown_log_event(const char* buf,
 
2865
                    const Format_description_log_event *description_event):
 
2866
    Log_event(buf, description_event)
 
2867
  {}
 
2868
  ~Unknown_log_event() {}
 
2869
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
 
2870
  Log_event_type get_type_code() { return UNKNOWN_EVENT;}
 
2871
  bool is_valid() const { return 1; }
 
2872
};
 
2873
#endif
 
2874
char *str_to_hex(char *to, const char *from, uint len);
2576
2875
 
2577
2876
/**
2578
2877
  @class Table_map_log_event
2701
3000
  </tr>
2702
3001
 
2703
3002
  <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>
 
3003
    <td>MYSQL_TYPE_DECIMAL</td><td>0</td>
 
3004
    <td>0</td>
 
3005
    <td>No column metadata.</td>
 
3006
  </tr>
 
3007
 
 
3008
  <tr>
 
3009
    <td>MYSQL_TYPE_TINY</td><td>1</td>
 
3010
    <td>0</td>
 
3011
    <td>No column metadata.</td>
 
3012
  </tr>
 
3013
 
 
3014
  <tr>
 
3015
    <td>MYSQL_TYPE_SHORT</td><td>2</td>
 
3016
    <td>0</td>
 
3017
    <td>No column metadata.</td>
 
3018
  </tr>
 
3019
 
 
3020
  <tr>
 
3021
    <td>MYSQL_TYPE_LONG</td><td>3</td>
 
3022
    <td>0</td>
 
3023
    <td>No column metadata.</td>
 
3024
  </tr>
 
3025
 
 
3026
  <tr>
 
3027
    <td>MYSQL_TYPE_FLOAT</td><td>4</td>
 
3028
    <td>1 byte</td>
 
3029
    <td>1 byte unsigned integer, representing the "pack_length", which
 
3030
    is equal to sizeof(float) on the server from which the event
 
3031
    originates.</td>
 
3032
  </tr>
 
3033
 
 
3034
  <tr>
 
3035
    <td>MYSQL_TYPE_DOUBLE</td><td>5</td>
2723
3036
    <td>1 byte</td>
2724
3037
    <td>1 byte unsigned integer, representing the "pack_length", which
2725
3038
    is equal to sizeof(double) on the server from which the event
2727
3040
  </tr>
2728
3041
 
2729
3042
  <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>
 
3043
    <td>MYSQL_TYPE_NULL</td><td>6</td>
 
3044
    <td>0</td>
 
3045
    <td>No column metadata.</td>
 
3046
  </tr>
 
3047
 
 
3048
  <tr>
 
3049
    <td>MYSQL_TYPE_TIMESTAMP</td><td>7</td>
 
3050
    <td>0</td>
 
3051
    <td>No column metadata.</td>
 
3052
  </tr>
 
3053
 
 
3054
  <tr>
 
3055
    <td>MYSQL_TYPE_LONGLONG</td><td>8</td>
 
3056
    <td>0</td>
 
3057
    <td>No column metadata.</td>
 
3058
  </tr>
 
3059
 
 
3060
  <tr>
 
3061
    <td>MYSQL_TYPE_INT24</td><td>9</td>
 
3062
    <td>0</td>
 
3063
    <td>No column metadata.</td>
 
3064
  </tr>
 
3065
 
 
3066
  <tr>
 
3067
    <td>MYSQL_TYPE_DATE</td><td>10</td>
 
3068
    <td>0</td>
 
3069
    <td>No column metadata.</td>
 
3070
  </tr>
 
3071
 
 
3072
  <tr>
 
3073
    <td>MYSQL_TYPE_TIME</td><td>11</td>
 
3074
    <td>0</td>
 
3075
    <td>No column metadata.</td>
 
3076
  </tr>
 
3077
 
 
3078
  <tr>
 
3079
    <td>MYSQL_TYPE_DATETIME</td><td>12</td>
 
3080
    <td>0</td>
 
3081
    <td>No column metadata.</td>
 
3082
  </tr>
 
3083
 
 
3084
  <tr>
 
3085
    <td>MYSQL_TYPE_YEAR</td><td>13</td>
 
3086
    <td>0</td>
 
3087
    <td>No column metadata.</td>
 
3088
  </tr>
 
3089
 
 
3090
  <tr>
 
3091
    <td><i>MYSQL_TYPE_NEWDATE</i></td><td><i>14</i></td>
2773
3092
    <td>&ndash;</td>
2774
3093
    <td><i>This enumeration value is only used internally and cannot
2775
3094
    exist in a binlog.</i></td>
2776
3095
  </tr>
2777
3096
 
2778
3097
  <tr>
2779
 
    <td>DRIZZLE_TYPE_VARCHAR</td><td>15</td>
 
3098
    <td>MYSQL_TYPE_VARCHAR</td><td>15</td>
2780
3099
    <td>2 bytes</td>
2781
3100
    <td>2 byte unsigned integer representing the maximum length of
2782
3101
    the string.</td>
2783
3102
  </tr>
2784
3103
 
2785
3104
  <tr>
2786
 
    <td>DRIZZLE_TYPE_NEWDECIMAL</td><td>246</td>
 
3105
    <td>MYSQL_TYPE_BIT</td><td>16</td>
 
3106
    <td>2 bytes</td>
 
3107
    <td>A 1 byte unsigned int representing the length in bits of the
 
3108
    bitfield (0 to 64), followed by a 1 byte unsigned int
 
3109
    representing the number of bytes occupied by the bitfield.  The
 
3110
    number of bytes is either int((length+7)/8) or int(length/8).</td>
 
3111
  </tr>
 
3112
 
 
3113
  <tr>
 
3114
    <td>MYSQL_TYPE_NEWDECIMAL</td><td>246</td>
2787
3115
    <td>2 bytes</td>
2788
3116
    <td>A 1 byte unsigned int representing the precision, followed
2789
3117
    by a 1 byte unsigned int representing the number of decimals.</td>
2790
3118
  </tr>
2791
3119
 
2792
3120
  <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>
 
3121
    <td><i>MYSQL_TYPE_ENUM</i></td><td><i>247</i></td>
 
3122
    <td>&ndash;</td>
 
3123
    <td><i>This enumeration value is only used internally and cannot
 
3124
    exist in a binlog.</i></td>
 
3125
  </tr>
 
3126
 
 
3127
  <tr>
 
3128
    <td><i>MYSQL_TYPE_SET</i></td><td><i>248</i></td>
 
3129
    <td>&ndash;</td>
 
3130
    <td><i>This enumeration value is only used internally and cannot
 
3131
    exist in a binlog.</i></td>
 
3132
  </tr>
 
3133
 
 
3134
  <tr>
 
3135
    <td>MYSQL_TYPE_TINY_BLOB</td><td>249</td>
 
3136
    <td>&ndash;</td>
 
3137
    <td><i>This enumeration value is only used internally and cannot
 
3138
    exist in a binlog.</i></td>
 
3139
  </tr>
 
3140
 
 
3141
  <tr>
 
3142
    <td><i>MYSQL_TYPE_MEDIUM_BLOB</i></td><td><i>250</i></td>
 
3143
    <td>&ndash;</td>
 
3144
    <td><i>This enumeration value is only used internally and cannot
 
3145
    exist in a binlog.</i></td>
 
3146
  </tr>
 
3147
 
 
3148
  <tr>
 
3149
    <td><i>MYSQL_TYPE_LONG_BLOB</i></td><td><i>251</i></td>
 
3150
    <td>&ndash;</td>
 
3151
    <td><i>This enumeration value is only used internally and cannot
 
3152
    exist in a binlog.</i></td>
 
3153
  </tr>
 
3154
 
 
3155
  <tr>
 
3156
    <td>MYSQL_TYPE_BLOB</td><td>252</td>
2808
3157
    <td>1 byte</td>
2809
3158
    <td>The pack length, i.e., the number of bytes needed to represent
2810
3159
    the length of the blob: 1, 2, 3, or 4.</td>
2811
3160
  </tr>
2812
3161
 
2813
3162
  <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).
 
3163
    <td>MYSQL_TYPE_VAR_STRING</td><td>253</td>
 
3164
    <td>2 bytes</td>
 
3165
    <td>This is used to store both strings and enumeration values.
 
3166
    The first byte is a enumeration value storing the <i>real
 
3167
    type</i>, which may be either MYSQL_TYPE_VAR_STRING or
 
3168
    MYSQL_TYPE_ENUM.  The second byte is a 1 byte unsigned integer
 
3169
    representing the field size, i.e., the number of bytes needed to
 
3170
    store the length of the string.</td>
 
3171
  </tr>
 
3172
 
 
3173
  <tr>
 
3174
    <td>MYSQL_TYPE_STRING</td><td>254</td>
 
3175
    <td>2 bytes</td>
 
3176
    <td>The first byte is always MYSQL_TYPE_VAR_STRING (i.e., 253).
2817
3177
    The second byte is the field size, i.e., the number of bytes in
2818
3178
    the representation of size of the string: 3 or 4.</td>
2819
3179
  </tr>
2820
3180
 
 
3181
  <tr>
 
3182
    <td>MYSQL_TYPE_GEOMETRY</td><td>255</td>
 
3183
    <td>1 byte</td>
 
3184
    <td>The pack length, i.e., the number of bytes needed to represent
 
3185
    the length of the geometry: 1, 2, 3, or 4.</td>
 
3186
  </tr>
 
3187
 
2821
3188
  </table>
2822
3189
*/
2823
3190
class Table_map_log_event : public Log_event
2853
3220
    ENUM_FLAG_COUNT
2854
3221
  };
2855
3222
 
2856
 
  typedef uint16_t flag_set;
 
3223
  typedef uint16 flag_set;
2857
3224
 
2858
3225
  /* Special constants representing sets of flags */
2859
3226
  enum 
2865
3232
  void clear_flags(flag_set flag) { m_flags &= ~flag; }
2866
3233
  flag_set get_flags(flag_set flag) const { return m_flags & flag; }
2867
3234
 
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, 
 
3235
#ifndef MYSQL_CLIENT
 
3236
  Table_map_log_event(THD *thd, TABLE *tbl, ulong tid, 
 
3237
                      bool is_transactional, uint16 flags);
 
3238
#endif
 
3239
#ifdef HAVE_REPLICATION
 
3240
  Table_map_log_event(const char *buf, uint event_len, 
2871
3241
                      const Format_description_log_event *description_event);
 
3242
#endif
2872
3243
 
2873
3244
  ~Table_map_log_event();
2874
3245
 
2876
3247
  virtual bool is_valid() const { return m_memory != NULL; /* we check malloc */ }
2877
3248
 
2878
3249
  virtual int get_data_size() { return m_data_size; } 
 
3250
#ifndef MYSQL_CLIENT
2879
3251
  virtual int save_field_metadata();
2880
3252
  virtual bool write_data_header(IO_CACHE *file);
2881
3253
  virtual bool write_data_body(IO_CACHE *file);
2882
3254
  virtual const char *get_db() { return m_dbnam; }
 
3255
#endif
 
3256
 
 
3257
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2883
3258
  virtual void pack_info(Protocol *protocol);
 
3259
#endif
 
3260
 
 
3261
#ifdef MYSQL_CLIENT
 
3262
  virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 
3263
#endif
 
3264
 
2884
3265
 
2885
3266
private:
 
3267
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2886
3268
  virtual int do_apply_event(Relay_log_info const *rli);
2887
3269
  virtual int do_update_pos(Relay_log_info *rli);
2888
3270
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
 
3271
#endif
2889
3272
 
2890
 
  Table         *m_table;
 
3273
#ifndef MYSQL_CLIENT
 
3274
  TABLE         *m_table;
 
3275
#endif
2891
3276
  char const    *m_dbnam;
2892
3277
  size_t         m_dblen;
2893
3278
  char const    *m_tblnam;
2894
3279
  size_t         m_tbllen;
2895
3280
  ulong          m_colcnt;
2896
 
  unsigned char         *m_coltype;
 
3281
  uchar         *m_coltype;
2897
3282
 
2898
 
  unsigned char         *m_memory;
 
3283
  uchar         *m_memory;
2899
3284
  ulong          m_table_id;
2900
3285
  flag_set       m_flags;
2901
3286
 
2902
3287
  size_t         m_data_size;
2903
3288
 
2904
 
  unsigned char          *m_field_metadata;        // buffer for field metadata
 
3289
  uchar          *m_field_metadata;        // buffer for field metadata
2905
3290
  /*
2906
3291
    The size of field metadata buffer set by calling save_field_metadata()
2907
3292
  */
2908
3293
  ulong          m_field_metadata_size;   
2909
 
  unsigned char         *m_null_bits;
2910
 
  unsigned char         *m_meta_memory;
 
3294
  uchar         *m_null_bits;
 
3295
  uchar         *m_meta_memory;
2911
3296
};
2912
3297
 
2913
3298
 
2967
3352
    COMPLETE_ROWS_F = (1U << 3)
2968
3353
  };
2969
3354
 
2970
 
  typedef uint16_t flag_set;
 
3355
  typedef uint16 flag_set;
2971
3356
 
2972
3357
  /* Special constants representing sets of flags */
2973
3358
  enum 
2981
3366
  void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; }
2982
3367
  flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; }
2983
3368
 
 
3369
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2984
3370
  virtual void pack_info(Protocol *protocol);
2985
 
 
2986
 
  int add_row_data(unsigned char *data, size_t length)
 
3371
#endif
 
3372
 
 
3373
#ifdef MYSQL_CLIENT
 
3374
  /* not for direct call, each derived has its own ::print() */
 
3375
  virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info)= 0;
 
3376
#endif
 
3377
 
 
3378
#ifndef MYSQL_CLIENT
 
3379
  int add_row_data(uchar *data, size_t length)
2987
3380
  {
2988
3381
    return do_add_row_data(data,length); 
2989
3382
  }
 
3383
#endif
2990
3384
 
2991
3385
  /* Member functions to implement superclass interface */
2992
3386
  virtual int get_data_size();
2995
3389
  size_t get_width() const          { return m_width; }
2996
3390
  ulong get_table_id() const        { return m_table_id; }
2997
3391
 
 
3392
#ifndef MYSQL_CLIENT
2998
3393
  virtual bool write_data_header(IO_CACHE *file);
2999
3394
  virtual bool write_data_body(IO_CACHE *file);
3000
3395
  virtual const char *get_db() { return m_table->s->db.str; }
 
3396
#endif
3001
3397
  /*
3002
3398
    Check that malloc() succeeded in allocating memory for the rows
3003
3399
    buffer and the COLS vector. Checking that an Update_rows_log_event
3009
3405
    return m_rows_buf && m_cols.bitmap;
3010
3406
  }
3011
3407
 
3012
 
  uint32_t     m_row_count;         /* The number of rows added to the event */
 
3408
  uint     m_row_count;         /* The number of rows added to the event */
3013
3409
 
3014
3410
protected:
3015
3411
  /* 
3016
3412
     The constructors are protected since you're supposed to inherit
3017
3413
     this class, not create instances of this class.
3018
3414
  */
3019
 
  Rows_log_event(THD*, Table*, ulong table_id, 
 
3415
#ifndef MYSQL_CLIENT
 
3416
  Rows_log_event(THD*, TABLE*, ulong table_id, 
3020
3417
                 MY_BITMAP const *cols, bool is_transactional);
3021
 
  Rows_log_event(const char *row_data, uint32_t event_len, 
 
3418
#endif
 
3419
  Rows_log_event(const char *row_data, uint event_len, 
3022
3420
                 Log_event_type event_type,
3023
3421
                 const Format_description_log_event *description_event);
3024
3422
 
3025
 
  virtual int do_add_row_data(unsigned char *data, size_t length);
3026
 
 
3027
 
  Table *m_table;               /* The table the rows belong to */
 
3423
#ifdef MYSQL_CLIENT
 
3424
  void print_helper(FILE *, PRINT_EVENT_INFO *, char const *const name);
 
3425
#endif
 
3426
 
 
3427
#ifndef MYSQL_CLIENT
 
3428
  virtual int do_add_row_data(uchar *data, size_t length);
 
3429
#endif
 
3430
 
 
3431
#ifndef MYSQL_CLIENT
 
3432
  TABLE *m_table;               /* The table the rows belong to */
 
3433
#endif
3028
3434
  ulong       m_table_id;       /* Table ID */
3029
3435
  MY_BITMAP   m_cols;           /* Bitmap denoting columns available */
3030
3436
  ulong       m_width;          /* The width of the columns bitmap */
3040
3446
  ulong       m_master_reclength; /* Length of record on master side */
3041
3447
 
3042
3448
  /* 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)];
 
3449
  uint32    m_bitbuf[128/(sizeof(uint32)*8)];
 
3450
  uint32    m_bitbuf_ai[128/(sizeof(uint32)*8)];
3045
3451
 
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 */
 
3452
  uchar    *m_rows_buf;         /* The rows in packed format */
 
3453
  uchar    *m_rows_cur;         /* One-after the end of the data */
 
3454
  uchar    *m_rows_end;         /* One-after the end of the allocated space */
3049
3455
 
3050
3456
  flag_set m_flags;             /* Flags for row-level events */
3051
3457
 
3052
3458
  /* helper functions */
3053
3459
 
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 */
 
3460
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
 
3461
  const uchar *m_curr_row;     /* Start of the row being processed */
 
3462
  const uchar *m_curr_row_end; /* One-after the end of the current row */
 
3463
  uchar    *m_key;      /* Buffer to keep key value during searches */
3057
3464
 
3058
3465
  int find_row(const Relay_log_info *const);
3059
3466
  int write_row(const Relay_log_info *const, const bool);
3062
3469
  int unpack_current_row(const Relay_log_info *const rli,
3063
3470
                         MY_BITMAP const *cols)
3064
3471
  { 
3065
 
    assert(m_table);
 
3472
    DBUG_ASSERT(m_table);
3066
3473
    ASSERT_OR_RETURN_ERROR(m_curr_row < m_rows_end, HA_ERR_CORRUPT_EVENT);
3067
3474
    int const result= ::unpack_row(rli, m_table, m_width, m_curr_row, cols,
3068
3475
                                   &m_curr_row_end, &m_master_reclength);
3071
3478
    ASSERT_OR_RETURN_ERROR(m_curr_row_end <= m_rows_end, HA_ERR_CORRUPT_EVENT);
3072
3479
    return result;
3073
3480
  }
 
3481
#endif
3074
3482
 
3075
3483
private:
3076
3484
 
 
3485
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3077
3486
  virtual int do_apply_event(Relay_log_info const *rli);
3078
3487
  virtual int do_update_pos(Relay_log_info *rli);
3079
3488
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
3128
3537
      
3129
3538
  */
3130
3539
  virtual int do_exec_row(const Relay_log_info *const rli) = 0;
 
3540
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
3131
3541
 
3132
3542
  friend class Old_rows_log_event;
3133
3543
};
3150
3560
    TYPE_CODE = WRITE_ROWS_EVENT
3151
3561
  };
3152
3562
 
3153
 
  Write_rows_log_event(THD*, Table*, ulong table_id, 
 
3563
#if !defined(MYSQL_CLIENT)
 
3564
  Write_rows_log_event(THD*, TABLE*, ulong table_id, 
3154
3565
                       bool is_transactional);
3155
 
  Write_rows_log_event(const char *buf, uint32_t event_len, 
 
3566
#endif
 
3567
#ifdef HAVE_REPLICATION
 
3568
  Write_rows_log_event(const char *buf, uint event_len, 
3156
3569
                       const Format_description_log_event *description_event);
3157
 
  static bool binlog_row_logging_function(THD *thd, Table *table,
 
3570
#endif
 
3571
#if !defined(MYSQL_CLIENT) 
 
3572
  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3158
3573
                                          bool is_transactional,
3159
 
                                          const unsigned char *before_record
 
3574
                                          const uchar *before_record
3160
3575
                                          __attribute__((unused)),
3161
 
                                          const unsigned char *after_record)
 
3576
                                          const uchar *after_record)
3162
3577
  {
3163
3578
    return thd->binlog_write_row(table, is_transactional, after_record);
3164
3579
  }
 
3580
#endif
3165
3581
 
3166
3582
private:
3167
3583
  virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3168
3584
 
 
3585
#ifdef MYSQL_CLIENT
 
3586
  void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 
3587
#endif
 
3588
 
 
3589
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3169
3590
  virtual int do_before_row_operations(const Slave_reporting_capability *const);
3170
3591
  virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3171
3592
  virtual int do_exec_row(const Relay_log_info *const);
 
3593
#endif
3172
3594
};
3173
3595
 
3174
3596
 
3193
3615
    TYPE_CODE = UPDATE_ROWS_EVENT
3194
3616
  };
3195
3617
 
3196
 
  Update_rows_log_event(THD*, Table*, ulong table_id,
 
3618
#ifndef MYSQL_CLIENT
 
3619
  Update_rows_log_event(THD*, TABLE*, ulong table_id,
3197
3620
                        bool is_transactional);
3198
3621
 
3199
3622
  void init(MY_BITMAP const *cols);
 
3623
#endif
3200
3624
 
3201
3625
  virtual ~Update_rows_log_event();
3202
3626
 
3203
 
  Update_rows_log_event(const char *buf, uint32_t event_len, 
 
3627
#ifdef HAVE_REPLICATION
 
3628
  Update_rows_log_event(const char *buf, uint event_len, 
3204
3629
                        const Format_description_log_event *description_event);
 
3630
#endif
3205
3631
 
3206
 
  static bool binlog_row_logging_function(THD *thd, Table *table,
 
3632
#if !defined(MYSQL_CLIENT) 
 
3633
  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3207
3634
                                          bool is_transactional,
3208
 
                                          const unsigned char *before_record,
3209
 
                                          const unsigned char *after_record)
 
3635
                                          const uchar *before_record,
 
3636
                                          const uchar *after_record)
3210
3637
  {
3211
3638
    return thd->binlog_update_row(table, is_transactional,
3212
3639
                                  before_record, after_record);
3213
3640
  }
 
3641
#endif
3214
3642
 
3215
3643
  virtual bool is_valid() const
3216
3644
  {
3220
3648
protected:
3221
3649
  virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3222
3650
 
 
3651
#ifdef MYSQL_CLIENT
 
3652
  void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 
3653
#endif
 
3654
 
 
3655
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3223
3656
  virtual int do_before_row_operations(const Slave_reporting_capability *const);
3224
3657
  virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3225
3658
  virtual int do_exec_row(const Relay_log_info *const);
 
3659
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
3226
3660
};
3227
3661
 
3228
3662
/**
3254
3688
    TYPE_CODE = DELETE_ROWS_EVENT
3255
3689
  };
3256
3690
 
3257
 
  Delete_rows_log_event(THD*, Table*, ulong, 
 
3691
#ifndef MYSQL_CLIENT
 
3692
  Delete_rows_log_event(THD*, TABLE*, ulong, 
3258
3693
                        bool is_transactional);
3259
 
  Delete_rows_log_event(const char *buf, uint32_t event_len, 
 
3694
#endif
 
3695
#ifdef HAVE_REPLICATION
 
3696
  Delete_rows_log_event(const char *buf, uint event_len, 
3260
3697
                        const Format_description_log_event *description_event);
3261
 
  static bool binlog_row_logging_function(THD *thd, Table *table,
 
3698
#endif
 
3699
#if !defined(MYSQL_CLIENT) 
 
3700
  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3262
3701
                                          bool is_transactional,
3263
 
                                          const unsigned char *before_record,
3264
 
                                          const unsigned char *after_record
 
3702
                                          const uchar *before_record,
 
3703
                                          const uchar *after_record
3265
3704
                                          __attribute__((unused)))
3266
3705
  {
3267
3706
    return thd->binlog_delete_row(table, is_transactional, before_record);
3268
3707
  }
 
3708
#endif
3269
3709
  
3270
3710
protected:
3271
3711
  virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3272
3712
 
 
3713
#ifdef MYSQL_CLIENT
 
3714
  void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 
3715
#endif
 
3716
 
 
3717
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3273
3718
  virtual int do_before_row_operations(const Slave_reporting_capability *const);
3274
3719
  virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3275
3720
  virtual int do_exec_row(const Relay_log_info *const);
 
3721
#endif
3276
3722
};
3277
3723
 
3278
3724
 
3314
3760
*/
3315
3761
class Incident_log_event : public Log_event {
3316
3762
public:
 
3763
#ifndef MYSQL_CLIENT
3317
3764
  Incident_log_event(THD *thd_arg, Incident incident)
3318
 
    : Log_event(thd_arg, 0, false), m_incident(incident)
 
3765
    : Log_event(thd_arg, 0, FALSE), m_incident(incident)
3319
3766
  {
 
3767
    DBUG_ENTER("Incident_log_event::Incident_log_event");
 
3768
    DBUG_PRINT("enter", ("m_incident: %d", m_incident));
3320
3769
    m_message.str= NULL;                    /* Just as a precaution */
3321
3770
    m_message.length= 0;
3322
 
    return;
 
3771
    DBUG_VOID_RETURN;
3323
3772
  }
3324
3773
 
3325
3774
  Incident_log_event(THD *thd_arg, Incident incident, LEX_STRING const msg)
3326
 
    : Log_event(thd_arg, 0, false), m_incident(incident)
 
3775
    : Log_event(thd_arg, 0, FALSE), m_incident(incident)
3327
3776
  {
 
3777
    DBUG_ENTER("Incident_log_event::Incident_log_event");
 
3778
    DBUG_PRINT("enter", ("m_incident: %d", m_incident));
3328
3779
    m_message= msg;
3329
 
    return;
 
3780
    DBUG_VOID_RETURN;
3330
3781
  }
 
3782
#endif
3331
3783
 
 
3784
#ifndef MYSQL_CLIENT
3332
3785
  void pack_info(Protocol*);
 
3786
#endif
3333
3787
 
3334
 
  Incident_log_event(const char *buf, uint32_t event_len,
 
3788
  Incident_log_event(const char *buf, uint event_len,
3335
3789
                     const Format_description_log_event *descr_event);
3336
3790
 
3337
3791
  virtual ~Incident_log_event();
3338
3792
 
 
3793
#ifdef MYSQL_CLIENT
 
3794
  virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
 
3795
#endif
 
3796
 
 
3797
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3339
3798
  virtual int do_apply_event(Relay_log_info const *rli);
 
3799
#endif
3340
3800
 
3341
3801
  virtual bool write_data_header(IO_CACHE *file);
3342
3802
  virtual bool write_data_body(IO_CACHE *file);
3355
3815
  LEX_STRING m_message;
3356
3816
};
3357
3817
 
3358
 
int append_query_string(const CHARSET_INFO * const csinfo,
3359
 
                        String const *from, String *to);
3360
 
 
3361
3818
static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache,
3362
3819
                                                       FILE *file)
3363
3820
{
3364
3821
  return         
3365
3822
    my_b_copy_to_file(cache, file) ||
3366
 
    reinit_io_cache(cache, WRITE_CACHE, 0, false, true);
 
3823
    reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE);
3367
3824
}
3368
3825
 
 
3826
#ifndef MYSQL_CLIENT
3369
3827
/*****************************************************************************
3370
3828
 
3371
3829
  Heartbeat Log Event class
3384
3842
class Heartbeat_log_event: public Log_event
3385
3843
{
3386
3844
public:
3387
 
  Heartbeat_log_event(const char* buf, uint32_t event_len,
 
3845
  Heartbeat_log_event(const char* buf, uint event_len,
3388
3846
                      const Format_description_log_event* description_event);
3389
3847
  Log_event_type get_type_code() { return HEARTBEAT_LOG_EVENT; }
3390
3848
  bool is_valid() const
3393
3851
              log_pos >= BIN_LOG_HEADER_SIZE);
3394
3852
    }
3395
3853
  const char * get_log_ident() { return log_ident; }
3396
 
  uint32_t get_ident_len() { return ident_len; }
 
3854
  uint get_ident_len() { return ident_len; }
3397
3855
  
3398
3856
private:
3399
3857
  const char* log_ident;
3400
 
  uint32_t ident_len;
 
3858
  uint ident_len;
3401
3859
};
 
3860
#endif
3402
3861
 
3403
3862
/**
3404
3863
  @} (end of group Replication)
3405
3864
*/
3406
3865
 
3407
 
#endif /* DRIZZLED_LOG_EVENT_H */
 
3866
#endif /* _log_event_h */