Browse Source

rowcountproperty for <sql>. PR 40923

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@807234 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
4e4a359351
3 changed files with 38 additions and 4 deletions
  1. +4
    -0
      WHATSNEW
  2. +7
    -0
      docs/manual/CoreTasks/sql.html
  3. +27
    -4
      src/main/org/apache/tools/ant/taskdefs/SQLExec.java

+ 4
- 0
WHATSNEW View File

@@ -901,6 +901,10 @@ Other changes:
can be set if an error/warning occurs.
Bugzilla Report 38807.

* <sql> 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
=============================================



+ 7
- 0
docs/manual/CoreTasks/sql.html View File

@@ -268,6 +268,13 @@ and <b>abort</b> execution and transaction and fail task.</p>
warning. <em>Since Ant 1.8.0</em></td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">rowcountproperty</td>
<td valign="top">The name of a property to set to the number of rows
updated by the first statement/transaction that actually returned
a row count. <em>Since Ant 1.8.0</em></td>
<td align="center" valign="top">No</td>
</tr>
</table>

<h3>Parameters specified as nested elements</h3>


+ 27
- 4
src/main/org/apache/tools/ant/taskdefs/SQLExec.java View File

@@ -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);
}
}
}

Loading…
Cancel
Save