Skip to content
Browse files

log every sql statement, even when they error

  • Loading branch information...
1 parent 19fc886 commit 98e001641ff0f859349cd60d270fec972edc16de @tenderlove tenderlove committed Oct 4, 2013
Showing with 25 additions and 25 deletions.
  1. +25 −25 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
View
50 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -772,32 +772,32 @@ def exec_no_cache(sql, name, binds)
end
def exec_cache(sql, name, binds)
+ stmt_key = prepare_statement(sql)
+
log(sql, name, binds) do
- begin
- stmt_key = prepare_statement(sql)
-
- @connection.send_query_prepared(stmt_key, binds.map { |col, val|
- type_cast(val, col)
- })
- @connection.block
- @connection.get_last_result
- rescue PGError => e
- # Get the PG code for the failure. Annoyingly, the code for
- # prepared statements whose return value may have changed is
- # FEATURE_NOT_SUPPORTED. Check here for more details:
- # http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/cache/plancache.c#l573
- begin
- code = e.result.result_error_field(PGresult::PG_DIAG_SQLSTATE)
- rescue
- raise e
- end
- if FEATURE_NOT_SUPPORTED == code
- @statements.delete sql_key(sql)
- retry
- else
- raise e
- end
- end
+ @connection.send_query_prepared(stmt_key, binds.map { |col, val|
+ type_cast(val, col)
+ })
+ @connection.block
+ @connection.get_last_result
+ end
+ rescue ActiveRecord::StatementInvalid => e
+ pgerror = e.original_exception
+
+ # Get the PG code for the failure. Annoyingly, the code for
+ # prepared statements whose return value may have changed is
+ # FEATURE_NOT_SUPPORTED. Check here for more details:
+ # http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/cache/plancache.c#l573
+ begin
+ code = pgerror.result.result_error_field(PGresult::PG_DIAG_SQLSTATE)
+ rescue
+ raise e
+ end
+ if FEATURE_NOT_SUPPORTED == code
+ @statements.delete sql_key(sql)
+ retry
+ else
+ raise e
end
end

0 comments on commit 98e0016

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