Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9593

JdbcTestUtils should not interpret comments as a separate statement

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1.2
    • Fix Version/s: 3.1.3, 3.2 RC1
    • Component/s: Test
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      Overview

      The splitSqlScripts() method in JdbcTestUtils splits scripts at a given delimiter, often ';'. If the script has a trailing comment this will be returned as a separate statement. When executing the statements an exception will be thrown.

      Steps to Reproduce

      If you call SimpleJdbcTestUtils.executeSqlScript() on the following script, the trailing comment will be detected as a separate statement and executed, resulting in a BadSqlGrammarException.

      CREATE SQEUENCE HIBERNATE_SEQUENCE;
      -- End of script

        Issue Links

          Activity

          Hide
          sbrannen Sam Brannen added a comment -

          Fixed as described in the comments for GitHub commit 4aaf014cc6:

          Support comments in SQL scripts in JdbcTestUtils

          Prior to this commit, utility methods in JdbcTestUtils interpreted SQL comments as separate statements, resulting in an exception when such a script is executed.

          This commit addresses this issue by introducing a readScript(lineNumberReader, String) method that accepts a comment prefix. Comment lines are therefore no longer returned in the parsed script. Furthermore, the existing readScript(lineNumberReader) method now delegates to this new readScript() method, supplying "--" as the default comment prefix.

          Show
          sbrannen Sam Brannen added a comment - Fixed as described in the comments for GitHub commit 4aaf014cc6 : Support comments in SQL scripts in JdbcTestUtils Prior to this commit, utility methods in JdbcTestUtils interpreted SQL comments as separate statements, resulting in an exception when such a script is executed. This commit addresses this issue by introducing a readScript(lineNumberReader, String) method that accepts a comment prefix. Comment lines are therefore no longer returned in the parsed script. Furthermore, the existing readScript(lineNumberReader) method now delegates to this new readScript() method, supplying "--" as the default comment prefix.
          Hide
          cbeams Chris Beams added a comment - - edited

          Now backported to 3.1.x:

          commit d8dc4a257afa2aad9575e4d17a283935735f949e
          Author: Sam Brannen <[email protected]>
          Commit: Chris Beams <[email protected]>
           
              Support comments in SQL scripts in JdbcTestUtils
              
              Prior to this commit, utility methods in JdbcTestUtils interpreted SQL
              comments as separate statements, resulting in an exception when such a
              script is executed.
              
              This commit addresses this issue by introducing a
              readScript(lineNumberReader, String) method that accepts a comment
              prefix. Comment lines are therefore no longer returned in the parsed
              script. Furthermore, the existing readScript(lineNumberReader) method
              now delegates to this new readScript() method, supplying "--" as the
              default comment prefix.
              
              Issue: SPR-9593
              Backport-Commit: 4aaf014cc6bed8bdeea375556b1022066359e79d

          Show
          cbeams Chris Beams added a comment - - edited Now backported to 3.1.x: commit d8dc4a257afa2aad9575e4d17a283935735f949e Author: Sam Brannen <[email protected]> Commit: Chris Beams <[email protected]>   Support comments in SQL scripts in JdbcTestUtils Prior to this commit, utility methods in JdbcTestUtils interpreted SQL comments as separate statements, resulting in an exception when such a script is executed. This commit addresses this issue by introducing a readScript(lineNumberReader, String) method that accepts a comment prefix. Comment lines are therefore no longer returned in the parsed script. Furthermore, the existing readScript(lineNumberReader) method now delegates to this new readScript() method, supplying "--" as the default comment prefix. Issue: SPR-9593 Backport-Commit: 4aaf014cc6bed8bdeea375556b1022066359e79d

            People

            • Assignee:
              sbrannen Sam Brannen
              Reporter:
              mrodland Johannes Odland
              Last updater:
              Sam Brannen
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 5 weeks, 1 day ago