ruby-binlog 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -24,6 +24,7 @@ gem install ruby-binlog
24
24
  puts event.query
25
25
  when Binlog::RowEvent
26
26
  puts event.event_type
27
+ p event.columns
27
28
  p event.rows
28
29
  else
29
30
  puts "(#{event.event_type})"
data/ext/Makefile CHANGED
@@ -9,33 +9,33 @@ hdrdir = $(topdir)
9
9
  VPATH = $(srcdir):$(topdir):$(hdrdir)
10
10
  prefix = $(DESTDIR)/usr
11
11
  exec_prefix = $(DESTDIR)/usr
12
- mandir = $(DESTDIR)/usr/share/man
13
- localedir = $(datarootdir)/locale
14
- vendordir = $(DESTDIR)/usr/lib/ruby
15
- datadir = $(DESTDIR)/usr/share
16
- sitearchdir = $(libdir)/ruby/site_ruby/$(ruby_version)/$(sitearch)
17
- libexecdir = $(DESTDIR)/usr/libexec
18
- psdir = $(docdir)
12
+ localstatedir = $(DESTDIR)/var
19
13
  sysconfdir = $(DESTDIR)/etc
20
- bindir = $(DESTDIR)/usr/bin
21
14
  includedir = $(DESTDIR)/usr/include
22
- vendorarchdir = $(libdir)/ruby/$(ruby_version)/$(sitearch)
15
+ sbindir = $(DESTDIR)/usr/sbin
16
+ mandir = $(DESTDIR)/usr/share/man
17
+ rubylibdir = $(vendordir)/$(ruby_version)
23
18
  sitedir = $(DESTDIR)/usr/lib/ruby/site_ruby
24
- libdir = $(DESTDIR)/usr/lib64
19
+ localedir = $(datarootdir)/locale
20
+ dvidir = $(docdir)
21
+ docdir = $(datarootdir)/doc/$(PACKAGE)
22
+ vendorarchdir = $(libdir)/ruby/$(ruby_version)/$(sitearch)
25
23
  sitelibdir = $(sitedir)/$(ruby_version)
26
- rubylibdir = $(vendordir)/$(ruby_version)
27
- localstatedir = $(DESTDIR)/var
24
+ vendordir = $(DESTDIR)/usr/lib/ruby
28
25
  infodir = $(DESTDIR)/usr/share/info
29
- docdir = $(datarootdir)/doc/$(PACKAGE)
26
+ htmldir = $(docdir)
27
+ pdfdir = $(docdir)
28
+ psdir = $(docdir)
29
+ sitearchdir = $(libdir)/ruby/site_ruby/$(ruby_version)/$(sitearch)
30
+ vendorlibdir = $(vendordir)/$(ruby_version)
30
31
  datarootdir = $(prefix)/share
31
- archdir = $(libdir)/ruby/$(ruby_version)/$(sitearch)
32
32
  oldincludedir = $(DESTDIR)/usr/include
33
+ bindir = $(DESTDIR)/usr/bin
34
+ libdir = $(DESTDIR)/usr/lib64
33
35
  sharedstatedir = $(DESTDIR)/var/lib
34
- htmldir = $(docdir)
35
- dvidir = $(docdir)
36
- vendorlibdir = $(vendordir)/$(ruby_version)
37
- pdfdir = $(docdir)
38
- sbindir = $(DESTDIR)/usr/sbin
36
+ archdir = $(libdir)/ruby/$(ruby_version)/$(sitearch)
37
+ datadir = $(DESTDIR)/usr/share
38
+ libexecdir = $(DESTDIR)/usr/libexec
39
39
 
40
40
  CC = gcc
41
41
  LIBRUBY = $(LIBRUBY_SO)
@@ -87,8 +87,8 @@ extout_prefix =
87
87
  target_prefix =
88
88
  LOCAL_LIBS =
89
89
  LIBS = $(LIBRUBYARG_SHARED) -lreplication -lstdc++ -lpthread -lrt -ldl -lcrypt -lm -lc
