aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-05-04 21:50:44 -0300
committerEmilio Tagua <miloops@gmail.com>2009-05-04 21:50:44 -0300
commitde843c86518e4ac871d4bb5b0873bb6c184ac304 (patch)
treed9d7a3668fe219bce3ae7f7e1954f208b1df6d1b /lib
parentf44853a5aa7f4481d99a3af4585f3a51272bc7f7 (diff)
downloadrails-de843c86518e4ac871d4bb5b0873bb6c184ac304.tar.gz
rails-de843c86518e4ac871d4bb5b0873bb6c184ac304.tar.bz2
rails-de843c86518e4ac871d4bb5b0873bb6c184ac304.zip
Fixes for PostgreSQL: always alias expresions and quote values.
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/relations/operations/project.rb6
-rw-r--r--lib/arel/sql/formatters.rb4
2 files changed, 5 insertions, 5 deletions
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)