ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r551323 - in /ant/core/trunk: WHATSNEW docs/manual/CoreTasks/sql.html src/main/org/apache/tools/ant/taskdefs/SQLExec.java
Date Wed, 27 Jun 2007 21:02:45 GMT
Author: mbenson
Date: Wed Jun 27 14:02:43 2007
New Revision: 551323

URL: http://svn.apache.org/viewvc?view=rev&rev=551323
Log:
"rawblobs" attribute added to SQL task.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/sql.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=551323&r1=551322&r2=551323
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Wed Jun 27 14:02:43 2007
@@ -160,6 +160,8 @@
 
 * 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
 ===================================

Modified: ant/core/trunk/docs/manual/CoreTasks/sql.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/sql.html?view=diff&rev=551323&r1=551322&r2=551323
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/sql.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/sql.html Wed Jun 27 14:02:43 2007
@@ -188,6 +188,13 @@
   <td width="10%" valign="top">No (default=true)</td>
 </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>
 
 <h3>Parameters specified as nested elements</h3>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java?view=diff&rev=551323&r1=551322&r2=551323
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java Wed Jun 27 14:02:43
2007
@@ -49,6 +49,7 @@
 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.
@@ -192,6 +193,12 @@
     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
      * @param srcFile the file containing the SQL command.
@@ -373,6 +380,15 @@
     }
 
     /**
+     * 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,16 +650,25 @@
                     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();
                 }
             }
         }
         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));
+        }
     }
 
     /*



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message