Skip to content

Commit 8636ce4

Browse files
yahondajoschugclaude
committed
Strip precision from TIMESTAMP data types in %ROWTYPE fields
ALL_TAB_COLUMNS.DATA_TYPE includes precision for TIMESTAMP and INTERVAL types (e.g., TIMESTAMP(6) WITH LOCAL TIME ZONE) even when declared without explicit precision. Strip it to match the exact strings expected by type mapping in oci_connection.rb, jdbc_connection.rb, and procedure_call.rb. Uses the same approach as table.rb: data_type.sub(/\(\d+\)/, "") Co-Authored-By: Jochen Schug <4573581+joschug@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3a7a307 commit 8636ce4

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/plsql/procedure.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ def get_field_definitions(argument_metadata) # :nodoc:
397397

398398
col_no, col_name, col_type_name, col_length, col_precision, col_scale, col_char_length, col_char_used = r
399399

400+
# remove scale (n) from data_type (returned for TIMESTAMPs and INTERVALs)
401+
col_type_name = col_type_name.sub(/\(\d+\)/, "")
402+
400403
fields[col_name.downcase.to_sym] = {
401404
position: col_no.to_i,
402405
data_type: col_type_name,

spec/plsql/procedure_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,6 +2427,44 @@ def new_candidate(status)
24272427
end
24282428
end
24292429

2430+
describe "Function with TIMESTAMP columns in %ROWTYPE" do
2431+
before(:all) do
2432+
plsql.connect! CONNECTION_PARAMS
2433+
plsql.execute "DROP FUNCTION test_timestamp_fn" rescue nil
2434+
plsql.execute "DROP TABLE test_timestamp_tbl" rescue nil
2435+
plsql.execute <<-SQL
2436+
CREATE TABLE test_timestamp_tbl (
2437+
id NUMBER,
2438+
ts TIMESTAMP,
2439+
ts_tz TIMESTAMP WITH TIME ZONE,
2440+
ts_ltz TIMESTAMP WITH LOCAL TIME ZONE
2441+
)
2442+
SQL
2443+
plsql.execute <<-SQL
2444+
CREATE OR REPLACE FUNCTION test_timestamp_fn(p_rec test_timestamp_tbl%ROWTYPE)
2445+
RETURN NUMBER
2446+
IS
2447+
BEGIN
2448+
RETURN p_rec.id;
2449+
END;
2450+
SQL
2451+
end
2452+
2453+
after(:all) do
2454+
plsql.execute "DROP FUNCTION test_timestamp_fn" rescue nil
2455+
plsql.execute "DROP TABLE test_timestamp_tbl" rescue nil
2456+
plsql.logoff
2457+
end
2458+
2459+
it "should strip precision from TIMESTAMP data types in %ROWTYPE fields" do
2460+
procedure = PLSQL::Procedure.find(plsql, :test_timestamp_fn)
2461+
fields = procedure.arguments[0][:p_rec][:fields]
2462+
expect(fields[:ts][:data_type]).to eq("TIMESTAMP")
2463+
expect(fields[:ts_tz][:data_type]).to eq("TIMESTAMP WITH TIME ZONE")
2464+
expect(fields[:ts_ltz][:data_type]).to eq("TIMESTAMP WITH LOCAL TIME ZONE")
2465+
end
2466+
end
2467+
24302468
describe "Function with TABLE OF %ROWTYPE parameter defined in package" do
24312469
before(:all) do
24322470
plsql.connect! CONNECTION_PARAMS

0 commit comments

Comments
 (0)