From de843c86518e4ac871d4bb5b0873bb6c184ac304 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 4 May 2009 21:50:44 -0300 Subject: Fixes for PostgreSQL: always alias expresions and quote values. --- lib/arel/relations/operations/project.rb | 6 +++--- lib/arel/sql/formatters.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/arel') diff --git a/lib/arel/relations/operations/project.rb b/lib/arel/relations/operations/project.rb index d7835edda4..5507ea3163 100644 --- a/lib/arel/relations/operations/project.rb +++ b/lib/arel/relations/operations/project.rb @@ -2,7 +2,7 @@ module Arel class Project < Compound attributes :relation, :projections deriving :== - + def initialize(relation, *projections, &block) @relation = relation @projections = (projections + (block_given?? [yield(relation)] : [])).collect { |p| p.bind(relation) } @@ -11,9 +11,9 @@ module Arel def attributes @attributes ||= projections.collect { |p| p.bind(self) } end - + def externalizable? attributes.any?(&:aggregation?) or relation.externalizable? end end -end \ No newline at end of file +end diff --git a/lib/arel/sql/formatters.rb b/lib/arel/sql/formatters.rb index aa10952d04..d8618ca2cc 100644 --- a/lib/arel/sql/formatters.rb +++ b/lib/arel/sql/formatters.rb @@ -25,7 +25,7 @@ module Arel if expression.function_sql == "DISTINCT" "#{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)}" : '') + "#{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 @@ -69,7 +69,7 @@ module Arel end def value(value) - value.to_sql(self) + quote value.to_sql(self) end def scalar(value, column = nil) -- cgit v1.2.3