diff --git a/WHATSNEW b/WHATSNEW index 5f5e6abac..0ceb5f5a8 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -160,6 +160,8 @@ Other changes: * Default text added to macrodef. Bugzilla report 42301. +* "rawblobs" attribute added to SQL task. + Changes from Ant 1.6.5 to Ant 1.7.0 =================================== diff --git a/docs/manual/CoreTasks/sql.html b/docs/manual/CoreTasks/sql.html index 8b49307f1..f70c426e3 100644 --- a/docs/manual/CoreTasks/sql.html +++ b/docs/manual/CoreTasks/sql.html @@ -188,6 +188,13 @@ and abort execution and transaction and fail task.

No (default=true) + + rawblobs + If true, will write raw streams rather than hex encoding when + printing BLOB results. Since Ant 1.7.1. + No, default false + +

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 79ffa952e..edac9c0b4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java +++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java @@ -49,6 +49,7 @@ import java.sql.SQLException; import java.sql.SQLWarning; import java.sql.ResultSet; import java.sql.ResultSetMetaData; +import java.sql.Types; /** * Executes a series of SQL statements on a database using JDBC. @@ -191,6 +192,12 @@ public class SQLExec extends JDBCTask { */ private boolean expandProperties = true; + /** + * should we print raw BLOB data? + * @since Ant 1.7.1 + */ + private boolean rawBlobs; + /** * Set the name of the SQL file to be run. * Required unless statements are enclosed in the build file @@ -372,6 +379,15 @@ public class SQLExec extends JDBCTask { escapeProcessing = enable; } + /** + * Set whether to print raw BLOBs rather than their string (hex) representations. + * @param rawBlobs whether to print raw BLOBs. + * @since Ant 1.7.1 + */ + public void setRawBlobs(boolean rawBlobs) { + this.rawBlobs = rawBlobs; + } + /** * Load the sql file and then execute it * @throws BuildException on error. @@ -634,10 +650,10 @@ public class SQLExec extends JDBCTask { out.println(); } while (rs.next()) { - out.print(rs.getString(1)); + printValue(rs, 1, out); for (int col = 2; col <= columnCount; col++) { out.write(','); - out.print(rs.getString(col)); + printValue(rs, col, out); } out.println(); } @@ -646,6 +662,15 @@ public class SQLExec extends JDBCTask { out.println(); } + private void printValue(ResultSet rs, int col, PrintStream out) + throws SQLException { + if (rawBlobs && rs.getMetaData().getColumnType(col) == Types.BLOB) { + new StreamPumper(rs.getBlob(col).getBinaryStream(), out).run(); + } else { + out.print(rs.getString(col)); + } + } + /* * Closes an unused connection after an error and doesn't rethrow * a possible SQLException