Mysql2 throws errors on invalid dates. Need suggestion for catching

A dataset I’m working with has bad dates in it (2010-00-09 for
example). This causes Mysql2 to throw an error at the adapter level.
How am I supposed to catch it so I can handle it correctly? I don’t
think it fails in ActiveRecord land, so I’m not sure how to handle it.

I figured since Rails 3 uses it by default, someone here would have
some experience.

I know I could fix the data, but I’m not sure when/if another batch
will come in like that and I want to make sure my app is bulletproof.

Thanks

On 14 sep, 07:11, Robert R. [email protected] wrote:

I know I could fix the data, but I’m not sure when/if another batch
will come in like that and I want to make sure my app is bulletproof.

Seems like you should fix the data, and add validations to ensure that
bad data doesn’t get into the database again.

Cheers,
Wincent

I’m not in control of the data and it comes in external to my app.
It’s an infrastructure I can’t change.

If I had control, I would do what you suggested.

make a before save method in the model and user a regular expression to
translate the date i do something similar changing oracle to mysql.

Please quote when replying. It’s very hard to follow the discussion
otherwise.

Robert R. wrote:

I’m not in control of the data and it comes in external to my app.
It’s an infrastructure I can’t change.

If I had control, I would do what you suggested.

Well, if you’re getting fed bad data, it’s not reasonable for your
end-users to expect good results. Garbage in, garbage out.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]