mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Escape table names during calculation queries. [wesley.moxam, Koz] Closes #4593
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8061 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
3c9cd19786
commit
8f74527282
2 changed files with 7 additions and 2 deletions
|
@ -167,7 +167,7 @@ module ActiveRecord
|
||||||
if operation == 'count'
|
if operation == 'count'
|
||||||
if merged_includes.any?
|
if merged_includes.any?
|
||||||
options[:distinct] = true
|
options[:distinct] = true
|
||||||
column_name = options[:select] || [table_name, primary_key] * '.'
|
column_name = options[:select] || [connection.quote_table_name(table_name), primary_key] * '.'
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:distinct]
|
if options[:distinct]
|
||||||
|
@ -182,7 +182,7 @@ module ActiveRecord
|
||||||
|
|
||||||
sql << ", #{options[:group_field]} AS #{options[:group_alias]}" if options[:group]
|
sql << ", #{options[:group_field]} AS #{options[:group_alias]}" if options[:group]
|
||||||
sql << " FROM (SELECT DISTINCT #{column_name}" if use_workaround
|
sql << " FROM (SELECT DISTINCT #{column_name}" if use_workaround
|
||||||
sql << " FROM #{table_name} "
|
sql << " FROM #{connection.quote_table_name(table_name)} "
|
||||||
if merged_includes.any?
|
if merged_includes.any?
|
||||||
join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merged_includes, options[:joins], options[:ar_joins])
|
join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merged_includes, options[:joins], options[:ar_joins])
|
||||||
sql << join_dependency.join_associations.collect{|join| join.association_join }.join
|
sql << join_dependency.join_associations.collect{|join| join.association_join }.join
|
||||||
|
|
|
@ -141,6 +141,11 @@ class MysqlReservedWordTest < Test::Unit::TestCase
|
||||||
assert_nothing_raised { Group.table_exists? }
|
assert_nothing_raised { Group.table_exists? }
|
||||||
assert_nothing_raised { Group.columns }
|
assert_nothing_raised { Group.columns }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Calculations
|
||||||
|
def test_calculations_work_with_reserved_words
|
||||||
|
assert_nothing_raised { Group.count }
|
||||||
|
end
|
||||||
|
|
||||||
#the following functions were added to DRY test cases
|
#the following functions were added to DRY test cases
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue