提交 c3e1ef0b 编写于 作者: R Raimonds Simanovskis

Oracle needs sequence value for primary key in INSERT statement

上级 a12358b3
......@@ -6,7 +6,14 @@ def setup
end
def test_insert_should_return_the_inserted_id
id = @connection.insert("INSERT INTO accounts (firm_id,credit_limit) VALUES (42,5000)")
# 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)
else
id = @connection.insert("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.
先完成此消息的编辑!
想要评论请 注册