Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.7-beta-1
-
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