Browse Source

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 <johan.adelow@corustechnologies.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268137 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 24 years ago
parent
commit
2e15020c1e
1 changed files with 34 additions and 21 deletions
  1. +34
    -21
      src/main/org/apache/tools/ant/taskdefs/SQLExec.java

+ 34
- 21
src/main/org/apache/tools/ant/taskdefs/SQLExec.java View File

@@ -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);


Loading…
Cancel
Save