90
- SRCS = ruby_binlog_xid_event.cpp ruby_binlog_rotate_event.cpp ruby_binlog_format_event.cpp ruby_binlog_user_var_event.cpp ruby_binlog.cpp ruby_binlog_table_map_event.cpp ruby_binlog_row_event.cpp ruby_binlog_event.cpp ruby_binlog_query_event.cpp ruby_binlog_unimplemented_event.cpp ruby_binlog_int_var_event.cpp ruby_binlog_incident_event.cpp
91
- OBJS = ruby_binlog_xid_event.o ruby_binlog_rotate_event.o ruby_binlog_format_event.o ruby_binlog_user_var_event.o ruby_binlog.o ruby_binlog_table_map_event.o ruby_binlog_row_event.o ruby_binlog_event.o ruby_binlog_query_event.o ruby_binlog_unimplemented_event.o ruby_binlog_int_var_event.o ruby_binlog_incident_event.o
90
+ SRCS = ruby_binlog_xid_event.cpp ruby_binlog_rotate_event.cpp ruby_binlog_format_event.cpp ruby_binlog_user_var_event.cpp ruby_binlog.cpp ruby_binlog_table_map_event.cpp ruby_binlog_get_field_type_str.cpp ruby_binlog_row_event.cpp ruby_binlog_event.cpp ruby_binlog_query_event.cpp ruby_binlog_unimplemented_event.cpp ruby_binlog_int_var_event.cpp ruby_binlog_incident_event.cpp
91
+ OBJS = ruby_binlog_xid_event.o ruby_binlog_rotate_event.o ruby_binlog_format_event.o ruby_binlog_user_var_event.o ruby_binlog.o ruby_binlog_table_map_event.o ruby_binlog_get_field_type_str.o ruby_binlog_row_event.o ruby_binlog_event.o ruby_binlog_query_event.o ruby_binlog_unimplemented_event.o ruby_binlog_int_var_event.o ruby_binlog_incident_event.o
92
92
  TARGET = binlog
93
93
  DLLIB = $(TARGET).so
94
94
  EXTSTATIC =
data/ext/binlog.so CHANGED
Binary file
data/ext/ruby_binlog.h CHANGED
@@ -23,6 +23,12 @@
23
23
 
24
24
  extern VALUE rb_mBinlog;
25
25
 
