Browse Source

"rawblobs" attribute added to SQL task.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@551323 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 18 years ago
parent
commit
63fb4d459b
3 changed files with 36 additions and 2 deletions
  1. +2
    -0
      WHATSNEW
  2. +7
    -0
      docs/manual/CoreTasks/sql.html
  3. +27
    -2
      src/main/org/apache/tools/ant/taskdefs/SQLExec.java

+ 2
- 0
WHATSNEW View File

@@ -160,6 +160,8 @@ Other changes:


* Default text added to macrodef. Bugzilla report 42301. * 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 Changes from Ant 1.6.5 to Ant 1.7.0
=================================== ===================================


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

@@ -188,6 +188,13 @@ and <b>abort</b> execution and transaction and fail task.</p>
<td width="10%" valign="top">No (default=true)</td> <td width="10%" valign="top">No (default=true)</td>
</tr> </tr>


<tr>
<td width="12%" valign="top">rawblobs</td>
<td width="78%" valign="top">If true, will write raw streams rather than hex encoding when
printing BLOB results. <em>Since Ant 1.7.1</em>.</td>
<td width="10%" valign="top">No, default <em>false</em></td>
</tr>

</table> </table>


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


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

@@ -49,6 +49,7 @@ import java.sql.SQLException;
import java.sql.SQLWarning; import java.sql.SQLWarning;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.Types;


/** /**
* Executes a series of SQL statements on a database using JDBC. * Executes a series of SQL statements on a database using JDBC.
@@ -191,6 +192,12 @@ public class SQLExec extends JDBCTask {
*/ */
private boolean expandProperties = true; 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. * 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
@@ -372,6 +379,15 @@ public class SQLExec extends JDBCTask {
escapeProcessing = enable; 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 * Load the sql file and then execute it
* @throws BuildException on error. * @throws BuildException on error.
@@ -634,10 +650,10 @@ public class SQLExec extends JDBCTask {
out.println(); out.println();
} }
while (rs.next()) { while (rs.next()) {
out.print(rs.getString(1));
printValue(rs, 1, out);
for (int col = 2; col <= columnCount; col++) { for (int col = 2; col <= columnCount; col++) {
out.write(','); out.write(',');
out.print(rs.getString(col));
printValue(rs, col, out);
} }
out.println(); out.println();
} }
@@ -646,6 +662,15 @@ public class SQLExec extends JDBCTask {
out.println(); 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 * Closes an unused connection after an error and doesn't rethrow
* a possible SQLException * a possible SQLException


Loading…
Cancel
Save