-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathruby_binlog_table_map_event.cpp
More file actions
135 lines (101 loc) · 3.65 KB
/
ruby_binlog_table_map_event.cpp
File metadata and controls
135 lines (101 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "ruby_binlog.h"
VALUE rb_cBinlogTableMapEvent;
namespace ruby {
namespace binlog {
void TableMapEvent::free(TableMapEvent *p) {
if (p->m_event) {
delete p->m_event;
p->m_event = 0;
}
p->m_event_header = 0;
delete p;
}
VALUE TableMapEvent::alloc(VALUE klass) {
TableMapEvent *p;
p = new TableMapEvent();
p->m_event = 0;
p->m_event_header = 0;
return Data_Wrap_Struct(klass, 0, &free, p);
}
void TableMapEvent::set_event(VALUE self, mysql::Binary_log_event *event) {
TableMapEvent *p;
Data_Get_Struct(self, TableMapEvent, p);
p->m_event = static_cast<Table_map_event*>(event);
p->m_event_header = event->header();
}
void TableMapEvent::init() {
rb_cBinlogTableMapEvent = rb_define_class_under(rb_mBinlog, "TableMapEvent", rb_cBinlogEvent);
rb_define_alloc_func(rb_cBinlogTableMapEvent, &alloc);
Event::init(rb_cBinlogTableMapEvent);
rb_define_method(rb_cBinlogTableMapEvent, "table_id", __F(&get_table_id), 0);
rb_define_method(rb_cBinlogTableMapEvent, "flags", __F(&get_flags), 0);
rb_define_method(rb_cBinlogTableMapEvent, "db_name", __F(&get_db_name), 0);
rb_define_method(rb_cBinlogTableMapEvent, "table_name", __F(&get_table_name), 0);
rb_define_method(rb_cBinlogTableMapEvent, "raw_columns", __F(&get_columns), 0);
rb_define_method(rb_cBinlogTableMapEvent, "columns", __F(&get_column_types), 0);
rb_define_method(rb_cBinlogTableMapEvent, "metadata", __F(&get_metadata), 0);
rb_define_method(rb_cBinlogTableMapEvent, "null_bits", __F(&get_null_bits), 0);
}
VALUE TableMapEvent::get_table_id(VALUE self) {
TableMapEvent *p;
Data_Get_Struct(self, TableMapEvent, p);
return ULL2NUM(p->m_event->table_id);
}
VALUE TableMapEvent::get_flags(VALUE self) {
TableMapEvent *p;
Data_Get_Struct(self, TableMapEvent, p);
return UINT2NUM(p->m_event->flags);
}
VALUE TableMapEvent::get_db_name(VALUE self) {
TableMapEvent *p;
Data_Get_Struct(self, TableMapEvent, p);
return rb_str_new2(p->m_event->db_name.c_str());
}
VALUE TableMapEvent::get_table_name(VALUE self) {
TableMapEvent *p;
Data_Get_Struct(self, TableMapEvent, p);
return rb_str_new2(p->m_event->table_name.c_str());
}
VALUE TableMapEvent::get_columns(VALUE self) {
TableMapEvent *p;
VALUE retval = rb_ary_new();
Data_Get_Struct(self, TableMapEvent, p);
for (std::vector<uint8_t>::iterator itor = p->m_event->columns.begin();
itor != p->m_event->columns.end(); itor++) {
rb_ary_push(retval, UINT2NUM(*itor));
}
return retval;
}
VALUE TableMapEvent::get_column_types(VALUE self) {
TableMapEvent *p;
VALUE retval = rb_ary_new();
Data_Get_Struct(self, TableMapEvent, p);
for (std::vector<uint8_t>::iterator itor = p->m_event->columns.begin();
itor != p->m_event->columns.end(); itor++) {
const char *colname = get_field_type_str(static_cast<enum_field_types>(*itor));
rb_ary_push(retval, (colname ? rb_str_new2(colname) : Qnil));
}
return retval;
}
VALUE TableMapEvent::get_metadata(VALUE self) {
TableMapEvent *p;
VALUE retval = rb_ary_new();
Data_Get_Struct(self, TableMapEvent, p);
for (std::vector<uint8_t>::iterator itor = p->m_event->metadata.begin();
itor != p->m_event->metadata.end(); itor++) {
rb_ary_push(retval, UINT2NUM(*itor));
}
return retval;
}
VALUE TableMapEvent::get_null_bits(VALUE self) {
TableMapEvent *p;
VALUE retval = rb_ary_new();
Data_Get_Struct(self, TableMapEvent, p);
for (std::vector<uint8_t>::iterator itor = p->m_event->null_bits.begin();
itor != p->m_event->null_bits.end(); itor++) {
rb_ary_push(retval, UINT2NUM(*itor));
}
return retval;
}
} // namespace binlog
} // namespace ruby