Permalink
Browse files

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
  • Loading branch information...
1 parent e74ec90 commit cee92312cfe6d573945b341e2de5d4ae7268bfcd @dhh dhh committed Mar 16, 2006
Showing with 18 additions and 1 deletion.
  1. +2 −0 activerecord/CHANGELOG
  2. +16 −1 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
View
@@ -105,6 +105,8 @@
* Documentation fixes for :dependent [robby@planetargon.com]
+* Stop the MySQL adapter crashing when views are present. #3782 [Jonathan Viney]
+
* Allow set_fixture_class to take Classes instead of strings for a class in a module. Raise FixtureClassNotFound if a fixture can't load. [Rick Olson]
* Fix quoting of inheritance column for STI eager loading #4098 [Jonathan Viney <jonathan@bluewire.net.nz>]
@@ -236,7 +236,14 @@ def add_limit_offset!(sql, options) #:nodoc
# 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 @@ def select(sql, name = nil)
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

0 comments on commit cee9231

Please sign in to comment.