From 1a850087363ee5a30d9c98007e1f253c4b134f13 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 11 Jul 2008 14:26:32 +0000 Subject: [PATCH] new showWarnings attribute that makes display SQLWarnings - if any. PR 41836 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@675962 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 ++ docs/manual/CoreTasks/sql.html | 10 +++++ .../apache/tools/ant/taskdefs/SQLExec.java | 40 +++++++++++++++++-- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 9f8962d10..499da96be 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -143,6 +143,9 @@ Other changes: and "go" as delimiters. Bugzilla Report 26459. + * A new showWarnings attribute of allows warnings to be logged. + Bugzilla Report 41836. + Changes from Ant 1.7.0 TO Ant 1.7.1 ============================================= diff --git a/docs/manual/CoreTasks/sql.html b/docs/manual/CoreTasks/sql.html index 6a78de5e4..7ca2e79e4 100644 --- a/docs/manual/CoreTasks/sql.html +++ b/docs/manual/CoreTasks/sql.html @@ -212,6 +212,16 @@ and abort execution and transaction and fail task.

"GO "). Since Ant 1.8.0. No, default true + + + showWarnings + If true, SQLWarnings will be logged at + the WARN level. Since Ant 1.8.0.
+ Note: even if the attribute is set to false, warnings that + apply to the connection will be logged at the verbose level. + No, default false + +

Parameters specified as nested elements

diff --git a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java index 2b71e116e..5f943a9e3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java +++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java @@ -205,6 +205,12 @@ public class SQLExec extends JDBCTask { */ private boolean strictDelimiterMatching = true; + /** + * whether to show SQLWarnings as WARN messages. + * @since Ant 1.8.0 + */ + private boolean showWarnings = false; + /** * Set the name of the SQL file to be run. * Required unless statements are enclosed in the build file @@ -413,6 +419,14 @@ public class SQLExec extends JDBCTask { strictDelimiterMatching = b; } + /** + * whether to show SQLWarnings as WARN messages. + * @since Ant 1.8.0 + */ + public void setShowWarnings(boolean b) { + showWarnings = b; + } + /** * Load the sql file and then execute it * @throws BuildException on error. @@ -599,6 +613,11 @@ public class SQLExec extends JDBCTask { } if (ret) { resultSet = getStatement().getResultSet(); + if (showWarnings) { + printWarnings(resultSet.getWarnings(), + Project.MSG_WARN); + } + resultSet.clearWarnings(); if (print) { printResults(resultSet, out); } @@ -607,16 +626,19 @@ public class SQLExec extends JDBCTask { updateCount = getStatement().getUpdateCount(); } while (ret || updateCount != -1); + if (showWarnings) { + printWarnings(getStatement().getWarnings(), Project.MSG_WARN); + } + getStatement().clearWarnings(); + log(updateCountTotal + " rows affected", Project.MSG_VERBOSE); if (print && showtrailers) { out.println(updateCountTotal + " rows affected"); } SQLWarning warning = getConnection().getWarnings(); - while (warning != null) { - log(warning + " sql warning", Project.MSG_VERBOSE); - warning = warning.getNextWarning(); - } + printWarnings(warning, showWarnings + ? Project.MSG_WARN : Project.MSG_VERBOSE); getConnection().clearWarnings(); goodSql++; } catch (SQLException e) { @@ -685,6 +707,9 @@ public class SQLExec extends JDBCTask { printValue(rs, col, out); } out.println(); + if (showWarnings) { + printWarnings(rs.getWarnings(), Project.MSG_WARN); + } } } } @@ -891,4 +916,11 @@ public class SQLExec extends JDBCTask { } } } + + private void printWarnings(SQLWarning warning, int level) { + while (warning != null) { + log(warning + " sql warning", level); + warning = warning.getNextWarning(); + } + } }