26
+ namespace ruby {
27
+ namespace binlog {
28
+ const char* get_field_type_str(mysql::system::enum_field_types type);
29
+ } // namespace binlog
30
+ } // namespace ruby
31
+
26
32
  extern "C" {
27
33
  #ifdef _WIN32
28
34
  __declspec(dllexport)
data/ext/ruby_binlog.o CHANGED
Binary file
@@ -92,6 +92,7 @@ struct TableMapEvent : public Event {
92
92
  static VALUE get_db_name(VALUE self);
93
93
  static VALUE get_table_name(VALUE self);
94
94
  static VALUE get_columns(VALUE self);
95
+ static VALUE get_column_types(VALUE self);
95
96
  static VALUE get_metadata(VALUE self);
96
97
  static VALUE get_null_bits(VALUE self);
97
98
  };
@@ -109,6 +110,7 @@ struct RowEvent : public Event {
109
110
  static VALUE get_table_id(VALUE self);
110
111
  static VALUE get_db_name(VALUE self);
111
112
  static VALUE get_table_name(VALUE self);
113
+ static VALUE get_column_types(VALUE self);
112
114
  static VALUE get_flags(VALUE self);
113
115
  static VALUE get_columns_len(VALUE self);
114
116
  static VALUE get_null_bits_len(VALUE self);
Binary file
Binary file
@@ -0,0 +1,41 @@
1
+ #include "ruby_binlog.h"
2
+
3
+ namespace ruby {
4
+ namespace binlog {
5
+
6
+ const char* get_field_type_str(mysql::system::enum_field_types type) {
7
+ switch(type) {
8
+ case mysql::system::MYSQL_TYPE_DECIMAL: return "DECIMAL"; break;
9
+ case mysql::system::MYSQL_TYPE_TINY: return "TINY"; break;
10
+ case mysql::system::MYSQL_TYPE_SHORT: return "SHORT"; break;
11
+ case mysql::system::MYSQL_TYPE_LONG: return "LONG"; break;
12
+ case mysql::system::MYSQL_TYPE_FLOAT: return "FLOAT"; break;
13
+ case mysql::system::MYSQL_TYPE_DOUBLE: return "DOUBLE"; break;
14
+ case mysql::system::MYSQL_TYPE_NULL: return "NULL"; break;
15
+ case mysql::system::MYSQL_TYPE_TIMESTAMP: return "TIMESTAMP"; break;
16
+ case mysql::system::MYSQL_TYPE_LONGLONG: return "LONGLONG"; break;
17
+ case mysql::system::MYSQL_TYPE_INT24: return "INT24"; break;
18
+ case mysql::system::MYSQL_TYPE_DATE: return "DATE"; break;
19
+ case mysql::system::MYSQL_TYPE_TIME: return "TIME"; break;
20
+ case mysql::system::MYSQL_TYPE_DATETIME: return "DATETIME"; break;
21
+ case mysql::system::MYSQL_TYPE_YEAR: return "YEAR"; break;
22
+ case mysql::system::MYSQL_TYPE_NEWDATE: return "NEWDATE"; break;
23
+ case mysql::system::MYSQL_TYPE_VARCHAR: return "VARCHAR"; break;
24
+ case mysql::system::MYSQL_TYPE_BIT: return "BIT"; break;
25
+ case mysql::system::MYSQL_TYPE_NEWDECIMAL: return "NEWDECIMAL"; break;
26
+ case mysql::system::MYSQL_TYPE_ENUM: return "ENUM"; break;
27
+ case mysql::system::MYSQL_TYPE_SET: return "SET"; break;
28
+ case mysql::system::MYSQL_TYPE_TINY_BLOB: return "TINY_BLOB"; break;
29
+ case mysql::system::MYSQL_TYPE_MEDIUM_BLOB: return "MEDIUM_BLOB"; break;
30
+ case mysql::system::MYSQL_TYPE_LONG_BLOB: return "LONG_BLOB"; break;
31
+ case mysql::system::MYSQL_TYPE_BLOB: return "BLOB"; break;
32
+ case mysql::system::MYSQL_TYPE_VAR_STRING: return "VAR_STRING"; break;
33
+ case mysql::system::MYSQL_TYPE_STRING: return "STRING"; break;
34
+ case mysql::system::MYSQL_TYPE_GEOMETRY: return "GEOMETRY"; break;
35
+ }
36
+
37
+ return 0;
38
+ }
39
+
40
+ } // namespace binlog
41
+ } // namespace ruby
Binary file
Binary file
Binary file
Binary file
@@ -51,6 +51,7 @@ void RowEvent::init() {
51
51
  rb_define_method(rb_cBinlogRowEvent, "table_id", __F(&get_table_id), 0);
52
52
  rb_define_method(rb_cBinlogRowEvent, "db_name", __F(&get_db_name), 0);
53
53
  rb_define_method(rb_cBinlogRowEvent, "table_name", __F(&get_table_name), 0);
54
+ rb_define_method(rb_cBinlogRowEvent, "columns", __F(&get_column_types), 0);
54
55
  rb_define_method(rb_cBinlogRowEvent, "flags", __F(&get_flags), 0);
55
56
  rb_define_method(rb_cBinlogRowEvent, "columns_len", __F(&get_columns_len), 0);
56
57
  rb_define_method(rb_cBinlogRowEvent, "null_bits_len", __F(&get_null_bits_len), 0);
@@ -92,6 +93,27 @@ VALUE RowEvent::get_table_name(VALUE self) {
92
93
  }
93
94
  }
94
95
 
96
+ VALUE RowEvent::get_column_types(VALUE self) {
97
+ RowEvent *p;
98
+ Data_Get_Struct(self, RowEvent, p);
99
+ VALUE retval = Qnil;
100
+
101
+ if (p->m_table_map) {
102
+ TableMapEvent *tme;
103
+ retval = rb_ary_new();
104
+
105
+ Data_Get_Struct(p->m_table_map, TableMapEvent, tme);
106
+
107
+ for (std::vector<uint8_t>::iterator itor = tme->m_event->columns.begin();
108
+ itor != tme->m_event->columns.end(); itor++) {
109
+ const char *colname = get_field_type_str(static_cast<mysql::system::enum_field_types>(*itor));
110
+ rb_ary_push(retval, (colname ? rb_str_new2(colname) : Qnil));
111
+ }
112
+ }
113
+
114
+ return retval;
115
+ }
116
+
95
117
  VALUE RowEvent::get_flags(VALUE self) {
96
118
  RowEvent *p;
97
119
  Data_Get_Struct(self, RowEvent, p);
Binary file
@@ -39,13 +39,14 @@ void TableMapEvent::init() {
39
39
 
40
40
  Event::init(rb_cBinlogTableMapEvent);
41
41
 
42
- rb_define_method(rb_cBinlogTableMapEvent, "table_id", __F(&get_table_id), 0);
43
- rb_define_method(rb_cBinlogTableMapEvent, "flags", __F(&get_flags), 0);
44
- rb_define_method(rb_cBinlogTableMapEvent, "db_name", __F(&get_db_name), 0);
45
- rb_define_method(rb_cBinlogTableMapEvent, "table_name", __F(&get_table_name), 0);
46
- rb_define_method(rb_cBinlogTableMapEvent, "columns", __F(&get_columns), 0);
47
- rb_define_method(rb_cBinlogTableMapEvent, "metadata", __F(&get_metadata), 0);
48
- rb_define_method(rb_cBinlogTableMapEvent, "null_bits", __F(&get_null_bits), 0);
42
+ rb_define_method(rb_cBinlogTableMapEvent, "table_id", __F(&get_table_id), 0);
43
+ rb_define_method(rb_cBinlogTableMapEvent, "flags", __F(&get_flags), 0);
44
+ rb_define_method(rb_cBinlogTableMapEvent, "db_name", __F(&get_db_name), 0);
45
+ rb_define_method(rb_cBinlogTableMapEvent, "table_name", __F(&get_table_name), 0);
46
+ rb_define_method(rb_cBinlogTableMapEvent, "raw_columns", __F(&get_columns), 0);
47
+ rb_define_method(rb_cBinlogTableMapEvent, "columns", __F(&get_column_types), 0);
48
+ rb_define_method(rb_cBinlogTableMapEvent, "metadata", __F(&get_metadata), 0);
49
+ rb_define_method(rb_cBinlogTableMapEvent, "null_bits", __F(&get_null_bits), 0);
49
50
  }
50
51
 
51
52
  VALUE TableMapEvent::get_table_id(VALUE self) {
@@ -86,6 +87,21 @@ VALUE TableMapEvent::get_columns(VALUE self) {
86
87
  return retval;
87
88
  }
88
89
 
90
+ VALUE TableMapEvent::get_column_types(VALUE self) {
91
+ TableMapEvent *p;
92
+ VALUE retval = rb_ary_new();
93
+
94
+ Data_Get_Struct(self, TableMapEvent, p);
95
+
96
+ for (std::vector<uint8_t>::iterator itor = p->m_event->columns.begin();
97
+ itor != p->m_event->columns.end(); itor++) {
98
+ const char *colname = get_field_type_str(static_cast<mysql::system::enum_field_types>(*itor));
99
+ rb_ary_push(retval, (colname ? rb_str_new2(colname) : Qnil));
100
+ }
101
+
102
+ return retval;
103
+ }
104
+
89
105
  VALUE TableMapEvent::get_metadata(VALUE self) {
90
106
  TableMapEvent *p;
91
107
  VALUE retval = rb_ary_new();
Binary file
Binary file
Binary file
Binary file
data/ext/test.rb CHANGED
@@ -11,6 +11,7 @@ while event = client.wait_for_next_event
11
11
  puts event.query
12
12
  when Binlog::RowEvent
13
13
  puts event.event_type
14
+ p event.columns
14
15
  p event.rows
15
16
  else
16
17
  puts "(#{event.event_type})"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-binlog
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel
@@ -34,6 +34,7 @@ files:
34
34
  - ext/ruby_binlog_rotate_event.cpp
35
35
  - ext/ruby_binlog_format_event.cpp
36
36
  - ext/Makefile
37
+ - ext/ruby_binlog_get_field_type_str.o
37
38
  - ext/ruby_binlog_format_event.o
38
39
  - ext/ruby_binlog_user_var_event.o
39
40
  - ext/ruby_binlog_user_var_event.cpp
@@ -43,6 +44,7 @@ files:
43
44
  - ext/ruby_binlog.cpp
44
45
  - ext/ruby_binlog_table_map_event.cpp
45
46
  - ext/ruby_binlog_row_event.o
47
+ - ext/ruby_binlog_get_field_type_str.cpp
46
48
  - ext/mkmf.log
47
49
  - ext/ruby_binlog_row_event.cpp
48
50
  - ext/ruby_binlog_event.cpp