aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-05-03 13:54:00 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-05-03 13:54:00 -0700
commit836b54eed8c78ccf53e9d76855a02fd007ad6145 (patch)
tree5fd9f04aa6061ee6c6a3a91f5fb1b6c4c111430c /activerecord/lib
parentd54ce7129c9a5983b5f0bfd05b35b52229211014 (diff)
parent323b7585e106ca9ca26db5a886801239c725a95a (diff)
downloadrails-836b54eed8c78ccf53e9d76855a02fd007ad6145.tar.gz
rails-836b54eed8c78ccf53e9d76855a02fd007ad6145.tar.bz2
rails-836b54eed8c78ccf53e9d76855a02fd007ad6145.zip
Merge pull request #381 from joshk/mysql2_schema_test.
Added the mysql schema test to mysql2 adapter
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb19
1 files changed, 17 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 98a8dd6453..42eeacc173 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -410,12 +410,27 @@ module ActiveRecord
show_variable 'collation_database'
end
- def tables(name = nil)
- execute("SHOW TABLES", 'SCHEMA').collect do |field|
+ def tables(name = nil, database = nil) #:nodoc:
+ sql = ["SHOW TABLES", database].compact.join(' IN ')
+ execute(sql, 'SCHEMA').collect do |field|
field.first
end
end
+ def table_exists?(name)
+ return true if super
+
+ name = name.to_s
+ schema, table = name.split('.', 2)
+
+ unless table # A table was provided without a schema
+ table = schema
+ schema = nil
+ end
+
+ tables(nil, schema).include? table
+ end
+
def drop_table(table_name, options = {})
super(table_name, options)
end