aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-04-10 19:02:06 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-04-11 10:10:01 -0700
commit269cd1b3c55c6ceb69c167ad97c357b56f49cb4b (patch)
tree02dda94b85bac78cf71ace785f6281b4ac68672b
parent8a11799a474d6cc1dc599e8823ce5bbb012944e7 (diff)
downloadrails-269cd1b3c55c6ceb69c167ad97c357b56f49cb4b.tar.gz
rails-269cd1b3c55c6ceb69c167ad97c357b56f49cb4b.tar.bz2
rails-269cd1b3c55c6ceb69c167ad97c357b56f49cb4b.zip
implement exec_query on mysql2 adapter
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb22
1 files changed, 20 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
index 7e237db357..1f7e527eeb 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -592,8 +592,26 @@ module ActiveRecord
# Returns an array of record hashes with the column names as keys and
# column values as values.
- def select(sql, name = nil)
- execute(sql, name).each(:as => :hash)
+ def select(sql, name = nil, binds = [])
+ exec_query(sql, name, binds).to_a
+ end
+
+ def exec_query(sql, name = 'SQL', binds = [])
+ @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone
+
+ log(sql, name, binds) do
+ begin
+ result = @connection.query(sql)
+ rescue ActiveRecord::StatementInvalid => exception
+ if exception.message.split(":").first =~ /Packets out of order/
+ raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings."
+ else
+ raise
+ end
+ end
+
+ ActiveRecord::Result.new(result.fields, result.to_a)
+ end
end
def supports_views?