Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-5898

Sql.java throws IllegalStateException("Failed to process query. Unterminated ' character?") when comments contain quotes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.8.8, 2.1.0-rc-1
    • 2.2.0-beta-1
    • SQL processing

    Description

      In versions of Groovy since 1.8, when Groovy SQL prepares to execute a parameterized query, it checks the query SQL for unterminated single quotes (lines 4168 - 4188 of groovy.sql.Sql.java in the current trunk source). However, the current code doesn't recognize that when the SQL contains comments, and the comments include apostrophes or single quote characters, that the SQL is valid.

      For example, this code will result in an exception:

      def myQuery = """
        select count(*), cast(? as varchar(10))
        -- An ' apostrophe
        from art.option 
      """
      
      sql.eachRow(myQuery.toString(), ['1.7.5']) 
      {row ->
        println row
      }
      

      Perhaps you could use a regex or string replace to remove or ignore everything found between "--" and "\n" or "/" and "/" before testing for unterminated quotes?

      Attachments

        Activity

          People

            paulk Paul King
            msinatl Marc Silverboard
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: