groovy
  1. groovy
  2. GROOVY-3137

Groovy SQL call, eachRow and Resultset in parameters

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.7
    • Fix Version/s: 1.6.5
    • Component/s: SQL processing
    • Labels:
      None
    • Environment:
      Windows XP SP3
    • Number of attachments :
      0

      Description

      Sql.call method should clean up passed ResultSets...consider calling this method from "eachRow" as well if OutParameters are used (see Bug report GROOVY-3136)

      public void call(String sql, List params, Closure closure) throws Exception {
          Connection connection = createConnection();
          CallableStatement statement = connection.prepareCall(sql);
          List results = new ArrayList(); // <<< put result list here...
          try {
              log.fine(sql);
              setParameters(params, statement);
              statement.execute();
              List results = new ArrayList();
              int indx = 0;
              int inouts = 0;
              for (Iterator iter = params.iterator(); iter.hasNext();) {
                  Object value = iter.next();
                  if (value instanceof OutParameter) {
                      if (value instanceof ResultSetOutParameter) {
                          results.add(CallResultSet.getImpl(statement, indx));
                      } else {
                          Object o = statement.getObject(indx + 1);
                          if (o instanceof ResultSet) {
                              results.add(new GroovyResultSetProxy((ResultSet) o).getImpl());
                          } else {
                              results.add(o);
                          }
                      }
                      inouts++;
                  }
                  indx++;
              }
              closure.call(results.toArray(new Object[inouts]));
          } catch (SQLException e) {
              log.log(Level.WARNING, "Failed to execute: " + sql, e);
              throw e;
          } finally {		
              // TODO: cleanup ResultSets in "results" -> closeResources(connection, statement);
          }
      }
      

        Issue Links

          Activity

          Hide
          Paul King added a comment -

          add code tags

          Show
          Paul King added a comment - add code tags
          Hide
          Paul King added a comment -

          There is a partial fix to this in trunk but I only have limited ability to test it. Can someone try testing for me please?

          The patch collects ResultSetOutParameter params or other found ResultSet params and closes them in the finally block.

          Currently just for the call method above with the closure, not eachRow or anything else.

          Show
          Paul King added a comment - There is a partial fix to this in trunk but I only have limited ability to test it. Can someone try testing for me please? The patch collects ResultSetOutParameter params or other found ResultSet params and closes them in the finally block. Currently just for the call method above with the closure, not eachRow or anything else.
          Hide
          Paul King added a comment -

          The "partial fix" is now merged onto the 1.6 branch too.

          Show
          Paul King added a comment - The "partial fix" is now merged onto the 1.6 branch too.
          Hide
          Paul King added a comment -

          No further feedback, assuming partial fix is sufficient

          Show
          Paul King added a comment - No further feedback, assuming partial fix is sufficient

            People

            • Assignee:
              Paul King
              Reporter:
              Ueli Kistler
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: