提交 326b12ae 编写于 作者: R Ryuta Kamizono

Fix `connection#create` in PG adapter

Originally `connection#create` had aliased to `connection#insert` in PG
adapter. But it was broken by #7447. Re-alias `create` to `insert` for
fixing it.
上级 9fb4efed
......@@ -119,6 +119,7 @@ def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, bind
value = exec_insert(sql, name, binds, pk, sequence_name)
id_value || last_inserted_id(value)
end
alias create insert
# Executes the update statement and returns the number of rows affected.
def update(arel, name = nil, binds = [])
......
......@@ -140,7 +140,6 @@ def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
super
id_value || @connection.last_id
end
alias :create :insert_sql
def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
execute to_sql(sql, binds), name
......
......@@ -90,10 +90,6 @@ def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
end
end
def create
super.insert
end
# The internal PostgreSQL identifier of the money data type.
MONEY_COLUMN_TYPE_OID = 790 #:nodoc:
# The internal PostgreSQL identifier of the BYTEA data type.
......
......@@ -294,7 +294,6 @@ def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #
super
id_value || @connection.last_insert_row_id
end
alias :create :insert_sql
def select_rows(sql, name = nil, binds = [])
exec_query(sql, name, binds).rows
......
......@@ -6,14 +6,23 @@ def setup
end
def test_insert_should_return_the_inserted_id
assert_not_nil return_the_inserted_id(method: :insert)
end
def test_create_should_return_the_inserted_id
assert_not_nil return_the_inserted_id(method: :create)
end
private
def return_the_inserted_id(method:)
# Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
if current_adapter?(:OracleAdapter)
sequence_name = "accounts_seq"
id_value = @connection.next_sequence_value(sequence_name)
id = @connection.insert("INSERT INTO accounts (id, firm_id,credit_limit) VALUES (accounts_seq.nextval,42,5000)", nil, :id, id_value, sequence_name)
@connection.send(method, "INSERT INTO accounts (id, firm_id,credit_limit) VALUES (accounts_seq.nextval,42,5000)", nil, :id, id_value, sequence_name)
else
id = @connection.insert("INSERT INTO accounts (firm_id,credit_limit) VALUES (42,5000)")
@connection.send(method, "INSERT INTO accounts (firm_id,credit_limit) VALUES (42,5000)")
end
assert_not_nil id
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册