Class: Flydata::SourceMysql::Parser::FlydataMysqlClient

Inherits:
Mysql2::Client
  • Object
show all
Defined in:
lib/flydata/source_mysql/parser/dump_parser.rb

Overview

Custom mysql client that gives access to the last query that was executed using the client which can be helpful when handling exceptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#last_queryObject

Returns the value of attribute last_query.


228
229
230
# File 'lib/flydata/source_mysql/parser/dump_parser.rb', line 228

def last_query
  @last_query
end

Instance Method Details

#query(sql, options = {}) ⇒ Object


230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/flydata/source_mysql/parser/dump_parser.rb', line 230

def query(sql, options = {})
  @last_query = sql
  max_retry = options[:retry_count] || 0
  retry_interval = options[:retry_interval] || 3
  count = 0
  result = nil
  begin
    result = super(sql, options)
  rescue => e
    count += 1
    raise e if max_retry != -1 && count > max_retry
    yield(count, e) if block_given?
    sleep retry_interval
    retry
  end
  result
end