From 4e4a3593518e23056df34ec915bda86ac510a0e1 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 24 Aug 2009 14:24:51 +0000 Subject: [PATCH] rowcountproperty for . PR 40923 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@807234 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 +++ docs/manual/CoreTasks/sql.html | 7 +++++ .../apache/tools/ant/taskdefs/SQLExec.java | 31 ++++++++++++++++--- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index c31886b8e..799a63721 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -901,6 +901,10 @@ Other changes: can be set if an error/warning occurs. Bugzilla Report 38807. + * has a new attribute rowcountproperty that can be used to set + a property to the number of rows affected by a task execution. + Bugzilla Report 40923. + 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 091c9f18e..d3e3c0ee0 100644 --- a/docs/manual/CoreTasks/sql.html +++ b/docs/manual/CoreTasks/sql.html @@ -268,6 +268,13 @@ and abort execution and transaction and fail task.

warning. Since Ant 1.8.0 No + + rowcountproperty + The name of a property to set to the number of rows + updated by the first statement/transaction that actually returned + a row count. Since Ant 1.8.0 + No +

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 707830a29..910325b59 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java +++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java @@ -262,6 +262,13 @@ public class SQLExec extends JDBCTask { */ private String warningProperty = null; + /** + * The name of the property that receives the number of rows + * returned + * @since Ant 1.8.0 + */ + private String rowCountProperty = null; + /** * Set the name of the SQL file to be run. * Required unless statements are enclosed in the build file @@ -555,6 +562,15 @@ public class SQLExec extends JDBCTask { this.warningProperty = warningProperty; } + /** + * Sets a given property to the number of rows in the first + * statement that returned a row count. + * @since Ant 1.8.0 + */ + public void setRowCountProperty(String rowCountProperty) { + this.rowCountProperty = rowCountProperty; + } + /** * Load the sql file and then execute it * @throws BuildException on error. @@ -778,6 +794,9 @@ public class SQLExec extends JDBCTask { getStatement().clearWarnings(); log(updateCountTotal + " rows affected", Project.MSG_VERBOSE); + if (updateCountTotal != -1) { + setRowCountProperty(updateCountTotal); + } if (print && showtrailers) { out.println(updateCountTotal + " rows affected"); @@ -1102,16 +1121,20 @@ public class SQLExec extends JDBCTask { } protected final void setErrorProperty() { - setProperty(errorProperty); + setProperty(errorProperty, "true"); } protected final void setWarningProperty() { - setProperty(warningProperty); + setProperty(warningProperty, "true"); + } + + protected final void setRowCountProperty(int rowCount) { + setProperty(rowCountProperty, Integer.toString(rowCount)); } - private void setProperty(String name) { + private void setProperty(String name, String value) { if (name != null) { - getProject().setNewProperty(name, "true"); + getProject().setNewProperty(name, value); } } }