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

Regression in ResourceDatabasePopulator: no longer supports newlines within statement properly [SPR-7449] #12107

Closed
spring-projects-issues opened this issue Aug 10, 2010 · 5 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Sam Brannen opened SPR-7449 and commented

Status Quo

The following lines from an SQL script worked with the EmbeddedDatabaseBuilder until I updated to the latest nightly snapshot (org.springframework.jdbc-3.0.4.BUILD-20100810.004442-53).

INSERT INTO
users(email_address, password, first_name, last_name, roles)
values('sam.brannen@example.com', '$pr!ng', 'Sam', 'Brannen', 'ROLE_USER,ROLE_ADMIN');

Execution of this script results in the following stacktrace:

org.springframework.dao.DataAccessResourceFailureException: Failed to populate database; nested exception is java.sql.SQLException: Unexpected token INTOUSERS, requires INTO in statement [INSERT INTOusers]
	at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory.populateDatabase(EmbeddedDatabaseFactory.java:158)
	at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory.initDatabase(EmbeddedDatabaseFactory.java:138)
	at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory.getDatabase(EmbeddedDatabaseFactory.java:114)
	at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder.build(EmbeddedDatabaseBuilder.java:112)

Removing the newline between INTO and users (as in the following script) works. Thus, recent changes (from 3.0.3 - 3.0.4) now swallow \n in SQL scripts, effectively concatenating adjacent lines.

INSERT INTO users(email_address, password, first_name, last_name, roles)
values('sam.brannen@example.com', '$pr!ng', 'Sam', 'Brannen', 'ROLE_USER,ROLE_ADMIN');

Proposed Solution

ResourceDatabasePopulator should be modified to properly interpret empty lines in contrast to simply swallowing all \n characters.


Affects: 3.0.4

Referenced from: commits 1503a13, e3400f7

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Interesting, as you may have noticed, the last commit on that class is Aug 7th (your nightly is Aug 8th), and Jürgen's comment is that he was 'fixing an accidental regression with respect to newlines'.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Look like that's yet another regression - hopefully easy enough to fix.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Yeah, but wait a minute.... I'm about to check in a failing (@Ignore'd) test case for you. ;)

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

OK, have a look at DatabasePopulatorTests.scriptWithEolBetweenTokens() for an @Ignore'd failing test.

- Sam

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Fixed. We're converting newlines and tabs to spaces now, instead of just skipping them as we did before.

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.4 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants