aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-07-01 20:29:33 -0300
committerEmilio Tagua <miloops@gmail.com>2009-07-01 20:29:33 -0300
commit808b9e90a38c6c19e109da8eb5f2a264fd780d9a (patch)
treede89ed495a0462f5e2c74be9fa3dbacae7c18124 /lib
parent97811698ab0e68b33fbf3067c3764e385dd75d53 (diff)
downloadrails-808b9e90a38c6c19e109da8eb5f2a264fd780d9a.tar.gz
rails-808b9e90a38c6c19e109da8eb5f2a264fd780d9a.tar.bz2
rails-808b9e90a38c6c19e109da8eb5f2a264fd780d9a.zip
Allow SQL strings to insert query. Insert should better return engine's result.
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/engines/sql/relations/writes.rb11
-rw-r--r--lib/arel/session.rb1
2 files changed, 8 insertions, 4 deletions
diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb
index b90d380c64..d648a54d91 100644
--- a/lib/arel/engines/sql/relations/writes.rb
+++ b/lib/arel/engines/sql/relations/writes.rb
@@ -11,11 +11,17 @@ module Arel
class Insert < Compound
def to_sql(formatter = nil)
+ insertion_attributes_values_sql = if record.is_a?(Value)
+ record.value
+ else
+ build_query "(#{record.keys.collect { |key| engine.quote_column_name(key.name) }.join(', ')})",
+ "VALUES (#{record.collect { |key, value| key.format(value) }.join(', ')})"
+ end
+
build_query \
"INSERT",
"INTO #{table_sql}",
- "(#{record.keys.collect { |key| engine.quote_column_name(key.name) }.join(', ')})",
- "VALUES (#{record.collect { |key, value| key.format(value) }.join(', ')})"
+ insertion_attributes_values_sql
end
end
@@ -28,7 +34,6 @@ module Arel
end
protected
-
def assignment_sql
if assignments.respond_to?(:collect)
assignments.collect do |attribute, value|
diff --git a/lib/arel/session.rb b/lib/arel/session.rb
index abef5c543b..cf04e8a93a 100644
--- a/lib/arel/session.rb
+++ b/lib/arel/session.rb
@@ -24,7 +24,6 @@ module Arel
module CRUD
def create(insert)
insert.call
- insert
end
def read(select)