Browse Source

new showWarnings attribute that makes <sql> display SQLWarnings - if any. PR 41836

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

+ 3
- 0
WHATSNEW View File

@@ -143,6 +143,9 @@ Other changes:
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
=============================================



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

@@ -212,6 +212,16 @@ and <b>abort</b> execution and transaction and fail task.</p>
"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>


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

@@ -205,6 +205,12 @@ public class SQLExec extends JDBCTask {
*/
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
@@ -413,6 +419,14 @@ public class SQLExec extends JDBCTask {
strictDelimiterMatching = b;
}

/**
* 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 @@ public class SQLExec extends JDBCTask {
}
if (ret) {
resultSet = getStatement().getResultSet();
if (showWarnings) {
printWarnings(resultSet.getWarnings(),
Project.MSG_WARN);
}
resultSet.clearWarnings();
if (print) {
printResults(resultSet, out);
}
@@ -607,16 +626,19 @@ public class SQLExec extends JDBCTask {
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 @@ public class SQLExec extends JDBCTask {
printValue(rs, col, out);
}
out.println();
if (showWarnings) {
printWarnings(rs.getWarnings(), Project.MSG_WARN);
}
}
}
}
@@ -891,4 +916,11 @@ public class SQLExec extends JDBCTask {
}
}
}

private void printWarnings(SQLWarning warning, int level) {
while (warning != null) {
log(warning + " sql warning", level);
warning = warning.getNextWarning();
}
}
}

Loading…
Cancel
Save