diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-01-14 17:38:43 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-01-17 14:09:14 -0800 |
commit | 9bc303cae2693c4394abb8363ed4dbdd9638bde3 (patch) | |
tree | d9b3c410aadce6eeb288b7c140566a1d846acf3a /activerecord | |
parent | c1bbf1b2e412b41340cb48c1c23cddb93f362944 (diff) | |
download | rails-9bc303cae2693c4394abb8363ed4dbdd9638bde3.tar.gz rails-9bc303cae2693c4394abb8363ed4dbdd9638bde3.tar.bz2 rails-9bc303cae2693c4394abb8363ed4dbdd9638bde3.zip |
translate exceptions on prepared statement failure
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 13 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 6 |
2 files changed, 13 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 8aa1ce5c04..d1acef3e53 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -349,6 +349,13 @@ module ActiveRecord 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 @@ module ActiveRecord :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) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 7e188907e1..ebbe918442 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -853,7 +853,11 @@ module ActiveRecord 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 |