Permalink
Browse files

translate exceptions on prepared statement failure

  • Loading branch information...
1 parent c1bbf1b commit 9bc303cae2693c4394abb8363ed4dbdd9638bde3 @tenderlove tenderlove committed Jan 15, 2014
@@ -349,6 +349,13 @@ def close
protected
+ def translate_exception(e, sql)
+ message = "#{e.class.name}: #{e.message}: #{sql}"
+ @logger.error message if @logger
+ exception = translate_exception(e, message)
+ exception.set_backtrace e.backtrace
+ end
+
def log(sql, name = "SQL", binds = [], statement_name = nil)
@instrumenter.instrument(
"sql.active_record",
@@ -358,11 +365,7 @@ def log(sql, name = "SQL", binds = [], statement_name = nil)
:statement_name => statement_name,
:binds => binds) { yield }
rescue => e
- message = "#{e.class.name}: #{e.message}: #{sql}"
- @logger.error message if @logger
- exception = translate_exception(e, message)
- exception.set_backtrace e.backtrace
- raise exception
+ raise translate_exception(e, sql)
end
def translate_exception(exception, message)
@@ -853,7 +853,11 @@ def prepare_statement(sql)
sql_key = sql_key(sql)
unless @statements.key? sql_key
nextkey = @statements.next_key
- @connection.prepare nextkey, sql
+ begin
+ @connection.prepare nextkey, sql
+ rescue => e
+ raise translate_exception(e, sql)
+ end
# Clear the queue
@connection.get_last_result
@statements[sql_key] = nextkey

0 comments on commit 9bc303c

Please sign in to comment.