Permalink
Browse files

Older mysql2 and SQL logging for Rails 3.0

  • Loading branch information...
1 parent d1ed078 commit 517940e8c549cc67fdfc26ff0cbba4bbc35ef768 @pat committed Jan 22, 2012
Showing with 18 additions and 5 deletions.
  1. +1 −0 Appraisals
  2. +1 −1 gemfiles/rails_3_0.gemfile
  3. +16 −4 lib/cucumber/thinking_sphinx/sql_logger.rb
View
@@ -1,6 +1,7 @@
appraise 'rails_3_0' do
gem 'activerecord', '~> 3.0.3'
gem 'actionpack', '~> 3.0.3'
+ gem 'mysql2', '~> 0.2.18', :platform => :ruby
end
appraise 'rails_3_1' do
@@ -3,11 +3,11 @@
source :rubygems
gem "rcov", "0.9.8", :platform=>:mri_18
-gem "mysql2", "~> 0.3.7", :platform=>:ruby
gem "pg", "~> 0.11.0", :platform=>:ruby
gem "activerecord-jdbcmysql-adapter", "~> 1.1.3", :platform=>:jruby
gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby
gem "activerecord", "~> 3.0.3"
gem "actionpack", "~> 3.0.3"
+gem "mysql2", "~> 0.2.18", :platform=>:ruby
gemspec :path=>"../"
@@ -6,10 +6,22 @@ module SqlLogger
/^SELECT @@ROWCOUNT/, /^SHOW FIELDS/
]
- def log(sql, name = 'SQL', binds = [])
- $queries_executed ||= []
- $queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r }
- super sql, name, binds
+ if ActiveRecord::VERSION::STRING.to_f > 3.0
+ def log(sql, name = 'SQL', binds = [])
+ $queries_executed ||= []
+ $queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r }
+ super sql, name, binds
+ end
+ else
+ def self.included(base)
+ base.send :alias_method_chain, :execute, :query_record
+ end
+
+ def execute_with_query_record(sql, name = 'SQL', &block)
+ $queries_executed ||= []
+ $queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r }
+ execute_without_query_record(sql, name, &block)
+ end
end
end
end

0 comments on commit 517940e

Please sign in to comment.