1

I am trying to insert a record into an Oracle database

I have a class that inherits from ActiveRecord:

DuplicateTransaction < ActiveRecord::Base
set_table_name "TRANSACTION"

I then try and insert using this:

DuplicateTransaction.create(key_id: '100123', transaction_uuid: '100111',      
expiry_datetime:'CURRENT_DATE', date_modified: 'CURRENT_DATE', date_created:    
'CURRENT_DATE')

The sql that comes out is:

INSERT INTO "TRANSACTION" ("date_created", "date_modified", "expiry_datetime", "id", 
"key_id", "transaction_uuid") 

The double quotes are making the column names case sensitive and giving me the error: ActiveRecord::StatementInvalid (ActiveRecord::JDBCError: ORA-00904: "transaction_uuid": invalid identifier

How can I either get rid of the double quotes or capitalize the column names?

Kevin White
  • 335
  • 1
  • 3
  • 8

2 Answers2

1

After looking at this it looks like you need to define an alias for the column (although I have not tried it):

alias_attribute :Date_Created, :date_created #or however you need to do the new name
Community
  • 1
  • 1
ScottJShea
  • 7,041
  • 11
  • 44
  • 67
1

The Oracle Enhanced Adapter seems to handle things correctly for Oracle - https://github.com/rsim/oracle-enhanced

I tried it out in both MRI and JRuby. It still produces quoted column names, but they are all in uppercase, eg:

jruby-1.6.5.1 :002 > u = User.create(:name => 'james')
SQL (15.0ms)  INSERT INTO "USERS" ("ID", "NAME") VALUES (:a1, :a2)  [["id", 22], ["name", "james"]] => #<User id: 22, name: "james"> 

My setup is:

[sodonnel@home testapp]$ jruby -v
jruby 1.6.5.1 (ruby-1.9.2-p136) (2011-12-27 1bf37c2) (OpenJDK 64-Bit Server VM 1.6.0_20) [linuxamd64-java]
[sodonnel@home testapp]$ rails -v
Rails 3.2.1 

Edit:

Also using plain jdbc adapter things seem to work fine on my setup.

Stephen ODonnell
  • 4,441
  • 17
  • 19