Skip to content

Commit 3759bfc

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 Oracle 11g and newer. 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 3759bfc

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,3 +2385,42 @@ def new_candidate(status)
23852385
expect { plsql.test_func(p_STRING: "xxx") }.not_to raise_error
23862386
end
23872387
end
2388+
2389+
describe "Procedure with %ROWTYPE parameter on table 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+
PROCEDURE test_proc(p_rec IN test_hidden_cols%ROWTYPE);
2398+
END;
2399+
SQL
2400+
plsql.execute <<-SQL
2401+
CREATE OR REPLACE PACKAGE BODY test_hidden_cols_pkg IS
2402+
PROCEDURE test_proc(p_rec IN test_hidden_cols%ROWTYPE) IS
2403+
BEGIN
2404+
NULL;
2405+
END;
2406+
END;
2407+
SQL
2408+
end
2409+
2410+
after(:all) do
2411+
plsql.execute "DROP PACKAGE test_hidden_cols_pkg" rescue nil
2412+
plsql.execute "DROP TABLE test_hidden_cols" rescue nil
2413+
plsql.logoff
2414+
end
2415+
2416+
it "should not include hidden columns in %ROWTYPE fields" do
2417+
proc = PLSQL::Procedure.find(plsql, :test_proc, "TEST_HIDDEN_COLS_PKG")
2418+
fields = proc.arguments[0][:p_rec][:fields]
2419+
field_names = fields.keys
2420+
expect(field_names).to include(:col1)
2421+
expect(field_names).to include(:col2)
2422+
# Use string comparison instead of symbol literal (e.g., :sys_nc00003$)
2423+
# because $ in symbol literals is a syntax error in the Ruby 2.4 parser
2424+
expect(field_names.none? { |name| name.to_s.start_with?("sys_nc") }).to be true
2425+
end
2426+
end

0 commit comments

Comments
 (0)