Extract PL/SQL boolean conversion helpers in ProcedureCall#293
Merged
Conversation
The `value.nil? ? nil : (value ? 1 : 0)` and `value.nil? ? nil : value == 1` patterns and the `data_type: "NUMBER", data_precision: 1` metadata override were each repeated across `add_argument`, `record_assignment_sql_values_metadata`, `add_return_variable`, and `return_variable_value`. Collapse them into three private helpers so the BOOLEAN-as-NUMBER(1) trick has a single point of change. No behavior change. `spec/plsql/procedure_spec.rb` is green (195 examples, 0 failures, 1 pre-existing pending). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3e729fe to
14e76d6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ProcedureCallhad the same two-and-a-half boolean conversion patterns scattered across four call sites:value.nil? ? nil : (value ? 1 : 0)(Ruby →NUMBER(1)for bind values) — 2 sitesnumeric_value.nil? ? nil : numeric_value == 1(NUMBER(1)→ Ruby on the way back) — 2 sitesmetadata.merge(data_type: "NUMBER", data_precision: 1)(override the bind metadata so the BOOLEAN parameter rides on a NUMBER bind) — 4 sitesPL/SQL
BOOLEANcannot be bound through the SQL layer, so the library swaps in aNUMBER(1)bind and re-assigns on the server side. That trick currently has its conversion code copy-pasted acrossadd_argument,record_assignment_sql_values_metadata,add_return_variable, andreturn_variable_value, which makes any future change to how booleans are marshalled (e.g. accepting'Y'/'N', aligning JDBC) a multi-site edit.This PR introduces three small
privatehelpers and one frozen constant onProcedureCall, and replaces the eight call sites. Behavior is unchanged.Out of scope on purpose:
CASE WHEN ... THEN 1 ...,IF ... THEN o_x := 1 ...) that build the server-side conversion remain unchanged — those are SQL generation, not Ruby-side value conversion.jdbc_connection.rb,oci_connection.rb, andprocedure.rbboolean handling are not touched in this PR.Diff stat:
lib/plsql/procedure_call.rb | 30 ++++++++++++++++++++++--------(+22 / -8), no other files modified.Test plan
bundle exec rspec spec/plsql/procedure_spec.rb -e "boolean"— 15 examples, 0 failuresbundle exec rspec spec/plsql/procedure_spec.rb— 195 examples, 0 failures, 1 pre-existing pending (the Oracle 9.2 indexed-by-binary-integer skip atprocedure_spec.rb:1525)ruby -c lib/plsql/procedure_call.rbpassesvalue.nil? ? nil : (value ? 1 : 0),nil? ? nil : * == 1, or the literaldata_type: "NUMBER", data_precision: 1outside the new helpers/constantTested locally against Oracle AI Database 23ai Free (
FREEPDB1) on macOS with MRI Ruby 4.0.4 + ruby-oci8 2.2.14. CI will exercise the JDBC path as well.🤖 Generated with Claude Code