Thanks Jeremy for the response. Using the autosequence worked for the
project I was working on at the time. For a different project, the
sequences are created outside of Sequel and I'm having the same problem as
above.
Looking at your response from before:
Server.dataset = Server.dataset.sequence(:sequence_name)
I'm not sure I understand where to use this. Can it not be specified by
the model somehow? (self.sequence_name = 'foo') ?
Thanks for any clarification here, i"ll keep poking around.
On Wednesday, April 18, 2012 11:29:28 AM UTC-4, Jeremy Evans wrote:
>
> On Wednesday, April 18, 2012 6:56:19 AM UTC-7, Jason Hines wrote:
>>
>> Using the following gems on Oracle 11g
>>
>> gem 'sequel', '3.32.0'
>> gem 'ruby-oci8', '2.1.0'
>>
>> I have the following table in place:
>>
>> DB.create_table :servers do
>> primary_key :id
>> String :site
>> String :p4port
>> String :service
>> String :monitored
>> end
>>
>> I have a working sequence and trigger in place to provide auto_increment
>> functionality when inserting into this table.
>>
>> I can verify that this works by issuing an INSERT SQL statement directly
>> (omitting the id field) into an Oracle client.
>>
>> In Rails, my controller attempts to create a new record using Sequel
>> model:
>>
>> # model
>> class Server < Sequel::Model
>> end
>>
>> # controller
>> @server = Server.new
>> @server.site = params[:site]
>> @server.p4port = params[:p4port]
>> @server.service = params[:service]
>> @server.monitored = params[:monitored]
>> @server.save
>>
>> This results in the following error:
>>
>> (0.000007s) Transaction.begin
>> (0.001127s) INSERT INTO "SERVERS" ("SITE", "P4PORT", "SERVICE",
>> "MONITORED") VALUES ('SVL', 'foobar:1666', 'PRODUCTION', 'Y')
>> (0.000891s) SELECT * FROM (SELECT * FROM "SERVERS" WHERE ("ID" IS NULL))
>> "T1" WHERE (ROWNUM <= 1)
>> (0.003289s) Transaction.rollback
>> Completed 500 Internal Server Error in 10ms
>>
>> Sequel::Error (Record not found):
>> app/controllers/admin/servers_controller.rb:18:in `create'
>>
>> (line 18 is the @server.save line)
>>
>>
>> The WHERE ID IS NULL clause is suspicious, as it appears that the trigger
>> is not being fired. I'm baffled by this because the trigger *does* work
>> properly outside of Sequel.
>>
>> Any ideas?
>>
>>
> Sequel needs Dataset#insert to return the inserted primary key value. On
> Oracle, this doesn't happen by default, you need to set the sequence to
> use. You can try:
>
> DB.autosequence = true
>
> to assume that a sequence exists that matches Sequel's default sequence
> name format. Since you are using Sequel to create the table, it should
> work.
>
> If you are not using Sequel to create the sequence, or you are using a
> non-default sequence name, you must manually set the sequence:
>
> Server.dataset = Server.dataset.sequence(:sequence_name)
>
> Jeremy
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/lSvQjYFEnLMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.