Rails on Oracle

Posted by Mike Blake Thu, 29 Mar 2007 21:15:00 GMT

When rails on jruby and connecting to Oracle via JDBC ,the following error eventually appears:

Update: java.sql.SQLException: Io exception: Broken pipe

Fix:

You need a dedicated connection from Oracle. Change the url: line in database.yml from url: jdbc:oracle:thin:@localhost:1521:XE to url: jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS =(PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))) (CONNECT_DATA =(SERVER = DEDICATED) (SID = XE)))
  1. Workarounds

Duplicating an existing Oracle Database using the build in task rake db:test:clone presented a few problems. Here’s what I did to work around them.

  1. ORA-01727: numeric precision specifier is out of range
OCIError: ORA-01727: numeric precision specifier is out of range (1 to 38): CREATE TABLE employee (id NUMBER(38) NOT NULL PRIMARY KEY, created_date DATE DEFAULT NULL, start_date DATE DEFAULT NULL, job_id DECIMAL DEFAULT NULL, total_hours NUMBER(126) DEFAULT NULL)

Fix:

For some reason whne rails dumps the schema, it reports Oracle type FLOAT as NUMBER, so you just need to changed that back to FLOAT if you want to import that schema.

###OCIError: ORA-00972 identifier is too long: OCIError: ORA-00972: identifier is too long: CREATE SEQUENCE gametime\_responsibility\_ref\_seq START WITH 10000

Fix:

Rails tries to create sequences in Oracle to handle AUTOINCREMENT id fields. It uses TABLE_NAME = ‘_SEQ’ for the sequence name. If a sqequence name is too long then you have to shorten it in schema.rb .

OCIError: ORA-00907: missing right parenthesis

OCIError: ORA-00907: missing right parenthesis: CREATE TABLE board (id NUMBER(38) NOT NULL PRIMARY KEY, name VARCHAR2(150) NOT NULL, name VARCHAR2(150) NOT NULL, parent VARCHAR2(150) DEFAULT NULL, log_level DECIMAL DEFAULT NULL, modified_date DATE(6) DEFAULT NULL, token DECIMAL DEFAULT NULL)

Fix:

For some reason Rails assigns Date fields a size in schema.rb . You’ll need to change all occurances of DATE to DATE .

Posted in  | Tags , , ,  | 1 comment