aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-16 03:00:27 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-16 03:00:27 +0000
commitcee92312cfe6d573945b341e2de5d4ae7268bfcd (patch)
tree057169534aa91a7c8c08261dfc1bb3175fd9176b /activerecord/lib/active_record
parente74ec90a073257b91b1760c6e05fbc632d514ca4 (diff)
downloadrails-cee92312cfe6d573945b341e2de5d4ae7268bfcd.tar.gz
rails-cee92312cfe6d573945b341e2de5d4ae7268bfcd.tar.bz2
rails-cee92312cfe6d573945b341e2de5d4ae7268bfcd.zip
Stop the MySQL adapter crashing when views are present. (closes #3782) [Jonathan Viney]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3886 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/mysql_adapter.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index dd7331c57d..e0d1ac3b54 100755
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -236,7 +236,14 @@ module ActiveRecord
# SCHEMA STATEMENTS ========================================
def structure_dump #:nodoc:
- select_all("SHOW TABLES").inject("") do |structure, table|
+ if supports_views?
+ sql = "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'"
+ else
+ sql = "SHOW TABLES"
+ end
+
+ select_all(sql).inject("") do |structure, table|
+ table.delete('Table_type')
structure += select_one("SHOW CREATE TABLE #{table.to_a.first.last}")["Create Table"] + ";\n\n"
end
end
@@ -334,6 +341,14 @@ module ActiveRecord
result.free
rows
end
+
+ def supports_views?
+ version[0] >= 5
+ end
+
+ def version
+ @version ||= @connection.server_info.scan(/^(\d+)\.(\d+)\.(\d+)/).flatten.map { |v| v.to_i }
+ end
end
end
end