Rails 2.1 + Oracle

Hi all,

I am completely new to use Oracle with Rails (was using MySQL before). I
have some trouble to get my code work despite the rails abstraction.

My code was working perfectly with MySQL, but now when I am trying to
save some objects with a :though relation.

So I have a request objects with many relation to others. When I do
request.save I get an OCIError.
I saw that usually ORA-02289 was a problem of rights in the database but
in this case, the user have all rights. rake db:migrate get no errors at
all.

If someone have more experience with Rails and Oracle, you are welcome
:slight_smile:

OCIError (ORA-02289: sequence does not exist):
stmt.c:539:in oci8lib.so
c:/ruby/lib/ruby/gems/1.8/gems/ruby-oci8-1.0.2-x86-mswin32/lib/oci8.rb:753:in
exec' c:/ruby/lib/ruby/gems/1.8/gems/ruby-oci8-1.0.2-x86-mswin32/lib/oci8.rb:142:indo_ocicall’
c:/ruby/lib/ruby/gems/1.8/gems/ruby-oci8-1.0.2-x86-mswin32/lib/oci8.rb:753:in
exec' c:/ruby/lib/ruby/gems/1.8/gems/ruby-oci8-1.0.2-x86-mswin32/lib/oci8.rb:255:inexec’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-oracle-adapter-1.0.0.9250/lib/active_record/connection_adapters/oracle_adapter.rb:700:in
exec' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-oracle-adapter-1.0.0.9250/lib/active_record/connection_adapters/oracle_adapter.rb:229:innext_sequence_value’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2493:in
create_without_callbacks' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/callbacks.rb:220:increate_without_timestamps’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/timestamp.rb:29:in
create' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2472:increate_or_update_without_callbacks’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/callbacks.rb:207:in
create_or_update' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2206:insave_without_validation!’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/validations.rb:911:in
save_without_dirty!' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/dirty.rb:83:insave_without_transactions!’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:110:in
save!' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:66:intransaction’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:79:in
transaction' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:98:intransaction’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:110:in
save!' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:118:inrollback_active_record_state!’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:110:in
save!' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/validations.rb:882:increate!’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/has_many_through_association.rb:61:in
insert_record' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1852:inwith_scope’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/has_many_through_association.rb:61:in
send' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/has_many_through_association.rb:61:ininsert_record’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations.rb:1215:in
send' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations.rb:1215:inafter_create_or_update_associated_records_for_services’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb:274:in
method_missing' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_proxy.rb:175:inmethod_missing’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_proxy.rb:175:in
each' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_proxy.rb:175:insend’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_proxy.rb:175:in
method_missing' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb:274:inmethod_missing’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations.rb:1215:in
after_create_or_update_associated_records_for_services' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:173:insend’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:173:in
evaluate_method' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:161:incall’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:93:in
run' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:92:ineach’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:92:in
send' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:92:inrun’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:272:in
run_callbacks' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/callbacks.rb:298:incallback’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/callbacks.rb:221:in
create_without_timestamps' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/timestamp.rb:29:increate’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2472:in
create_or_update_without_callbacks' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/callbacks.rb:207:increate_or_update’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2200:in
save_without_validation' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/validations.rb:901:insave_without_dirty’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/dirty.rb:75:in
save_without_transactions' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:106:insave’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in
transaction' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:79:intransaction’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:98:in
transaction' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:106:insave’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:118:in
rollback_active_record_state!' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:106:insave’

Ok, I got it to work with enhanced oracle adapter. I think the problems
came from the timestamp column which seems not to be well supported by
the ‘standard’ oracle adapter.

Hi Again,

It seems that using Oracle with Rails is a little bit more complex than
with MySQL.

Is someone is aware of some caching process with Oracle, because I have
the following code:

account_check = AccountRequest.find_by_login(user)

if account_check
flash.now[:notice] = “A request is already pending for this user”
return
end

And despite the fact I have remove all entries in the account_requests
table, the controller still get some old data by oracle when I refresh
the page.

How can I solve this ?

On Tue, Jul 8, 2008 at 3:31 AM, MR Damien
[email protected] wrote:

And despite the fact I have remove all entries in the account_requests
table, the controller still get some old data by oracle when I refresh
the page.

How can I solve this ?

Are you removing them in such a way that Rails knows?

AccountRequest.destroy_all

Also, a newer Oracle has the recycle bin feature, and you may find
calling execute "purge recyclebin" helpful.


Greg D.
http://destiney.com/

Greg D. wrote:

On Tue, Jul 8, 2008 at 3:31 AM, MR Damien
[email protected] wrote:

And despite the fact I have remove all entries in the account_requests
table, the controller still get some old data by oracle when I refresh
the page.

How can I solve this ?

Are you removing them in such a way that Rails knows?

AccountRequest.destroy_all

Also, a newer Oracle has the recycle bin feature, and you may find
calling execute "purge recyclebin" helpful.


Greg D.
http://destiney.com/

Hi,

The problem is solved (I forgot to use ‘commit’ I have used mysql for
too long time). Now I have problems with Oracle Sequences (again as
shown in the first post) …

Kent S. wrote:

On Thu, Jul 10, 2008 at 2:53 AM, MR Damien
[email protected] wrote:

Hi,

The problem is solved (I forgot to use ‘commit’ I have used mysql for
too long time). Now I have problems with Oracle Sequences (again as
shown in the first post) …

Oracle adapter assumes that you have “${table_name}_seq” sequence
defined for each of your tables. Also you can override the sequence
name with ActiveRecord::Base.set_sequence_name method.


Kent

http://www.datanoise.com

I have a sequence for all table but the joined tables (used by has_many
:though), perhaps because of the :id => false option.

On Thu, Jul 10, 2008 at 2:53 AM, MR Damien
[email protected] wrote:

Hi,

The problem is solved (I forgot to use ‘commit’ I have used mysql for
too long time). Now I have problems with Oracle Sequences (again as
shown in the first post) …

Oracle adapter assumes that you have “${table_name}_seq” sequence
defined for each of your tables. Also you can override the sequence
name with ActiveRecord::Base.set_sequence_name method.


Kent

MR Damien wrote:

MR Damien wrote:

I have a sequence for all table but the joined tables (used by has_many
:though), perhaps because of the :id => false option.

Now I removed all :id => false from join table, I have a problem of
ORA-00972: identifier is too long for sequences.

Do you know how to shorten the name of sequences ?

I solved that by shortening the table name

MR Damien wrote:

I have a sequence for all table but the joined tables (used by has_many
:though), perhaps because of the :id => false option.

Now I removed all :id => false from join table, I have a problem of
ORA-00972: identifier is too long for sequences.

Do you know how to shorten the name of sequences ?