Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/plsql/procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ def get_field_definitions(argument_metadata) # :nodoc:

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

# remove precision (n) from data_type (returned for TIMESTAMPs and INTERVALs)
col_type_name = col_type_name.sub(/\(\d+\)/, "")

fields[col_name.downcase.to_sym] = {
position: col_no.to_i,
data_type: col_type_name,
Expand Down
38 changes: 38 additions & 0 deletions spec/plsql/procedure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,44 @@ def new_candidate(status)
end
end

describe "Function with TIMESTAMP columns in %ROWTYPE" do
before(:all) do
plsql.connect! CONNECTION_PARAMS
plsql.execute "DROP FUNCTION test_timestamp_fn" rescue nil
plsql.execute "DROP TABLE test_timestamp_tbl" rescue nil
plsql.execute <<-SQL
CREATE TABLE test_timestamp_tbl (
id NUMBER,
ts TIMESTAMP,
ts_tz TIMESTAMP WITH TIME ZONE,
ts_ltz TIMESTAMP WITH LOCAL TIME ZONE
)
SQL
plsql.execute <<-SQL
CREATE OR REPLACE FUNCTION test_timestamp_fn(p_rec test_timestamp_tbl%ROWTYPE)
RETURN NUMBER
IS
BEGIN
RETURN p_rec.id;
END;
SQL
end

after(:all) do
plsql.execute "DROP FUNCTION test_timestamp_fn" rescue nil
plsql.execute "DROP TABLE test_timestamp_tbl" rescue nil
plsql.logoff
end

it "should strip precision from TIMESTAMP data types in %ROWTYPE fields" do
procedure = PLSQL::Procedure.find(plsql, :test_timestamp_fn)
fields = procedure.arguments[0][:p_rec][:fields]
expect(fields[:ts][:data_type]).to eq("TIMESTAMP")
expect(fields[:ts_tz][:data_type]).to eq("TIMESTAMP WITH TIME ZONE")
expect(fields[:ts_ltz][:data_type]).to eq("TIMESTAMP WITH LOCAL TIME ZONE")
end
end

describe "Function with TABLE OF %ROWTYPE parameter defined in package" do
before(:all) do
plsql.connect! CONNECTION_PARAMS
Expand Down