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/-/06i7cgTqChUJ.
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.