Skip to content

Commit 63039de

Browse files
yahondajoschugclaude
committed
Exclude hidden columns from table type field definitions
Use ALL_TAB_COLUMNS instead of ALL_TAB_COLS when querying column definitions for table/view type parameters. ALL_TAB_COLUMNS excludes hidden columns (e.g., those created by functional indexes) by default, and is available in all supported Oracle versions including 11g. Based on rsim#208 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 39cf870 commit 63039de

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/plsql/procedure.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def get_field_definitions(argument_metadata) # :nodoc:
391391
when "TABLE", "VIEW"
392392
@schema.select_all(
393393
"SELECT column_id, column_name, data_type, data_length, data_precision, data_scale, char_length, char_used
394-
FROM ALL_TAB_COLS WHERE OWNER = :owner AND TABLE_NAME = :type_name
394+
FROM ALL_TAB_COLUMNS WHERE OWNER = :owner AND TABLE_NAME = :type_name
395395
ORDER BY column_id",
396396
@schema_name, argument_metadata[:type_name]) do |r|
397397

spec/plsql/procedure_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,3 +2385,44 @@ def new_candidate(status)
23852385
expect { plsql.test_func(p_STRING: "xxx") }.not_to raise_error
23862386
end
23872387
end
2388+
2389+
describe "Function with table type parameter that has hidden columns" do
2390+
before(:all) do
2391+
plsql.connect! CONNECTION_PARAMS
2392+
plsql.execute "CREATE TABLE test_hidden_cols (col1 VARCHAR2(50), col2 VARCHAR2(50))"
2393+
# Functional index creates a hidden column in ALL_TAB_COLS
2394+
plsql.execute "CREATE INDEX test_hidden_cols_idx ON test_hidden_cols (UPPER(col1))"
2395+
plsql.execute <<-SQL
2396+
CREATE OR REPLACE PACKAGE test_hidden_cols_pkg IS
2397+
TYPE t_tab IS TABLE OF test_hidden_cols%ROWTYPE;
2398+
PROCEDURE test_proc(p_tab IN t_tab);
2399+
END;
2400+
SQL
2401+
plsql.execute <<-SQL
2402+
CREATE OR REPLACE PACKAGE BODY test_hidden_cols_pkg IS
2403+
PROCEDURE test_proc(p_tab IN t_tab) IS
2404+
BEGIN
2405+
NULL;
2406+
END;
2407+
END;
2408+
SQL
2409+
end
2410+
2411+
after(:all) do
2412+
plsql.execute "DROP PACKAGE test_hidden_cols_pkg" rescue nil
2413+
plsql.execute "DROP TABLE test_hidden_cols" rescue nil
2414+
plsql.logoff
2415+
end
2416+
2417+
it "should not include hidden columns in table type fields" do
2418+
fields = plsql.test_hidden_cols_pkg.test_proc.arguments[:p_tab]
2419+
# The hidden column from the functional index should not appear
2420+
# Only col1 and col2 should be present
2421+
field_names = fields[:fields] ? fields[:fields].keys : []
2422+
expect(field_names).to include(:col1)
2423+
expect(field_names).to include(:col2)
2424+
# Use string comparison instead of symbol literal (e.g., :sys_nc00003$)
2425+
# because $ in symbol literals is a syntax error in the Ruby 2.4 parser
2426+
expect(field_names.none? { |name| name.to_s.start_with?("sys_nc") }).to be true
2427+
end
2428+
end

0 commit comments

Comments
 (0)