|
@@ -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 |
|
|