Skip to content
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

Use of DatabaseMetadata#getProcedures (and functions) should take search string escape into account #22725

Closed
bashtanov opened this issue Apr 2, 2019 · 4 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug
Milestone

Comments

@bashtanov
Copy link

bashtanov commented Apr 2, 2019

All versions including master.
As far as I could see, SimpleJdbcCall calls java.sql.databaseMetaData.getProcedures with just procedure and schema names, not with patterns for them to match. This results in problems with procedures having underscores in their names:

            // create some functions
            JdbcTemplate jt = new JdbcTemplate(dataSource);
            for (String procName: ImmutableList.of("just_a_procedure_name_with_underscores", "just_a_procedure_name_with2underscores")){
                jt.execute("create or replace function " + procName + "() returns int as $$ select 1; $$ language sql");
            }

            // call one of them
            jt.execute("");
            SimpleJdbcCall sjc = new SimpleJdbcCall(jt);
            sjc.withProcedureName("just_a_procedure_name_with_underscores").execute();
org.springframework.dao.InvalidDataAccessApiUsageException: Unable to determine the correct call signature - multiple procedures/functions/signatures for just_a_procedure_name_with_underscores found [null.public.just_a_procedure_name_with2underscores, null.public.just_a_procedure_name_with_underscores]

Passing underscores backslash-escaped to withProcedure doesn't help either: the correct function gets found but not called as its name is different from the pattern to find it.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 2, 2019
@bashtanov
Copy link
Author

I should have said I used it with pgjdbc

@rstoyanchev rstoyanchev added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Nov 10, 2021
@snicoll
Copy link
Member

snicoll commented Nov 23, 2023

with just procedure and schema names, not with patterns for them to match

@bashtanov I can reproduce but I don't think there's anything we can do about this. We call java.sql.DatabaseMetaData#getFunctions with the function you gave us, i.e. just_a_procedure_name_with_underscores and Postgres decides to return two hits for that name.

What do you mean by "not with patterns for them to match"?

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Nov 23, 2023
@bashtanov
Copy link
Author

bashtanov commented Nov 23, 2023

@snicoll

We call java.sql.DatabaseMetaData#getFunctions with the function you gave us

And this is wrong, because, according to its documentation, java.sql.DatabaseMetaData#getFunctions accepts not the function name, but a pattern to look for functions. If you want to use this API to get info on a function with name just_a_procedure_name_with_underscores you should pass just@_a@_procedure@_name@_with@_underscores, where @ is what is returned by java.sql.DatabaseMetaData#getSearchStringEscape (in reality I would imagine it to be \, not @). Does it sound reasonable?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 23, 2023
@snicoll snicoll changed the title SimpleJdbcCall calls databaseMetaData.getProcedures with procedure name, not with pattern Use of DatabaseMetadata#getProcedures (and functions) should take search string escape into account Nov 24, 2023
@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Nov 24, 2023
@snicoll snicoll added this to the 6.1.x milestone Nov 24, 2023
@snicoll
Copy link
Member

snicoll commented Nov 24, 2023

@bashtanov well, this is embarrassing. I did notice the pattern but missed what that actually means and the use of the escape character. Thanks for getting back to us, we'll get this fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants