Class: Mysql

Inherits:
Object show all
Defined in:
lib/ap4r/message_store_ext.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#original_queryObject



520
# File 'lib/ap4r/message_store_ext.rb', line 520

alias original_query query

#query(q, &block) ⇒ Object

In Ruby/MySQL, query method does NOT care about a given block. To make it behave the same as MySQL/Ruby, this method adds iteration over query results.



525
526
527
528
529
530
531
532
533
534
535
536
# File 'lib/ap4r/message_store_ext.rb', line 525

def query(q, &block)
  maybe_result = original_query(q, &block)
  puts "Mysql extention: query called by #{q}" if $DEBUG
  puts "Mysql#query returns #{maybe_result}(class: #{maybe_result.class})." if $DEBUG
  return maybe_result unless block && maybe_result.kind_of?(Mysql::Result)
  begin
    puts "Mysql extention: about to yield result." if $DEBUG
    block.call(maybe_result)
  ensure
    maybe_result.free
  end
end