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

Sql rows() methods access ResultSet after Connection closed

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7-beta-1
    • 1.6.5, 1.7-beta-2
    • SQL processing
    • None
    • Patch

    Description

      Change 17279 introduced a Command Pattern (PreparedQueryCommand, QueryCommand) for executing the rows() methods.

      I don't think this works in general, because the methods now attempt to access the ResultSet after containing resources have been closed. E.g. in rows(String, Closure):

      ResultSet rs = executeQuery(sql);
      if (metaClosure != null) metaClosure.call(rs.getMetaData());
      return asList(sql, rs);

      The executeQuery() method:

      return new QueryCommand(sql).execute();

      And AbstractQueryCommand.execute() calls:

      closeResources(connection, statement, null);

      Unfortunately the standard test suite does not expose the problem – I think because HSQLDB is over-tolerant. I changed the test suite to use MySQL and it fails.

      I must admit I don't completely understand all of the resource handling paths in the Sql class, with regard to cached connections and what-not. My standard usage pattern in scripts is:

      Sql db = new Sql(dataSource)
      // do stuff.

      With this pattern, and databases other than HSQLDB, I find the rows() and firstRow() methods fail with trunk.

      I attach a patch that restores some of the earlier code. I don't like my patch though, because the new code is nicer, but we better figure out something that works I guess!

      John Hurst

      Attachments

        1. sql_17615.patch
          8 kB
          jwb
        2. rows_broken_with_command_pattern.patch
          2 kB
          John Hurst

        Activity

          People

            paulk Paul King
            john.b.hurst John Hurst
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: