aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-10-13 11:09:21 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-10-26 13:44:09 -0700
commitd4b0bcb88e058a642b193b9e008b43a32fd64d64 (patch)
tree55338294df56b1dac50ed71a36e725c387c23230 /activerecord
parentd6b16bbaf705237f68980c4b0bd3b407225d8aa0 (diff)
downloadrails-d4b0bcb88e058a642b193b9e008b43a32fd64d64.tar.gz
rails-d4b0bcb88e058a642b193b9e008b43a32fd64d64.tar.bz2
rails-d4b0bcb88e058a642b193b9e008b43a32fd64d64.zip
all mysql tests are passing
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index c31326d891..a4cd2cd964 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -315,11 +315,11 @@ module ActiveRecord
def exec(sql, name = 'SQL', bind_values = [])
log(sql, name) do
+ result = nil
stmt = @connection.prepare(sql)
stmt.execute(*bind_values.map { |col, val|
col ? col.type_cast(val) : val
})
- result = nil
if metadata = stmt.result_metadata
cols = metadata.fetch_fields.map { |field| field.name }
values = []
@@ -331,6 +331,19 @@ module ActiveRecord
end
end
+ def exec_without_stmt(sql, name = 'SQL') # :nodoc:
+ # Some queries, like SHOW CREATE TABLE don't work through the prepared
+ # statement API. For those queries, we need to use this method. :'(
+ log(sql, name) do
+ result = @connection.query(sql)
+ cols = result.fetch_fields.map { |field| field.name }
+ values = []
+ result.each { |row| values << row }
+ result.free
+ ActiveRecord::Result.new(cols, values)
+ end
+ end
+
# Executes an SQL query and returns a MySQL::Result object. Note that you have to free
# the Result object after you're done using it.
def execute(sql, name = nil) #:nodoc:
@@ -411,7 +424,8 @@ module ActiveRecord
select_all(sql).map do |table|
table.delete('Table_type')
- select_one("SHOW CREATE TABLE #{quote_table_name(table.to_a.first.last)}")["Create Table"] + ";\n\n"
+ sql = "SHOW CREATE TABLE #{quote_table_name(table.to_a.first.last)}"
+ exec_without_stmt(sql).first['Create Table'] + ";\n\n"
end.join("")
end