Skip to content

case-insensitive table names and proc params #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 28, 2020
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
5 changes: 5 additions & 0 deletions lib/plsql/procedure_call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ def initialize(procedure, args = [], options = {})
@dbms_output_stream = @schema.dbms_output_stream
@skip_self = options[:skip_self]
@self = options[:self]

if args.size == 1 && args[0].is_a?(Hash) && args[0].keys.all? { |k| k.is_a?(Symbol) }
args[0] = args[0].map { |k, v| [k.downcase, v] }.to_h
end

@overload = get_overload_from_arguments_list(args)
@procedure.ensure_tmp_tables_created(@overload) if @procedure.respond_to?(:ensure_tmp_tables_created)
construct_sql(args)
Expand Down
1 change: 1 addition & 0 deletions lib/plsql/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def insert(record)
end

table_proc = TableProcedure.new(@schema, self, :insert)
record = record.map { |k, v| [k.downcase.to_sym, v] }.to_h
table_proc.add_insert_arguments(record)

call = ProcedureCall.new(table_proc, table_proc.argument_values)
Expand Down
24 changes: 24 additions & 0 deletions spec/plsql/procedure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2358,3 +2358,27 @@ def new_candidate(status)
end
end
end

describe "case-insensitive params" do
before(:all) do
plsql.connect! CONNECTION_PARAMS
plsql.execute <<-SQL
CREATE OR REPLACE FUNCTION test_func
( p_string VARCHAR2 )
RETURN VARCHAR2
IS
BEGIN
RETURN UPPER(p_string);
END test_func;
SQL
end

after(:all) do
plsql.execute "DROP FUNCTION test_func"
plsql.logoff
end

it "should call procedure/function with case-insensitive param names" do
expect { plsql.test_func(p_STRING: "xxx") }.not_to raise_error
end
end
5 changes: 5 additions & 0 deletions spec/plsql/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@
expect(plsql.test_employees2.all("ORDER BY employee_id")).to eq(@employees2)
end

it "should insert with case-insensetive table name" do
plsql.test_employees.insert @employees.first.map { |k, v| [k.upcase.to_sym, v] }.to_h
expect(plsql.test_employees.all).to eq([@employees.first])
end

end

describe "insert values" do
Expand Down