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

Incorrect named parameter parsing results in InvalidDataAccessApiUsageException: No value supplied for the SQL parameter [SPR-13181] #17773

Closed
spring-projects-issues opened this issue Jul 1, 2015 · 5 comments
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: superseded An issue that has been superseded by another

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 1, 2015

Hendy Irawan opened SPR-13181 and commented

For the following SQL:

UPDATE ppdbbandung2015.school
  SET
    name=:name,
    code=:code,
    level=:level,
    address=:address,
    address_district=:address_district,
    address_subdistrict=:address_subdistrict,
    address_rw=:address_rw,
    address_rt=:address_rt,
    is_border=:is_border,
    foreigner_percentage=:foreigner_percentage,
    option_i=:option_i,
    option=ARRAY[:option]::json[]
  WHERE id=:id;

Notice that we have ARRAY[:option] which should be proper when executed in PostgreSQL, however Spring parses the ] after :option as part of the parameter name, resulting in:

org.springframework.dao.InvalidDataAccessApiUsageException: No value supplied for the SQL parameter 'option]': No value registered for key 'option]'
	at org.springframework.jdbc.core.namedparam.NamedParameterUtils.buildValueArray(NamedParameterUtils.java:336)
	at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.getPreparedStatementCreator(NamedParameterJdbcTemplate.java:374)
	at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:313)
	at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:318)
	at org.soluvas.scrape.core.sql.TableDmlGenerator.lambda$upsert$6(TableDmlGenerator.java:128)
	at org.soluvas.scrape.core.sql.TableDmlGenerator$$Lambda$3/1563634025.doInTransaction(Unknown Source)
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
	at org.soluvas.scrape.core.sql.TableDmlGenerator.upsert(TableDmlGenerator.java:108)
	at org.soluvas.scrape.core.UpsertTest.upsert(UpsertTest.java:76)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

Workaround: just add a space after the parameter name, however such special characters (e.g. "]", "{" ) should never form part of a named parameter.

Related to #17770, #17771.


Affects: 4.1.7

@spring-projects-issues spring-projects-issues added type: bug A general bug status: waiting-for-triage An issue we've not yet triaged or decided on in: data Issues in data modules (jdbc, orm, oxm, tx) and removed type: bug A general bug labels Jan 11, 2019
@rstoyanchev rstoyanchev added status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 11, 2019
@spring-projects-issues
Copy link
Collaborator Author

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

@foal
Copy link

foal commented Jan 17, 2019

Still relevant

@rstoyanchev rstoyanchev reopened this Jan 17, 2019
@rstoyanchev rstoyanchev added status: waiting-for-triage An issue we've not yet triaged or decided on for: team-attention and removed status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process labels Jan 17, 2019
@rstoyanchev rstoyanchev added status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process and removed for: team-attention labels Jun 28, 2019
@Chen-Clark
Copy link

?

@snicoll
Copy link
Member

snicoll commented Nov 2, 2023

I did a quick test and didn't manage to reproduce this issue. Given that several people here claim it is relevant, please share a small test that reproduces the problem. Tests of NamedParameterUtils are quite easy to build.

This is the test that I used:

@Test // gh-17773
public void parseSqlStatementWithPostgresArray() {
	String sql = """
		UPDATE ppdbbandung2015.school
		SET
			name=:name,
			code=:code,
			level=:level,
			address=:address,
			address_district=:address_district
			address_subdistrict=:address_subdistrict
			address_rw=:address_rw
			address_rt=:address_rt
			is_border=:is_border,
			foreigner_percentage=:foreigner_percentage,
			option_i=:option_i,
			option=ARRAY[:option]::json[]
		WHERE id=:id;""";

	ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
	assertThat(parsedSql.getParameterNames()).containsOnly(
			"name", "code", "level", "address", "address_district",
			"address_subdistrict", "address_rw", "address_rt",
			"is_border", "foreigner_percentage", "option_i",
			"option", "id");
}

@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process labels Nov 2, 2023
@sbrannen
Copy link
Member

sbrannen commented Nov 2, 2023

This appears to have been fixed in #27716 and #27925.

If you still encounter this issue with Spring Framework 6.0.13 (or a later version), please create a new issue.

Thanks

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale Nov 2, 2023
@sbrannen sbrannen added status: superseded An issue that has been superseded by another and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 2, 2023
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) status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

6 participants