From 2e15020c1e0390dcba2144bf2a66e387edd9f2c8 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Wed, 1 Nov 2000 05:59:16 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20SQLExec=20printing=20of=20results.=20It?= =?UTF-8?q?=20was=20using=20the=20return=20from=20getResultSet=20to=20indi?= =?UTF-8?q?cate=20that=20there=20are=20no=20more=20result=20sets=20but=20I?= =?UTF-8?q?=20think=20it=20should=20have=20been=20using=20the=20result=20o?= =?UTF-8?q?f=20getMoreResults().=20I=20have=20made=20the=20appropriate=20c?= =?UTF-8?q?hange.=20I=20have=20also=20made=20changes=20to=20handle=20NULL?= =?UTF-8?q?=20results=20Reported=20by:=09Johan=20Adel=EF=BF=BDw=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268137 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/SQLExec.java | 55 ++++++++++++------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java index bb516ca6f..0478e1202 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java +++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java @@ -522,31 +522,44 @@ public class SQLExec extends Task { 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);