ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r675968 - in /ant/core/trunk: WHATSNEW docs/manual/CoreTasks/sql.html src/main/org/apache/tools/ant/taskdefs/SQLExec.java
Date Fri, 11 Jul 2008 14:41:33 GMT
Author: bodewig
Date: Fri Jul 11 07:41:33 2008
New Revision: 675968

URL: http://svn.apache.org/viewvc?rev=675968&view=rev
Log:
allow SQLWarnings to stop <sql>.  PR 41836.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/sql.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=675968&r1=675967&r2=675968&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Jul 11 07:41:33 2008
@@ -146,6 +146,10 @@
  * A new showWarnings attribute of <sql> allows warnings to be logged.
    Bugzilla Report 41836.
 
+ * A new treatWarningsAsErrors attribute of <sql> can be used to fail
+   a build if a warning occurs.
+   Bugzilla Report 41836.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/docs/manual/CoreTasks/sql.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/sql.html?rev=675968&r1=675967&r2=675968&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/sql.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/sql.html Fri Jul 11 07:41:33 2008
@@ -222,6 +222,15 @@
   <td width="10%" valign="top">No, default <em>false</em></td>
 </tr>
 
+<tr>
+  <td width="12%" valign="top">treatWarningsAsErrors</td>
+  <td width="78%" valign="top">If true, SQLWarnings will be treated
+    like errors - and the logic selected via the onError attribute
+    applies.
+    <em>Since Ant 1.8.0</em>.<br/>
+  <td width="10%" valign="top">No, default <em>false</em></td>
+</tr>
+
 </table>
 
 <h3>Parameters specified as nested elements</h3>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java?rev=675968&r1=675967&r2=675968&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java Fri Jul 11 07:41:33
2008
@@ -212,6 +212,12 @@
     private boolean showWarnings = false;
 
     /**
+     * Whether a warning is an error - in which case onError aplies.
+     * @since Ant 1.8.0
+     */
+    private boolean treatWarningsAsErrors = false;
+
+    /**
      * Set the name of the SQL file to be run.
      * Required unless statements are enclosed in the build file
      * @param srcFile the file containing the SQL command.
@@ -428,6 +434,14 @@
     }
 
     /**
+     * Whether a warning is an error - in which case onError aplies.
+     * @since Ant 1.8.0
+     */
+    public void setTreatWarningsAsErrors(boolean b) {
+        treatWarningsAsErrors =  b;
+    }
+
+    /**
      * Load the sql file and then execute it
      * @throws BuildException on error.
      */
@@ -613,10 +627,7 @@
                 }
                 if (ret) {
                     resultSet = getStatement().getResultSet();
-                    if (showWarnings) {
-                        printWarnings(resultSet.getWarnings(),
-                                      Project.MSG_WARN);
-                    }
+                    printWarnings(resultSet.getWarnings(), false);
                     resultSet.clearWarnings();
                     if (print) {
                         printResults(resultSet, out);
@@ -626,9 +637,7 @@
                 updateCount = getStatement().getUpdateCount();
             } while (ret || updateCount != -1);
 
-            if (showWarnings) {
-                printWarnings(getStatement().getWarnings(), Project.MSG_WARN);
-            }
+            printWarnings(getStatement().getWarnings(), false);
             getStatement().clearWarnings();
 
             log(updateCountTotal + " rows affected", Project.MSG_VERBOSE);
@@ -637,8 +646,7 @@
                 out.println(updateCountTotal + " rows affected");
             }
             SQLWarning warning = getConnection().getWarnings();
-            printWarnings(warning, showWarnings
-                          ? Project.MSG_WARN : Project.MSG_VERBOSE);
+            printWarnings(warning, true);
             getConnection().clearWarnings();
             goodSql++;
         } catch (SQLException e) {
@@ -707,9 +715,7 @@
                         printValue(rs, col, out);
                     }
                     out.println();
-                    if (showWarnings) {
-                        printWarnings(rs.getWarnings(), Project.MSG_WARN);
-                    }
+                    printWarnings(rs.getWarnings(), false);
                 }
             }
         }
@@ -917,10 +923,18 @@
         }
     }
 
-    private void printWarnings(SQLWarning warning, int level) {
-        while (warning != null) {
-            log(warning + " sql warning", level);
-            warning = warning.getNextWarning();
+    private void printWarnings(SQLWarning warning, boolean force)
+        throws SQLException {
+        SQLWarning initialWarning = warning;
+        if (showWarnings || force) {
+            while (warning != null) {
+                log(warning + " sql warning",
+                    showWarnings ? Project.MSG_WARN : Project.MSG_VERBOSE);
+                warning = warning.getNextWarning();
+            }
+        }
+        if (treatWarningsAsErrors && initialWarning != null) {
+            throw initialWarning;
         }
     }
 }



Mime
View raw message