highBandWidth
highBandWidth

Reputation: 17321

MySQL connection execution in Ruby error handling

How do I do error handling with something like this in RoR:

conn = Person.connection
conn.execute(sql_stmt)

What if there were errors while executing the SQL?

Upvotes: 0

Views: 225

Answers (1)

mu is too short
mu is too short

Reputation: 434665

The execute method is just a wrapper for the connection's query method and that will raise an Mysql::Error exception if something is wrong. If you use mysql2 instead of the older mysql gem, then I think you'll get a Mysql2::Error exception.

Upvotes: 1

Related Questions