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

Support comments within SQL statements in JdbcTestUtils [SPR-9982] #14616

Closed
1 task done
spring-projects-issues opened this issue Nov 12, 2012 · 3 comments
Closed
1 task done
Assignees
Labels
in: data in: test type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Nov 12, 2012

Joram Agten opened SPR-9982 and commented

Status Quo

Executing an SQL script via JdbcTestUtils.executeSqlScript() with the following content fails.

INSERT INTO persons( person_id
                   , name)
VALUES( 1      -- person_id
      , 'Name' --name
);
org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [INSERT INTO persons( person_id                   , name)VALUES( 1      - person_id      , 'Name' --name)]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00917: missing comma

Proposed Solutions

  1. keep the carriage returns after each line when building statements (line 388 389)
  2. strip all characters (per line) after the DEFAULT_COMMENT_PREFIX (including the prefix)

I think solution 1 is preferred, since 2 might become db dependent.

Deliverables

  1. Ensure that multi-line statements which contain comments can be executed.

Affects: 3.1.3

Issue Links:

  • #14227 JdbcTestUtils should not interpret comments as a separate statement
  • #14964 JdbcTestUtils readScript fails to see commented lines with tabs
  • #14708 Support comments within SQL statements in ResourceDatabasePopulator
  • #14165 Support multi-line SQL comments in ResourceDatabasePopulator and JdbcTestUtils
  • #13899 Improve comment handling in ResourceDatabasePopulator ("supersedes")

Referenced from: commits 8a422f4, d0f687f

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 12, 2012

Chris Beams commented

Sam Brannen, this looks related to #14227. Can you take a look?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 5, 2012

Sam Brannen commented

Resolved as described in the comments for GitHub commit d0f687f028:

Support comments in statements in JdbcTestUtils

Prior to this commit, executing an SQL script with JdbcTestUtils would
fail if a statement in the script contained a line comment within the
statement.

This commit ensures that standard SQL comments (i.e., any text beginning
with two hyphens and extending to the end of the line) are properly
omitted from the statement before executing it.

In addition, multiple adjacent whitespace characters within a statement
but outside a literal are now collapsed into a single space.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 5, 2012

Sam Brannen commented

If you're watching or reading this issue, you may also be interested in #14708.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data in: test type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants