1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Revert "Merge pull request #482 from kirs/multiple-insert"

This reverts commit 6d105c7f89, reversing
changes made to 437aa3a4bb.

This broke Active Record when the values are sql literals
This commit is contained in:
Rafael Mendonça França 2017-05-04 15:13:58 -07:00
parent 6d105c7f89
commit a98c9bdbdd
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
7 changed files with 5 additions and 54 deletions

View file

@ -37,12 +37,8 @@ module Arel
self
end
def create_values values, columns = nil
def create_values values, columns
Nodes::Values.new values, columns
end
def create_tuple values
Nodes::Tuple.new values
end
end
end

View file

@ -6,7 +6,6 @@ require 'arel/nodes/select_core'
require 'arel/nodes/insert_statement'
require 'arel/nodes/update_statement'
require 'arel/nodes/bind_param'
require 'arel/nodes/tuple'
# terminal

View file

@ -1,13 +0,0 @@
# frozen_string_literal: true
module Arel
module Nodes
class Tuple < Node
attr_reader :values
def initialize(values)
@values = values
super()
end
end
end
end

View file

@ -131,7 +131,6 @@ module Arel
end
if o.values
collector << " VALUES"
maybe_visit o.values, collector
elsif o.select
maybe_visit o.select, collector
@ -167,19 +166,8 @@ module Arel
collector << "FALSE"
end
def visit_Arel_Nodes_Tuple o, collector
len = o.values.length - 1
o.values.each_with_index { |value, i|
collector = visit value, collector
unless i == len
collector << COMMA
end
}
collector
end
def visit_Arel_Nodes_Values o, collector
collector << "("
collector << "VALUES ("
len = o.expressions.length - 1
o.expressions.each_with_index { |value, i|

View file

@ -28,25 +28,6 @@ module Arel
}
end
it 'inserts multiple values' do
table = Table.new(:users)
manager = Arel::InsertManager.new
manager.into table
manager.columns << table[:id]
manager.columns << table[:name]
manager.values = manager.create_tuple([
manager.create_values(%w{ 1 david }),
manager.create_values(%w{ 2 kirs }),
manager.create_values(["3", Arel.sql('DEFAULT')], []),
])
manager.to_sql.must_be_like %{
INSERT INTO \"users\" (\"id\", \"name\") VALUES ('1', 'david'), ('2', 'kirs'), ('3', DEFAULT)
}
end
it "inserts false" do
table = Table.new(:users)
manager = Arel::InsertManager.new

View file

@ -42,10 +42,10 @@ module Arel
end
it 'should return an insert manager' do
im = @relation.compile_insert '(NULL)'
im = @relation.compile_insert 'VALUES(NULL)'
assert_kind_of Arel::InsertManager, im
im.into Table.new(:users)
assert_equal "INSERT INTO \"users\" VALUES (NULL)", im.to_sql
assert_equal "INSERT INTO \"users\" VALUES(NULL)", im.to_sql
end
describe 'skip' do

View file

@ -26,7 +26,7 @@ module Arel
bp = Nodes::BindParam.new
values = Nodes::Values.new([bp])
sql = compile values
sql.must_be_like '(?)'
sql.must_be_like 'VALUES (?)'
end
it 'can define a dispatch method' do