How to catch Oracle errors in a rake task

How can I trap the following Oracle error in a rake task? I can trap
most Oracle errors in the website with “@phone.errors.count > 0”, but
in the rake task the task stops before a check can be done.

The rake task used to work before the Oracle DB administrator decided
to put in foreign key, integrity constraints in Oracle.

rake aborted!
OCIError: ORA-00001: unique constraint (OWNER.PHONE_NUMBERS_PK)
violated: INSERT INTO phone_numbers

thanks for the response.
I have “validates_uniqueness_of :phone_number” in the model, and it
worked fine until the DBA got involved.
Now for this error, Oracle just causes the rake task to abort rather
than returning an error.

On Thu, Feb 11, 2010 at 12:48 PM, sultan [email protected]
wrote:

How can I trap the following Oracle error in a rake task?

Ruby has exception handling:

http://ruby-doc.org/docs/ProgrammingRuby/html/tut_exceptions.html

I can trap
most Oracle errors in the website with “@phone.errors.count > 0”, but
in the rake task the task stops before a check can be done.

The rake task used to work before the Oracle DB administrator decided
to put in foreign key, integrity constraints in Oracle.

You can do a find to see if you are about to cause an exceptions
before you cause it.

rake aborted!
OCIError: ORA-00001: unique constraint (OWNER.PHONE_NUMBERS_PK)
violated: INSERT INTO phone_numbers

You need to duplicate this constraint in the model using
validates_uniqueness_of :phone_number.


Greg D.
destiney.com | gregdonald.com

On Thu, Feb 11, 2010 at 1:23 PM, sultan [email protected] wrote:

thanks for the response.
I have “validates_uniqueness_of :phone_number” in the model, and it
worked fine until the DBA got involved.
Now for this error, Oracle just causes the rake task to abort rather
than returning an error.

The DBA is doing exactly what she should be doing, IMHO.

Clean up your data. Stop breaking the foreign key constraints.


Greg D.
destiney.com | gregdonald.com

The data is fine, and I am not trying to break any foreign key
constraints.
I am getting an error on an insert, all I need to know is how to
capture the error before Oracle aborts the rake task.
Can I request you to respectfully to bow out of this conversion, so
that someone else may try to help?

On Thu, Feb 11, 2010 at 1:58 PM, sultan [email protected] wrote:

The data is fine, and I am not trying to break any foreign key
constraints.
I am getting an error on an insert, all I need to know is how to
capture the error before Oracle aborts the rake task.
Can I request you to respectfully to bow out of this conversion, so
that someone else may try to help?

Sure thing. I’m guessing lots of people are dying to assist you with
fixing your broken DBA.


Greg D.
destiney.com | gregdonald.com