ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r675962 - 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:26:32 GMT
Author: bodewig
Date: Fri Jul 11 07:26:32 2008
New Revision: 675962

URL: http://svn.apache.org/viewvc?rev=675962&view=rev
Log:
new showWarnings attribute that makes <sql> display SQLWarnings - if any.  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=675962&r1=675961&r2=675962&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Jul 11 07:26:32 2008
@@ -143,6 +143,9 @@
    and "go" as delimiters.
    Bugzilla Report 26459.
 
+ * A new showWarnings attribute of <sql> allows warnings to be logged.
+   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=675962&r1=675961&r2=675962&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/sql.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/sql.html Fri Jul 11 07:26:32 2008
@@ -212,6 +212,16 @@
     "GO ").  <em>Since Ant 1.8.0</em>.</td>
   <td width="10%" valign="top">No, default <em>true</em></td>
 </tr>
+
+<tr>
+  <td width="12%" valign="top">showWarnings</td>
+  <td width="78%" valign="top">If true, SQLWarnings will be logged at
+    the WARN level.  <em>Since Ant 1.8.0</em>.<br/>
+    <b>Note:</b> even if the attribute is set to false, warnings that
+    apply to the connection will be logged at the verbose level.</td>
+  <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=675962&r1=675961&r2=675962&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:26:32
2008
@@ -206,6 +206,12 @@
     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
      * @param srcFile the file containing the SQL command.
@@ -414,6 +420,14 @@
     }
 
     /**
+     * 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 @@
                 }
                 if (ret) {
                     resultSet = getStatement().getResultSet();
+                    if (showWarnings) {
+                        printWarnings(resultSet.getWarnings(),
+                                      Project.MSG_WARN);
+                    }
+                    resultSet.clearWarnings();
                     if (print) {
                         printResults(resultSet, out);
                     }
@@ -607,16 +626,19 @@
                 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 @@
                         printValue(rs, col, out);
                     }
                     out.println();
+                    if (showWarnings) {
+                        printWarnings(rs.getWarnings(), Project.MSG_WARN);
+                    }
                 }
             }
         }
@@ -891,4 +916,11 @@
             }
         }
     }
+
+    private void printWarnings(SQLWarning warning, int level) {
+        while (warning != null) {
+            log(warning + " sql warning", level);
+            warning = warning.getNextWarning();
+        }
+    }
 }



Mime
View raw message