From d7f171dae2ce7c8b601fc648d2d209413c8df52d Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Wed, 13 May 2026 10:42:49 +0900 Subject: [PATCH] Move ora_number_to_ruby_number to Connection base class The exact same private method was duplicated character-for-character in both OCIConnection and JDBCConnection. Pull it up into Connection so the "return BigDecimal instead of Float to avoid rounding errors" rule lives in one place; subclasses keep calling it as before via inheritance. Net change: -3 LOC. No behavior change. Full suite is green (468 examples, 0 failures, 1 pre-existing pending). Co-Authored-By: Claude Opus 4.7 (1M context) --- lib/plsql/connection.rb | 7 +++++++ lib/plsql/jdbc_connection.rb | 5 ----- lib/plsql/oci_connection.rb | 5 ----- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/plsql/connection.rb b/lib/plsql/connection.rb index 130ccbc..d6535e7 100644 --- a/lib/plsql/connection.rb +++ b/lib/plsql/connection.rb @@ -266,5 +266,12 @@ def drop_session_ruby_temporary_tables exec "DROP TABLE #{row[0]}" end end + + private + + def ora_number_to_ruby_number(num) + # return BigDecimal instead of Float to avoid rounding errors + num == (num_to_i = num.to_i) ? num_to_i : (num.is_a?(BigDecimal) ? num : BigDecimal(num.to_s)) + end end end diff --git a/lib/plsql/jdbc_connection.rb b/lib/plsql/jdbc_connection.rb index 38ea6cc..66a9ad5 100644 --- a/lib/plsql/jdbc_connection.rb +++ b/lib/plsql/jdbc_connection.rb @@ -588,10 +588,5 @@ def java_timestamp(value) def java_bigdecimal(value) value && java.math.BigDecimal.new(value.to_s) end - - def ora_number_to_ruby_number(num) - # return BigDecimal instead of Float to avoid rounding errors - num == (num_to_i = num.to_i) ? num_to_i : (num.is_a?(BigDecimal) ? num : BigDecimal(num.to_s)) - end end end diff --git a/lib/plsql/oci_connection.rb b/lib/plsql/oci_connection.rb index 9c4caef..f5c868c 100644 --- a/lib/plsql/oci_connection.rb +++ b/lib/plsql/oci_connection.rb @@ -301,11 +301,6 @@ def raw_oci_connection end end - def ora_number_to_ruby_number(num) - # return BigDecimal instead of Float to avoid rounding errors - num == (num_to_i = num.to_i) ? num_to_i : (num.is_a?(BigDecimal) ? num : BigDecimal(num.to_s)) - end - def ora_date_to_ruby_date(val) case val when DateTime