Browse Source

errorproperty and warningproperty for <sql>. Submitted by Andrew Stevens. PR 38807

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@807228 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
cfb2e01084
5 changed files with 75 additions and 0 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +4
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +12
    -0
      docs/manual/CoreTasks/sql.html
  5. +54
    -0
      src/main/org/apache/tools/ant/taskdefs/SQLExec.java

+ 1
- 0
CONTRIBUTORS View File

@@ -10,6 +10,7 @@ Alison Winters
Andreas Ames Andreas Ames
Andreas Mross Andreas Mross
Andrew Everitt Andrew Everitt
Andrew Stevens
Andrey Urazov Andrey Urazov
Andy Wood Andy Wood
Anil K. Vijendran Anil K. Vijendran


+ 4
- 0
WHATSNEW View File

@@ -897,6 +897,10 @@ Other changes:


* A new <resourceexists> condition can check whether resources exists. * A new <resourceexists> condition can check whether resources exists.


* <sql> has two new attributes errorproperty and warningproperty that
can be set if an error/warning occurs.
Bugzilla Report 38807.

Changes from Ant 1.7.0 TO Ant 1.7.1 Changes from Ant 1.7.0 TO Ant 1.7.1
============================================= =============================================




+ 4
- 0
contributors.xml View File

@@ -66,6 +66,10 @@
<first>Andrew</first> <first>Andrew</first>
<last>Everitt</last> <last>Everitt</last>
</name> </name>
<name>
<first>Andrew</first>
<last>Stevens</last>
</name>
<name> <name>
<first>Andrey</first> <first>Andrey</first>
<last>Urazov</last> <last>Urazov</last>


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

@@ -256,6 +256,18 @@ and <b>abort</b> execution and transaction and fail task.</p>
ever occurs)</td> ever occurs)</td>
</tr> </tr>


<tr>
<td valign="top">errorproperty</td>
<td valign="top">The name of a property to set in the event of an
error. <em>Since Ant 1.8.0</em></td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">warningproperty</td>
<td valign="top">The name of a property to set in the event of an
warning. <em>Since Ant 1.8.0</em></td>
<td align="center" valign="top">No</td>
</tr>
</table> </table>


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


+ 54
- 0
src/main/org/apache/tools/ant/taskdefs/SQLExec.java View File

@@ -250,6 +250,18 @@ public class SQLExec extends JDBCTask {
*/ */
private boolean treatWarningsAsErrors = false; private boolean treatWarningsAsErrors = false;


/**
* The name of the property to set in the event of an error
* @since Ant 1.8.0
*/
private String errorProperty = null;

/**
* The name of the property to set in the event of a warning
* @since Ant 1.8.0
*/
private String warningProperty = null;

/** /**
* Set the name of the SQL file to be run. * Set the name of the SQL file to be run.
* Required unless statements are enclosed in the build file * Required unless statements are enclosed in the build file
@@ -521,6 +533,28 @@ public class SQLExec extends JDBCTask {
csvQuoteChar = s; csvQuoteChar = s;
} }


/**
* Property to set to "true" if a statement throws an error.
*
* @param errorProperty the name of the property to set in the
* event of an error.
* @since Ant 1.8.0
*/
public void setErrorProperty(String errorProperty) {
this.errorProperty = errorProperty;
}

/**
* Property to set to "true" if a statement produces a warning.
*
* @param warningProperty the name of the property to set in the
* event of a warning.
* @since Ant 1.8.0
*/
public void setWarningProperty(String warningProperty) {
this.warningProperty = warningProperty;
}

/** /**
* Load the sql file and then execute it * Load the sql file and then execute it
* @throws BuildException on error. * @throws BuildException on error.
@@ -614,11 +648,13 @@ public class SQLExec extends JDBCTask {
if (onError.equals("abort")) { if (onError.equals("abort")) {
throw new BuildException(e, getLocation()); throw new BuildException(e, getLocation());
} }
setErrorProperty();
} catch (SQLException e) { } catch (SQLException e) {
closeQuietly(); closeQuietly();
if (onError.equals("abort")) { if (onError.equals("abort")) {
throw new BuildException(e, getLocation()); throw new BuildException(e, getLocation());
} }
setErrorProperty();
} finally { } finally {
try { try {
if (getStatement() != null) { if (getStatement() != null) {
@@ -758,6 +794,7 @@ public class SQLExec extends JDBCTask {
if (!onError.equals("continue")) { if (!onError.equals("continue")) {
throw e; throw e;
} }
setErrorProperty();
} finally { } finally {
if (resultSet != null) { if (resultSet != null) {
try { try {
@@ -1059,5 +1096,22 @@ public class SQLExec extends JDBCTask {
if (treatWarningsAsErrors && initialWarning != null) { if (treatWarningsAsErrors && initialWarning != null) {
throw initialWarning; throw initialWarning;
} }
if (initialWarning != null) {
setWarningProperty();
}
}

protected final void setErrorProperty() {
setProperty(errorProperty);
}

protected final void setWarningProperty() {
setProperty(warningProperty);
}

private void setProperty(String name) {
if (name != null) {
getProject().setNewProperty(name, "true");
}
} }
} }

Loading…
Cancel
Save