diff options
author | Bryan Helmkamp <bryan@brynary.com> | 2009-05-18 01:11:40 -0400 |
---|---|---|
committer | Bryan Helmkamp <bryan@brynary.com> | 2009-05-18 01:11:50 -0400 |
commit | 930c9f90a03729bdc380ab84882a118d8c17e54d (patch) | |
tree | 4ba2526647ddcfa08bbb6ee8739d670cda896e46 /lib/arel/engines/sql/formatters.rb | |
parent | 1234c926cce2a979ec967a8c5bc6ba58cda1ce71 (diff) | |
download | rails-930c9f90a03729bdc380ab84882a118d8c17e54d.tar.gz rails-930c9f90a03729bdc380ab84882a118d8c17e54d.tar.bz2 rails-930c9f90a03729bdc380ab84882a118d8c17e54d.zip |
Cleanup Sql formatters a bit
Diffstat (limited to 'lib/arel/engines/sql/formatters.rb')
-rw-r--r-- | lib/arel/engines/sql/formatters.rb | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/lib/arel/engines/sql/formatters.rb b/lib/arel/engines/sql/formatters.rb index 08a32843c9..ae80feb18e 100644 --- a/lib/arel/engines/sql/formatters.rb +++ b/lib/arel/engines/sql/formatters.rb @@ -14,18 +14,17 @@ module Arel class SelectClause < Formatter def attribute(attribute) # FIXME this should check that the column exists - if attribute.name.to_s =~ /^\w*$/ - "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" + (attribute.alias ? " AS #{quote(attribute.alias.to_s)}" : "") - else - attribute.name.to_s + (attribute.alias ? " AS #{quote(attribute.alias.to_s)}" : "") - end + "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" + + (attribute.alias ? " AS #{quote(attribute.alias.to_s)}" : "") end def expression(expression) if expression.function_sql == "DISTINCT" - "#{expression.function_sql} #{expression.attribute.to_sql(self)}" + (expression.alias ? " AS #{quote_column_name(expression.alias)}" : '') + "#{expression.function_sql} #{expression.attribute.to_sql(self)}" + + (expression.alias ? " AS #{quote_column_name(expression.alias)}" : '') else - "#{expression.function_sql}(#{expression.attribute.to_sql(self)})" + (expression.alias ? " AS #{quote_column_name(expression.alias)}" : " AS #{expression.function_sql.to_s.downcase}_id") + "#{expression.function_sql}(#{expression.attribute.to_sql(self)})" + + (expression.alias ? " AS #{quote_column_name(expression.alias)}" : " AS #{expression.function_sql.to_s.downcase}_id") end end @@ -93,11 +92,8 @@ module Arel end def table(table) - if table.name =~ /^(\w|-)*$/ - quote_table_name(table.name) + (table.name != name_for(table) ? " AS " + quote_table_name(name_for(table)) : '') - else - table.name + (table.name != name_for(table) ? " AS " + (name_for(table)) : '') - end + quote_table_name(table.name) + + (table.name != name_for(table) ? " AS " + quote_table_name(name_for(table)) : '') end end @@ -106,10 +102,6 @@ module Arel quote(scalar, environment.column) end - def array(array) - "(" + array.collect { |e| e.to_sql(self) }.join(', ') + ")" - end - def range(left, right) "#{left} AND #{right}" end |