Skip to content

Add optional SQL logging spec helper#285

Merged
yahonda merged 2 commits intorsim:masterfrom
yahonda:add-spec-sql-logger
May 7, 2026
Merged

Add optional SQL logging spec helper#285
yahonda merged 2 commits intorsim:masterfrom
yahonda:add-spec-sql-logger

Conversation

@yahonda
Copy link
Copy Markdown
Collaborator

@yahonda yahonda commented May 7, 2026

Summary

  • Add spec/support/sql_logger.rb: prepend a logging module onto PLSQL::OCIConnection and PLSQL::JDBCConnection (exec, cursor_from_query, parse) and route ActiveRecord::Base.logger to the same Logger. Every SQL statement issued during a spec run is written to debug.log in the working directory.
  • Logger arguments ("debug.log", 0, 100 * 1024 * 1024) mirror those used in activerecord-oracle_enhanced-adapter's spec helper, so debug.log rotates the same way.
  • Add debug.log to .gitignore (matching the oracle_enhanced repo's .gitignore entry).
  • Add gem "logger" to the Gemfile because logger became a bundled gem in Ruby 3.5; without this declaration, NO_ACTIVERECORD=1 runs would lose access to it (today it is pulled in transitively only via activerecord).

Test plan

  • bundle exec rspec spec/plsql/sequence_spec.rb — passes; debug.log is created and contains EXEC / QUERY / PARSE lines for the sequence DDL and SELECT seq.NEXTVAL FROM dual queries.
  • bundle exec rspec spec/plsql/schema_spec.rbdebug.log interleaves PL/SQL-side and oracle_enhanced adapter SQL.
  • NO_ACTIVERECORD=1 bundle exec rspec spec/plsql/sequence_spec.rb — works on Ruby 3.5+ thanks to the explicit gem "logger"; only PL/SQL-side SQL is logged.
  • git status after a run shows debug.log ignored.

yahonda added 2 commits May 7, 2026 17:46
Set PLSQL_DEBUG_LOG=debug.log when running rspec to capture every SQL
statement issued by PLSQL::OCIConnection / PLSQL::JDBCConnection (exec,
cursor_from_query, parse) plus any SQL emitted via ActiveRecord::Base
when specs use plsql.activerecord_class. Logger arguments mirror those
used in the activerecord-oracle_enhanced-adapter spec helper.

logger is added to the Gemfile because it is a bundled gem on Ruby 3.5+
and would otherwise be unavailable when NO_ACTIVERECORD=1 (which skips
activerecord, the gem that pulls logger in transitively).
Match the activerecord-oracle_enhanced-adapter convention of writing
spec SQL to debug.log unconditionally. The previous PLSQL_DEBUG_LOG
env var gate is removed so debug.log is always available when tests
fail, and debug.log is added to .gitignore.
@yahonda yahonda merged commit 1a22735 into rsim:master May 7, 2026
20 checks passed
@yahonda yahonda deleted the add-spec-sql-logger branch May 7, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant