mysql_binlog 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,226 @@
|
|
1
|
+
module MysqlBinlog
|
2
|
+
# A hash to map MySQL collation name to ID and character set name.
|
3
|
+
#
|
4
|
+
# This hash is produced by the following query:
|
5
|
+
# SELECT concat(
|
6
|
+
# " :",
|
7
|
+
# rpad(collation_name, 24, " "),
|
8
|
+
# " => { :id => ",
|
9
|
+
# lpad(id, 3, " "),
|
10
|
+
# ", :character_set => :",
|
11
|
+
# rpad(character_set_name, 8, " "),
|
12
|
+
# " },"
|
13
|
+
# ) AS ruby_code
|
14
|
+
# FROM information_schema.collations
|
15
|
+
# ORDER BY collation_name
|
16
|
+
#
|
17
|
+
COLLATION_HASH = {
|
18
|
+
:armscii8_bin => { :id => 64, :character_set => :armscii8 },
|
19
|
+
:armscii8_general_ci => { :id => 32, :character_set => :armscii8 },
|
20
|
+
:ascii_bin => { :id => 65, :character_set => :ascii },
|
21
|
+
:ascii_general_ci => { :id => 11, :character_set => :ascii },
|
22
|
+
:big5_bin => { :id => 84, :character_set => :big5 },
|
23
|
+
:big5_chinese_ci => { :id => 1, :character_set => :big5 },
|
24
|
+
:binary => { :id => 63, :character_set => :binary },
|
25
|
+
:cp1250_bin => { :id => 66, :character_set => :cp1250 },
|
26
|
+
:cp1250_croatian_ci => { :id => 44, :character_set => :cp1250 },
|
27
|
+
:cp1250_czech_cs => { :id => 34, :character_set => :cp1250 },
|
28
|
+
:cp1250_general_ci => { :id => 26, :character_set => :cp1250 },
|
29
|
+
:cp1250_polish_ci => { :id => 99, :character_set => :cp1250 },
|
30
|
+
:cp1251_bin => { :id => 50, :character_set => :cp1251 },
|
31
|
+
:cp1251_bulgarian_ci => { :id => 14, :character_set => :cp1251 },
|
32
|
+
:cp1251_general_ci => { :id => 51, :character_set => :cp1251 },
|
33
|
+
:cp1251_general_cs => { :id => 52, :character_set => :cp1251 },
|
34
|
+
:cp1251_ukrainian_ci => { :id => 23, :character_set => :cp1251 },
|
35
|
+
:cp1256_bin => { :id => 67, :character_set => :cp1256 },
|
36
|
+
:cp1256_general_ci => { :id => 57, :character_set => :cp1256 },
|
37
|
+
:cp1257_bin => { :id => 58, :character_set => :cp1257 },
|
38
|
+
:cp1257_general_ci => { :id => 59, :character_set => :cp1257 },
|
39
|
+
:cp1257_lithuanian_ci => { :id => 29, :character_set => :cp1257 },
|
40
|
+
:cp850_bin => { :id => 80, :character_set => :cp850 },
|
41
|
+
:cp850_general_ci => { :id => 4, :character_set => :cp850 },
|
42
|
+
:cp852_bin => { :id => 81, :character_set => :cp852 },
|
43
|
+
:cp852_general_ci => { :id => 40, :character_set => :cp852 },
|
44
|
+
:cp866_bin => { :id => 68, :character_set => :cp866 },
|
45
|
+
:cp866_general_ci => { :id => 36, :character_set => :cp866 },
|
46
|
+
:cp932_bin => { :id => 96, :character_set => :cp932 },
|
47
|
+
:cp932_japanese_ci => { :id => 95, :character_set => :cp932 },
|
48
|
+
:dec8_bin => { :id => 69, :character_set => :dec8 },
|
49
|
+
:dec8_swedish_ci => { :id => 3, :character_set => :dec8 },
|
50
|
+
:eucjpms_bin => { :id => 98, :character_set => :eucjpms },
|
51
|
+
:eucjpms_japanese_ci => { :id => 97, :character_set => :eucjpms },
|
52
|
+
:euckr_bin => { :id => 85, :character_set => :euckr },
|
53
|
+
:euckr_korean_ci => { :id => 19, :character_set => :euckr },
|
54
|
+
:gb2312_bin => { :id => 86, :character_set => :gb2312 },
|
55
|
+
:gb2312_chinese_ci => { :id => 24, :character_set => :gb2312 },
|
56
|
+
:gbk_bin => { :id => 87, :character_set => :gbk },
|
57
|
+
:gbk_chinese_ci => { :id => 28, :character_set => :gbk },
|
58
|
+
:geostd8_bin => { :id => 93, :character_set => :geostd8 },
|
59
|
+
:geostd8_general_ci => { :id => 92, :character_set => :geostd8 },
|
60
|
+
:greek_bin => { :id => 70, :character_set => :greek },
|
61
|
+
:greek_general_ci => { :id => 25, :character_set => :greek },
|
62
|
+
:hebrew_bin => { :id => 71, :character_set => :hebrew },
|
63
|
+
:hebrew_general_ci => { :id => 16, :character_set => :hebrew },
|
64
|
+
:hp8_bin => { :id => 72, :character_set => :hp8 },
|
65
|
+
:hp8_english_ci => { :id => 6, :character_set => :hp8 },
|
66
|
+
:keybcs2_bin => { :id => 73, :character_set => :keybcs2 },
|
67
|
+
:keybcs2_general_ci => { :id => 37, :character_set => :keybcs2 },
|
68
|
+
:koi8r_bin => { :id => 74, :character_set => :koi8r },
|
69
|
+
:koi8r_general_ci => { :id => 7, :character_set => :koi8r },
|
70
|
+
:koi8u_bin => { :id => 75, :character_set => :koi8u },
|
71
|
+
:koi8u_general_ci => { :id => 22, :character_set => :koi8u },
|
72
|
+
:latin1_bin => { :id => 47, :character_set => :latin1 },
|
73
|
+
:latin1_danish_ci => { :id => 15, :character_set => :latin1 },
|
74
|
+
:latin1_general_ci => { :id => 48, :character_set => :latin1 },
|
75
|
+
:latin1_general_cs => { :id => 49, :character_set => :latin1 },
|
76
|
+
:latin1_german1_ci => { :id => 5, :character_set => :latin1 },
|
77
|
+
:latin1_german2_ci => { :id => 31, :character_set => :latin1 },
|
78
|
+
:latin1_spanish_ci => { :id => 94, :character_set => :latin1 },
|
79
|
+
:latin1_swedish_ci => { :id => 8, :character_set => :latin1 },
|
80
|
+
:latin2_bin => { :id => 77, :character_set => :latin2 },
|
81
|
+
:latin2_croatian_ci => { :id => 27, :character_set => :latin2 },
|
82
|
+
:latin2_czech_cs => { :id => 2, :character_set => :latin2 },
|
83
|
+
:latin2_general_ci => { :id => 9, :character_set => :latin2 },
|
84
|
+
:latin2_hungarian_ci => { :id => 21, :character_set => :latin2 },
|
85
|
+
:latin5_bin => { :id => 78, :character_set => :latin5 },
|
86
|
+
:latin5_turkish_ci => { :id => 30, :character_set => :latin5 },
|
87
|
+
:latin7_bin => { :id => 79, :character_set => :latin7 },
|
88
|
+
:latin7_estonian_cs => { :id => 20, :character_set => :latin7 },
|
89
|
+
:latin7_general_ci => { :id => 41, :character_set => :latin7 },
|
90
|
+
:latin7_general_cs => { :id => 42, :character_set => :latin7 },
|
91
|
+
:macce_bin => { :id => 43, :character_set => :macce },
|
92
|
+
:macce_general_ci => { :id => 38, :character_set => :macce },
|
93
|
+
:macroman_bin => { :id => 53, :character_set => :macroman },
|
94
|
+
:macroman_general_ci => { :id => 39, :character_set => :macroman },
|
95
|
+
:sjis_bin => { :id => 88, :character_set => :sjis },
|
96
|
+
:sjis_japanese_ci => { :id => 13, :character_set => :sjis },
|
97
|
+
:swe7_bin => { :id => 82, :character_set => :swe7 },
|
98
|
+
:swe7_swedish_ci => { :id => 10, :character_set => :swe7 },
|
99
|
+
:tis620_bin => { :id => 89, :character_set => :tis620 },
|
100
|
+
:tis620_thai_ci => { :id => 18, :character_set => :tis620 },
|
101
|
+
:ucs2_bin => { :id => 90, :character_set => :ucs2 },
|
102
|
+
:ucs2_czech_ci => { :id => 138, :character_set => :ucs2 },
|
103
|
+
:ucs2_danish_ci => { :id => 139, :character_set => :ucs2 },
|
104
|
+
:ucs2_esperanto_ci => { :id => 145, :character_set => :ucs2 },
|
105
|
+
:ucs2_estonian_ci => { :id => 134, :character_set => :ucs2 },
|
106
|
+
:ucs2_general_ci => { :id => 35, :character_set => :ucs2 },
|
107
|
+
:ucs2_general_mysql500_ci => { :id => 159, :character_set => :ucs2 },
|
108
|
+
:ucs2_hungarian_ci => { :id => 146, :character_set => :ucs2 },
|
109
|
+
:ucs2_icelandic_ci => { :id => 129, :character_set => :ucs2 },
|
110
|
+
:ucs2_latvian_ci => { :id => 130, :character_set => :ucs2 },
|
111
|
+
:ucs2_lithuanian_ci => { :id => 140, :character_set => :ucs2 },
|
112
|
+
:ucs2_persian_ci => { :id => 144, :character_set => :ucs2 },
|
113
|
+
:ucs2_polish_ci => { :id => 133, :character_set => :ucs2 },
|
114
|
+
:ucs2_romanian_ci => { :id => 131, :character_set => :ucs2 },
|
115
|
+
:ucs2_roman_ci => { :id => 143, :character_set => :ucs2 },
|
116
|
+
:ucs2_sinhala_ci => { :id => 147, :character_set => :ucs2 },
|
117
|
+
:ucs2_slovak_ci => { :id => 141, :character_set => :ucs2 },
|
118
|
+
:ucs2_slovenian_ci => { :id => 132, :character_set => :ucs2 },
|
119
|
+
:ucs2_spanish2_ci => { :id => 142, :character_set => :ucs2 },
|
120
|
+
:ucs2_spanish_ci => { :id => 135, :character_set => :ucs2 },
|
121
|
+
:ucs2_swedish_ci => { :id => 136, :character_set => :ucs2 },
|
122
|
+
:ucs2_turkish_ci => { :id => 137, :character_set => :ucs2 },
|
123
|
+
:ucs2_unicode_ci => { :id => 128, :character_set => :ucs2 },
|
124
|
+
:ujis_bin => { :id => 91, :character_set => :ujis },
|
125
|
+
:ujis_japanese_ci => { :id => 12, :character_set => :ujis },
|
126
|
+
:utf16_bin => { :id => 55, :character_set => :utf16 },
|
127
|
+
:utf16_czech_ci => { :id => 111, :character_set => :utf16 },
|
128
|
+
:utf16_danish_ci => { :id => 112, :character_set => :utf16 },
|
129
|
+
:utf16_esperanto_ci => { :id => 118, :character_set => :utf16 },
|
130
|
+
:utf16_estonian_ci => { :id => 107, :character_set => :utf16 },
|
131
|
+
:utf16_general_ci => { :id => 54, :character_set => :utf16 },
|
132
|
+
:utf16_hungarian_ci => { :id => 119, :character_set => :utf16 },
|
133
|
+
:utf16_icelandic_ci => { :id => 102, :character_set => :utf16 },
|
134
|
+
:utf16_latvian_ci => { :id => 103, :character_set => :utf16 },
|
135
|
+
:utf16_lithuanian_ci => { :id => 113, :character_set => :utf16 },
|
136
|
+
:utf16_persian_ci => { :id => 117, :character_set => :utf16 },
|
137
|
+
:utf16_polish_ci => { :id => 106, :character_set => :utf16 },
|
138
|
+
:utf16_romanian_ci => { :id => 104, :character_set => :utf16 },
|
139
|
+
:utf16_roman_ci => { :id => 116, :character_set => :utf16 },
|
140
|
+
:utf16_sinhala_ci => { :id => 120, :character_set => :utf16 },
|
141
|
+
:utf16_slovak_ci => { :id => 114, :character_set => :utf16 },
|
142
|
+
:utf16_slovenian_ci => { :id => 105, :character_set => :utf16 },
|
143
|
+
:utf16_spanish2_ci => { :id => 115, :character_set => :utf16 },
|
144
|
+
:utf16_spanish_ci => { :id => 108, :character_set => :utf16 },
|
145
|
+
:utf16_swedish_ci => { :id => 109, :character_set => :utf16 },
|
146
|
+
:utf16_turkish_ci => { :id => 110, :character_set => :utf16 },
|
147
|
+
:utf16_unicode_ci => { :id => 101, :character_set => :utf16 },
|
148
|
+
:utf32_bin => { :id => 61, :character_set => :utf32 },
|
149
|
+
:utf32_czech_ci => { :id => 170, :character_set => :utf32 },
|
150
|
+
:utf32_danish_ci => { :id => 171, :character_set => :utf32 },
|
151
|
+
:utf32_esperanto_ci => { :id => 177, :character_set => :utf32 },
|
152
|
+
:utf32_estonian_ci => { :id => 166, :character_set => :utf32 },
|
153
|
+
:utf32_general_ci => { :id => 60, :character_set => :utf32 },
|
154
|
+
:utf32_hungarian_ci => { :id => 178, :character_set => :utf32 },
|
155
|
+
:utf32_icelandic_ci => { :id => 161, :character_set => :utf32 },
|
156
|
+
:utf32_latvian_ci => { :id => 162, :character_set => :utf32 },
|
157
|
+
:utf32_lithuanian_ci => { :id => 172, :character_set => :utf32 },
|
158
|
+
:utf32_persian_ci => { :id => 176, :character_set => :utf32 },
|
159
|
+
:utf32_polish_ci => { :id => 165, :character_set => :utf32 },
|
160
|
+
:utf32_romanian_ci => { :id => 163, :character_set => :utf32 },
|
161
|
+
:utf32_roman_ci => { :id => 175, :character_set => :utf32 },
|
162
|
+
:utf32_sinhala_ci => { :id => 179, :character_set => :utf32 },
|
163
|
+
:utf32_slovak_ci => { :id => 173, :character_set => :utf32 },
|
164
|
+
:utf32_slovenian_ci => { :id => 164, :character_set => :utf32 },
|
165
|
+
:utf32_spanish2_ci => { :id => 174, :character_set => :utf32 },
|
166
|
+
:utf32_spanish_ci => { :id => 167, :character_set => :utf32 },
|
167
|
+
:utf32_swedish_ci => { :id => 168, :character_set => :utf32 },
|
168
|
+
:utf32_turkish_ci => { :id => 169, :character_set => :utf32 },
|
169
|
+
:utf32_unicode_ci => { :id => 160, :character_set => :utf32 },
|
170
|
+
:utf8mb4_bin => { :id => 46, :character_set => :utf8mb4 },
|
171
|
+
:utf8mb4_czech_ci => { :id => 234, :character_set => :utf8mb4 },
|
172
|
+
:utf8mb4_danish_ci => { :id => 235, :character_set => :utf8mb4 },
|
173
|
+
:utf8mb4_esperanto_ci => { :id => 241, :character_set => :utf8mb4 },
|
174
|
+
:utf8mb4_estonian_ci => { :id => 230, :character_set => :utf8mb4 },
|
175
|
+
:utf8mb4_general_ci => { :id => 45, :character_set => :utf8mb4 },
|
176
|
+
:utf8mb4_hungarian_ci => { :id => 242, :character_set => :utf8mb4 },
|
177
|
+
:utf8mb4_icelandic_ci => { :id => 225, :character_set => :utf8mb4 },
|
178
|
+
:utf8mb4_latvian_ci => { :id => 226, :character_set => :utf8mb4 },
|
179
|
+
:utf8mb4_lithuanian_ci => { :id => 236, :character_set => :utf8mb4 },
|
180
|
+
:utf8mb4_persian_ci => { :id => 240, :character_set => :utf8mb4 },
|
181
|
+
:utf8mb4_polish_ci => { :id => 229, :character_set => :utf8mb4 },
|
182
|
+
:utf8mb4_romanian_ci => { :id => 227, :character_set => :utf8mb4 },
|
183
|
+
:utf8mb4_roman_ci => { :id => 239, :character_set => :utf8mb4 },
|
184
|
+
:utf8mb4_sinhala_ci => { :id => 243, :character_set => :utf8mb4 },
|
185
|
+
:utf8mb4_slovak_ci => { :id => 237, :character_set => :utf8mb4 },
|
186
|
+
:utf8mb4_slovenian_ci => { :id => 228, :character_set => :utf8mb4 },
|
187
|
+
:utf8mb4_spanish2_ci => { :id => 238, :character_set => :utf8mb4 },
|
188
|
+
:utf8mb4_spanish_ci => { :id => 231, :character_set => :utf8mb4 },
|
189
|
+
:utf8mb4_swedish_ci => { :id => 232, :character_set => :utf8mb4 },
|
190
|
+
:utf8mb4_turkish_ci => { :id => 233, :character_set => :utf8mb4 },
|
191
|
+
:utf8mb4_unicode_ci => { :id => 224, :character_set => :utf8mb4 },
|
192
|
+
:utf8_bin => { :id => 83, :character_set => :utf8 },
|
193
|
+
:utf8_czech_ci => { :id => 202, :character_set => :utf8 },
|
194
|
+
:utf8_danish_ci => { :id => 203, :character_set => :utf8 },
|
195
|
+
:utf8_esperanto_ci => { :id => 209, :character_set => :utf8 },
|
196
|
+
:utf8_estonian_ci => { :id => 198, :character_set => :utf8 },
|
197
|
+
:utf8_general_ci => { :id => 33, :character_set => :utf8 },
|
198
|
+
:utf8_general_mysql500_ci => { :id => 223, :character_set => :utf8 },
|
199
|
+
:utf8_hungarian_ci => { :id => 210, :character_set => :utf8 },
|
200
|
+
:utf8_icelandic_ci => { :id => 193, :character_set => :utf8 },
|
201
|
+
:utf8_latvian_ci => { :id => 194, :character_set => :utf8 },
|
202
|
+
:utf8_lithuanian_ci => { :id => 204, :character_set => :utf8 },
|
203
|
+
:utf8_persian_ci => { :id => 208, :character_set => :utf8 },
|
204
|
+
:utf8_polish_ci => { :id => 197, :character_set => :utf8 },
|
205
|
+
:utf8_romanian_ci => { :id => 195, :character_set => :utf8 },
|
206
|
+
:utf8_roman_ci => { :id => 207, :character_set => :utf8 },
|
207
|
+
:utf8_sinhala_ci => { :id => 211, :character_set => :utf8 },
|
208
|
+
:utf8_slovak_ci => { :id => 205, :character_set => :utf8 },
|
209
|
+
:utf8_slovenian_ci => { :id => 196, :character_set => :utf8 },
|
210
|
+
:utf8_spanish2_ci => { :id => 206, :character_set => :utf8 },
|
211
|
+
:utf8_spanish_ci => { :id => 199, :character_set => :utf8 },
|
212
|
+
:utf8_swedish_ci => { :id => 200, :character_set => :utf8 },
|
213
|
+
:utf8_turkish_ci => { :id => 201, :character_set => :utf8 },
|
214
|
+
:utf8_unicode_ci => { :id => 192, :character_set => :utf8 },
|
215
|
+
}
|
216
|
+
|
217
|
+
# An array of collation IDs to collation and character set name for
|
218
|
+
# efficient lookup by ID.
|
219
|
+
COLLATION = COLLATION_HASH.inject(Array.new) do |collation_array, item|
|
220
|
+
collation_array[item[1][:id]] = {
|
221
|
+
:character_set => item[1][:character_set],
|
222
|
+
:collation => item[0],
|
223
|
+
}
|
224
|
+
collation_array
|
225
|
+
end
|
226
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module MysqlBinlog
|
2
|
+
# A simple method to print a string as in hex representation per byte,
|
3
|
+
# with no more than 24 bytes per line, and spaces between each byte.
|
4
|
+
# There is probably a better way to do this, but I don't know it.
|
5
|
+
def hexdump(data)
|
6
|
+
data.bytes.each_slice(24).inject("") do |string, slice|
|
7
|
+
string << " " + slice.map { |b| "%02x" % b }.join(" ") + "\n"
|
8
|
+
string
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Wrap another Reader class, passing through all method calls, but optionally
|
13
|
+
# printing the contents of data read, and the method calls themselves. This
|
14
|
+
# is very useful for debugging the library itself, or if exceptions are
|
15
|
+
# getting thrown when reading a possibly unsupported log.
|
16
|
+
class DebuggingReader
|
17
|
+
def initialize(wrapped, options={})
|
18
|
+
@wrapped = wrapped
|
19
|
+
@options = options
|
20
|
+
end
|
21
|
+
|
22
|
+
# Pass through all method calls to the reader class we're delegating to.
|
23
|
+
# If various options are enabled, print debugging information.
|
24
|
+
def method_missing(method, *args)
|
25
|
+
if @options[:calls]
|
26
|
+
puts "#{@wrapped.class}.#{method}"
|
27
|
+
end
|
28
|
+
|
29
|
+
return_value = @wrapped.send(method, *args)
|
30
|
+
|
31
|
+
# Print the returned data from :read in a nice hex dump format.
|
32
|
+
if method == :read and @options[:data]
|
33
|
+
puts "Read #{args[0]} bytes #{caller.first.split(":")[2]}:"
|
34
|
+
puts hexdump(return_value)
|
35
|
+
end
|
36
|
+
|
37
|
+
return_value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysql_binlog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeremy Cole
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-08-21 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: Library for parsing MySQL binary logs in Ruby
|
@@ -29,10 +29,12 @@ extra_rdoc_files: []
|
|
29
29
|
files:
|
30
30
|
- lib/mysql_binlog.rb
|
31
31
|
- lib/mysql_binlog/binlog.rb
|
32
|
-
- lib/mysql_binlog/binlog_field_parser.rb
|
33
32
|
- lib/mysql_binlog/binlog_event_parser.rb
|
33
|
+
- lib/mysql_binlog/binlog_field_parser.rb
|
34
|
+
- lib/mysql_binlog/mysql_character_set.rb
|
34
35
|
- lib/mysql_binlog/reader/binlog_file_reader.rb
|
35
36
|
- lib/mysql_binlog/reader/binlog_stream_reader.rb
|
37
|
+
- lib/mysql_binlog/reader/debugging_reader.rb
|
36
38
|
- bin/mysql_binlog_dump
|
37
39
|
homepage: http://jcole.us/
|
38
40
|
licenses: []
|