@@ -205,6 +205,12 @@ public class SQLExec extends JDBCTask {
*/
*/
private boolean strictDelimiterMatching = true;
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.
* 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
@@ -413,6 +419,14 @@ public class SQLExec extends JDBCTask {
strictDelimiterMatching = b;
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
* Load the sql file and then execute it
* @throws BuildException on error.
* @throws BuildException on error.
@@ -599,6 +613,11 @@ public class SQLExec extends JDBCTask {
}
}
if (ret) {
if (ret) {
resultSet = getStatement().getResultSet();
resultSet = getStatement().getResultSet();
if (showWarnings) {
printWarnings(resultSet.getWarnings(),
Project.MSG_WARN);
}
resultSet.clearWarnings();
if (print) {
if (print) {
printResults(resultSet, out);
printResults(resultSet, out);
}
}
@@ -607,16 +626,19 @@ public class SQLExec extends JDBCTask {
updateCount = getStatement().getUpdateCount();
updateCount = getStatement().getUpdateCount();
} while (ret || updateCount != -1);
} while (ret || updateCount != -1);
if (showWarnings) {
printWarnings(getStatement().getWarnings(), Project.MSG_WARN);
}
getStatement().clearWarnings();
log(updateCountTotal + " rows affected", Project.MSG_VERBOSE);
log(updateCountTotal + " rows affected", Project.MSG_VERBOSE);
if (print && showtrailers) {
if (print && showtrailers) {
out.println(updateCountTotal + " rows affected");
out.println(updateCountTotal + " rows affected");
}
}
SQLWarning warning = getConnection().getWarnings();
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();
getConnection().clearWarnings();
goodSql++;
goodSql++;
} catch (SQLException e) {
} catch (SQLException e) {
@@ -685,6 +707,9 @@ public class SQLExec extends JDBCTask {
printValue(rs, col, out);
printValue(rs, col, out);
}
}
out.println();
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();
}
}
}
}