mysql_binlog 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,8 @@ reader = BinlogFileReader.new(ARGV.first)
9
9
  #reader = DebuggingReader.new(reader, :data => true, :calls => true)
10
10
  binlog = Binlog.new(reader)
11
11
 
12
+ binlog.ignore_rotate = true
13
+
12
14
  binlog.each_event do |event|
13
15
  pp event
14
16
  end
@@ -39,6 +39,7 @@ module MysqlBinlog
39
39
  attr_accessor :event_parser
40
40
  attr_accessor :filter_event_types
41
41
  attr_accessor :filter_flags
42
+ attr_accessor :ignore_rotate
42
43
  attr_accessor :max_query_length
43
44
 
44
45
  def initialize(reader)
@@ -48,6 +49,7 @@ module MysqlBinlog
48
49
  @fde = nil
49
50
  @filter_event_types = nil
50
51
  @filter_flags = nil
52
+ @ignore_rotate = false
51
53
  @max_query_length = 1048576
52
54
  end
53
55
 
@@ -127,6 +129,7 @@ module MysqlBinlog
127
129
 
128
130
  case event_type
129
131
  when :rotate_event
132
+ next if ignore_rotate
130
133
  reader.rotate(fields[:name], fields[:pos])
131
134
  when :format_description_event
132
135
  process_fde(fields)
@@ -251,10 +251,17 @@ module MysqlBinlog
251
251
  when :blob, :geometry
252
252
  { :length_size => parser.read_uint8 }
253
253
  when :string, :var_string
254
- {
255
- :real_type => MYSQL_TYPES[parser.read_uint8],
256
- :max_length => parser.read_uint8,
257
- }
254
+ # The :string type sets a :real_type field to indicate the actual type
255
+ # which is fundamentally incompatible with :string parsing. Setting
256
+ # a :type key in this hash will cause table_map_event to override the
257
+ # main field :type with the provided type here.
258
+ real_type = MYSQL_TYPES[parser.read_uint8]
259
+ case real_type
260
+ when :enum, :set
261
+ { :type => real_type, :size => parser.read_uint8 }
262
+ else
263
+ { :max_length => parser.read_uint8 }
264
+ end
258
265
  end
259
266
  end
260
267
  private :_table_map_event_column_metadata_read
@@ -281,6 +288,14 @@ module MysqlBinlog
281
288
  columns_metadata = _table_map_event_column_metadata(columns_type)
282
289
  columns_nullable = parser.read_bit_array(columns)
283
290
 
291
+ # Remap overloaded types before we piece together the entire event.
292
+ columns.times do |c|
293
+ if columns_metadata[c] and columns_metadata[c][:type]
294
+ columns_type[c] = columns_metadata[c][:type]
295
+ columns_metadata[c].delete :type
296
+ end
297
+ end
298
+
284
299
  map_entry[:columns] = columns.times.map do |c|
285
300
  {
286
301
  :type => columns_type[c],
@@ -80,6 +80,23 @@ module MysqlBinlog
80
80
  reader.read(8).unpack("Q").first
81
81
  end
82
82
 
83
+ def read_uint_by_size(size)
84
+ case size
85
+ when 1
86
+ read_uint8
87
+ when 2
88
+ read_uint16
89
+ when 3
90
+ read_uint24
91
+ when 4
92
+ read_uint32
93
+ when 6
94
+ read_uint48
95
+ when 8
96
+ read_uint64
97
+ end
98
+ end
99
+
83
100
  # Read a single-precision (4-byte) floating point number.
84
101
  def read_float
85
102
  reader.read(4).unpack("g").first
@@ -132,16 +149,7 @@ module MysqlBinlog
132
149
  # optional size parameter (default 1), followed by the string itself with
133
150
  # no termination character.
134
151
  def read_lpstring(size=1)
135
- case size
136
- when 1
137
- length = read_uint8
138
- when 2
139
- length = read_uint16
140
- when 3
141
- length = read_uint24
142
- when 4
143
- length = read_uint32
144
- end
152
+ length = read_uint_by_size(size)
145
153
  read_nstring(length)
146
154
  end
147
155
 
@@ -279,6 +287,8 @@ module MysqlBinlog
279
287
  convert_mysql_type_time(read_uint24)
280
288
  when :datetime
281
289
  convert_mysql_type_datetime(read_uint64)
290
+ when :enum, :set
291
+ read_uint_by_size(metadata[:size])
282
292
  #when :bit
283
293
  #when :newdecimal
284
294
  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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
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-06-28 00:00:00 Z
18
+ date: 2012-06-29 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Library for parsing MySQL binary logs in Ruby