Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: a50642f6cb
Fetching contributors…

Cannot retrieve contributors at this time

file 39 lines (30 sloc) 1.41 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
ActiveRecord::Base.connection.class.class_eval do
  IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /SHOW FIELDS/]

  def execute_with_query_record(sql, name = nil, &block)
    $queries_executed ||= []
    $queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r }
    execute_without_query_record(sql, name, &block)
  end

  alias_method_chain :execute, :query_record
end

# Oracle specific ignored SQLs
ActiveRecord::Base.connection.class.class_eval do
  IGNORED_SELECT_SQL = [/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO/, /^\s*select .* from ((all|user)_tab_columns|(all|user)_triggers|(all|user)_constraints)/im]

  def select_with_query_record(sql, name = nil)
    $queries_executed ||= []
    $queries_executed << sql unless IGNORED_SELECT_SQL.any? { |r| sql =~ r }
    select_without_query_record(sql, name)
  end

  alias_method_chain :select, :query_record
end if ENV['ARCONN'] == 'oracle'

ActiveRecord::Base.connection.class.class_eval {
  attr_accessor :column_calls, :column_calls_by_table

  def columns_with_calls(*args)
    @column_calls ||= 0
    @column_calls_by_table ||= Hash.new {|h,table| h[table] = 0}

    @column_calls += 1
    @column_calls_by_table[args.first.to_s] += 1
    columns_without_calls(*args)
  end

  alias_method_chain :columns, :calls
}
Something went wrong with that request. Please try again.