mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #39712 from arthurschreiber/arthur/use-subquery-for-information-schema
Use a subquery when filtering `information_schema.tables` by `table_name`.
This commit is contained in:
commit
0f6a4f5895
1 changed files with 8 additions and 4 deletions
|
@ -203,10 +203,14 @@ module ActiveRecord
|
|||
def data_source_sql(name = nil, type: nil)
|
||||
scope = quoted_scope(name, type: type)
|
||||
|
||||
sql = +"SELECT table_name FROM information_schema.tables"
|
||||
sql << " WHERE table_schema = #{scope[:schema]}"
|
||||
sql << " AND table_name = #{scope[:name]}" if scope[:name]
|
||||
sql << " AND table_type = #{scope[:type]}" if scope[:type]
|
||||
sql = +"SELECT table_name FROM (SELECT * FROM information_schema.tables "
|
||||
sql << " WHERE table_schema = #{scope[:schema]}) _subquery"
|
||||
if scope[:type] || scope[:name]
|
||||
conditions = []
|
||||
conditions << "_subquery.table_type = #{scope[:type]}" if scope[:type]
|
||||
conditions << "_subquery.table_name = #{scope[:name]}" if scope[:name]
|
||||
sql << " WHERE #{conditions.join(" AND ")}"
|
||||
end
|
||||
sql
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue