You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by co...@locus.apache.org on 2000/11/01 06:59:17 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs SQLExec.java

conor       00/10/31 21:59:17

  Modified:    src/main/org/apache/tools/ant/taskdefs SQLExec.java
  Log:
  Fix SQLExec printing of results. It was using the return from getResultSet to
  indicate that there are no more result sets but I think it should have been using
  the result of getMoreResults(). I have made the appropriate change. I have also
  made changes to handle NULL results
  Reported by:	Johan Adel�w <jo...@corustechnologies.com>
  
  Revision  Changes    Path
  1.11      +34 -21    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
  
  Index: SQLExec.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SQLExec.java	2000/10/10 14:56:35	1.10
  +++ SQLExec.java	2000/11/01 05:59:16	1.11
  @@ -522,31 +522,44 @@
   		log("Opening PrintStream to output file " + output, Project.MSG_VERBOSE);
                   out = new PrintStream(new BufferedOutputStream(new FileOutputStream(output)));
               }
  -            while ((rs = statement.getResultSet()) != null) {
  -		log("Processing new result set.", Project.MSG_VERBOSE);
  -                ResultSetMetaData md = rs.getMetaData();
  -                int columnCount = md.getColumnCount();
  -                StringBuffer line = new StringBuffer();
  -                if (showheaders) {
  -                    for (int col = 1; col < columnCount; col++) {
  -                        line.append(md.getColumnName(col));
  -                        line.append(",");
  +            do {
  +                rs = statement.getResultSet();
  +                if (rs != null) {
  +        	    log("Processing new result set.", Project.MSG_VERBOSE);
  +                    ResultSetMetaData md = rs.getMetaData();
  +                    int columnCount = md.getColumnCount();
  +                    StringBuffer line = new StringBuffer();
  +                    if (showheaders) {
  +                        for (int col = 1; col < columnCount; col++) {
  +                            line.append(md.getColumnName(col));
  +                            line.append(",");
  +                        }
  +                        line.append(md.getColumnName(columnCount));
  +                        out.println(line);
  +                        line.setLength(0);
                       }
  -                    line.append(md.getColumnName(columnCount));
  -                    out.println(line);
  -                    line.setLength(0);
  -                }
  -                while (rs.next()) {
  -                    for (int col = 1; col < columnCount; col++) {
  -                        line.append(rs.getString(col).trim());
  -                        line.append(",");
  +                    while (rs.next()) {
  +                        boolean first = true;
  +                        for (int col = 1; col <= columnCount; col++) {
  +                            String columnValue = rs.getString(col);
  +                            if (columnValue != null) {
  +                                columnValue = columnValue.trim();
  +                            }
  +                             
  +                            if (first) {
  +                                first = false;
  +                            }
  +                            else {
  +                                line.append(",");
  +                            }
  +                            line.append(columnValue);
  +                        }
  +                        out.println(line);
  +                        line.setLength(0);
                       }
  -                    line.append(rs.getString(columnCount).trim());
  -                    out.println(line);
  -                    line.setLength(0);
                   }
  -                statement.getMoreResults();
               }
  +            while (statement.getMoreResults());
           }
           catch (IOException ioe) {
               throw new BuildException("Error writing " + output.getAbsolutePath(), ioe, location);