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

JdbcTestUtils readScript fails to see commented lines with tabs [SPR-10330] #14964

Closed
spring-projects-issues opened this issue Feb 25, 2013 · 1 comment
Assignees

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Feb 25, 2013

Laurent S. opened SPR-10330 and commented

Spring failed to parse SQL script when some lines are comments with tabs before comments markers.

For example for the file :

	-- My comment
My SQL INSERT STATEMENT;

This will generate the following statement

-- My comment My SQL INSERT STATEMENT;

And throw the following exception on execution :

org.hibernate.exception.GenericJDBCException: Type SQL non valide: sqlKind = UNINITIALIZED
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
	at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
	at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
	at $Proxy53.executeUpdate(Unknown Source)
	at org.springframework.jdbc.core.JdbcTemplate$1UpdateStatementCallback.doInStatement(JdbcTemplate.java:509)
	at org.springframework.jdbc.core.JdbcTemplate$1UpdateStatementCallback.doInStatement(JdbcTemplate.java:1)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:396)
	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:519)
	at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.update(SimpleJdbcTemplate.java:252)
	at org.springframework.test.jdbc.SimpleJdbcTestUtils.executeSqlScript(SimpleJdbcTestUtils.java:150)
	at org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests.executeSqlScript(AbstractTransactionalJUnit4SpringContextTests.java:141)
[...]

My guess for the fix would be to add trim on the following statement :
JdbcTestUtils.java, readScript(LineNumberReader lineNumberReader, String commentPrefix), Line 257:

if (StringUtils.hasText(currentStatement) && (commentPrefix != null && !currentStatement.trim().startsWith(commentPrefix))) {

Affects: 3.1.4

Issue Links:

  • #14616 Support comments within SQL statements in JdbcTestUtils
  • #13899 Improve comment handling in ResourceDatabasePopulator ("supersedes")

Referenced from: commits b3a693e

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 8, 2013

Sam Brannen commented

This issue appears to have already been addressed in #14616 which was included in the Spring Framework 3.2 release.

Furthermore, the claim raised in this issue has been disputed as described in GitHub commit b3a693e356:

*Add test to assess claim in SPR-10330*

This commit verifies that JdbcTestUtils.readScript() properly handles
SQL comments prefixed by tab characters.

I am therefore resolving this issue as Cannot Reproduce; however, if you find that you still face this issue with Spring 3.2.x and 4.0, please reopen this issue.

Thanks,

Sam

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants