Skip to content
Browse files

translate exceptions on prepared statement failure

  • Loading branch information...
1 parent 7d14e03 commit e0b623a938583f8c02d925d2f812cc32dfed879e @tenderlove tenderlove committed Jan 14, 2014
View
13 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -353,6 +353,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",
@@ -362,11 +369,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)
View
6 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -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 e0b623a

Please sign in to comment.
Something went wrong with that request. Please try again.