Return-Path: Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 66127 invoked by uid 500); 1 Nov 2000 05:59:17 -0000 Delivered-To: apmail-jakarta-ant-cvs@apache.org Received: (qmail 66124 invoked by uid 1142); 1 Nov 2000 05:59:17 -0000 Date: 1 Nov 2000 05:59:17 -0000 Message-ID: <20001101055917.66123.qmail@locus.apache.org> From: conor@locus.apache.org To: jakarta-ant-cvs@apache.org Subject: 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 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);