Permalink
Browse files

Oracle needs sequence value for primary key in INSERT statement

  • Loading branch information...
1 parent a12358b commit c3e1ef0b4051c515fa2e3f49ea47309c79a89aee @rsim rsim committed Mar 22, 2009
Showing with 8 additions and 1 deletion.
  1. +8 −1 activerecord/test/cases/database_statements_test.rb
@@ -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

0 comments on commit c3e1ef0

Please sign in to comment.