antoine 2003/07/16 10:29:36
Modified: . WHATSNEW
src/main/org/apache/tools/ant/taskdefs SQLExec.java
Log:
Allow Result Sets and Errors to be processed properly in SQL task with
multiple statements
PR: 21594
Submitted by: Jeff Bohanek (jeff dot bohanek at msi dot com)
Revision Changes Path
1.459 +3 -0 ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/ant/WHATSNEW,v
retrieving revision 1.458
retrieving revision 1.459
diff -u -r1.458 -r1.459
--- WHATSNEW 16 Jul 2003 14:17:25 -0000 1.458
+++ WHATSNEW 16 Jul 2003 17:29:35 -0000 1.459
@@ -356,6 +356,9 @@
* <sql> has a new attribute to control escape processing.
+* <sql> is able to display properly several resultsets if you are
+ running a compound sql statement. Bugzilla Report 21594.
+
* <javah> will invoke oldjavah on JDK 1.4.2. Bugzilla Report 18667.
* A new <containsregexp> selector has been added, that selects files
1.57 +65 -38 ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
Index: SQLExec.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- SQLExec.java 6 Jul 2003 09:57:36 -0000 1.56
+++ SQLExec.java 16 Jul 2003 17:29:36 -0000 1.57
@@ -527,13 +527,43 @@
try {
totalSql++;
log("SQL: " + sql, Project.MSG_VERBOSE);
- if (!statement.execute(sql)) {
- log(statement.getUpdateCount() + " rows affected",
- Project.MSG_VERBOSE);
- } else {
- if (print) {
- printResults(out);
+
+ boolean ret;
+ int updateCount = 0, updateCountTotal = 0;
+ ResultSet resultSet = null;
+
+ ret = statement.execute(sql);
+ updateCount = statement.getUpdateCount();
+ resultSet = statement.getResultSet();
+ do
+ {
+ if (!ret)
+ {
+ if (updateCount != -1)
+ {
+ updateCountTotal += updateCount;
+ }
}
+ else
+ {
+ if (print)
+ {
+ printResults(out);
+ }
+ }
+ ret = statement.getMoreResults();
+ updateCount = statement.getUpdateCount();
+ resultSet = statement.getResultSet();
+ } while ((resultSet != null) || (updateCount != -1));
+
+ log(updateCountTotal + " rows affected",
+ Project.MSG_VERBOSE);
+
+ if (print)
+ {
+ StringBuffer line = new StringBuffer();
+ line.append(updateCountTotal + " rows affected");
+ out.println(line);
}
SQLWarning warning = conn.getWarnings();
@@ -557,43 +587,40 @@
*/
protected void printResults(PrintStream out) throws
java.sql.SQLException {
ResultSet rs = null;
- 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 = new StringBuffer();
+ 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(",");
}
- 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);
+ line.append(md.getColumnName(columnCount));
+ out.println(line);
+ line = new StringBuffer();
+ }
+ 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(",");
}
- out.println(line);
- line = new StringBuffer();
+ line.append(columnValue);
}
+ out.println(line);
+ line = new StringBuffer();
}
}
- while (statement.getMoreResults());
out.println();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]