aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2010-02-18 19:17:55 -0300
committerEmilio Tagua <miloops@gmail.com>2010-02-18 19:17:55 -0300
commit18b2a3ce6b4519b7d5e0f4a63bc6cfb5b8808632 (patch)
treec83e7c71104776801ed63f283f7e32341ef913a7 /lib
parent39d88b8bce309fe9bdc1011b312c857ef194fbfa (diff)
downloadrails-18b2a3ce6b4519b7d5e0f4a63bc6cfb5b8808632.tar.gz
rails-18b2a3ce6b4519b7d5e0f4a63bc6cfb5b8808632.tar.bz2
rails-18b2a3ce6b4519b7d5e0f4a63bc6cfb5b8808632.zip
Insertions should use insert and not execute to get a valid returning
value. Moved clasuses to Arel::Relation.
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/engines/sql/engine.rb2
-rw-r--r--lib/arel/engines/sql/relations/compiler.rb23
-rw-r--r--lib/arel/engines/sql/relations/relation.rb28
-rw-r--r--lib/arel/engines/sql/relations/writes.rb4
4 files changed, 30 insertions, 27 deletions
diff --git a/lib/arel/engines/sql/engine.rb b/lib/arel/engines/sql/engine.rb
index 79011a3db5..f0991f0a0f 100644
--- a/lib/arel/engines/sql/engine.rb
+++ b/lib/arel/engines/sql/engine.rb
@@ -20,7 +20,7 @@ module Arel
module CRUD
def create(relation)
- connection.execute(relation.to_sql)
+ connection.insert(relation.to_sql(false), nil, relation.primary_key)
end
def read(relation)
diff --git a/lib/arel/engines/sql/relations/compiler.rb b/lib/arel/engines/sql/relations/compiler.rb
index 185f1a5c87..c974e43b88 100644
--- a/lib/arel/engines/sql/relations/compiler.rb
+++ b/lib/arel/engines/sql/relations/compiler.rb
@@ -39,29 +39,6 @@ module Arel
parts.compact.join(" ")
end
- def from_clauses
- sources.blank? ? table_sql(Sql::TableReference.new(relation)) : sources
- end
-
- def select_clauses
- attributes.collect { |a| a.to_sql(Sql::SelectClause.new(relation)) }
- end
-
- def where_clauses
- wheres.collect { |w| w.to_sql(Sql::WhereClause.new(relation)) }
- end
-
- def group_clauses
- groupings.collect { |g| g.to_sql(Sql::GroupClause.new(relation)) }
- end
-
- def having_clauses
- havings.collect { |g| g.to_sql(Sql::HavingClause.new(relation)) }
- end
-
- def order_clauses
- orders.collect { |o| o.to_sql(Sql::OrderClause.new(relation)) }
- end
end
end
diff --git a/lib/arel/engines/sql/relations/relation.rb b/lib/arel/engines/sql/relations/relation.rb
index 5038e1db81..52b91c71ea 100644
--- a/lib/arel/engines/sql/relations/relation.rb
+++ b/lib/arel/engines/sql/relations/relation.rb
@@ -25,8 +25,34 @@ module Arel
@primary_key ||= begin
table.name.classify.constantize.primary_key
rescue NameError
- "id"
+ nil
end
end
+
+ protected
+
+ def from_clauses
+ sources.blank? ? table_sql(Sql::TableReference.new(self)) : sources
+ end
+
+ def select_clauses
+ attributes.collect { |a| a.to_sql(Sql::SelectClause.new(self)) }
+ end
+
+ def where_clauses
+ wheres.collect { |w| w.to_sql(Sql::WhereClause.new(self)) }
+ end
+
+ def group_clauses
+ groupings.collect { |g| g.to_sql(Sql::GroupClause.new(self)) }
+ end
+
+ def having_clauses
+ havings.collect { |g| g.to_sql(Sql::HavingClause.new(self)) }
+ end
+
+ def order_clauses
+ orders.collect { |o| o.to_sql(Sql::OrderClause.new(self)) }
+ end
end
end
diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb
index 00cd61cdde..0a6250a3b9 100644
--- a/lib/arel/engines/sql/relations/writes.rb
+++ b/lib/arel/engines/sql/relations/writes.rb
@@ -10,7 +10,7 @@ module Arel
end
class Insert < Compound
- def to_sql
+ def to_sql(include_returning = true)
insertion_attributes_values_sql = if record.is_a?(Value)
record.value
else
@@ -33,7 +33,7 @@ module Arel
"INSERT",
"INTO #{table_sql}",
insertion_attributes_values_sql,
- ("RETURNING #{engine.quote_column_name(primary_key)}" if compiler.supports_insert_with_returning?)
+ ("RETURNING #{engine.quote_column_name(primary_key)}" if include_returning && compiler.supports_insert_with_returning?)
end
end