diff --git a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java index 6d1e5148c..d91356665 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java +++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java @@ -273,6 +273,11 @@ public class SQLExec extends JDBCTask { */ private String rowCountProperty = null; + /** + * The name of the property to force the csv quote character + */ + private boolean forceCsvQuoteChar = false; + /** * Set the name of the SQL file to be run. * Required unless statements are enclosed in the build file @@ -586,6 +591,13 @@ public class SQLExec extends JDBCTask { this.rowCountProperty = rowCountProperty; } + /** + * Force the csv quote character + */ + public void setForceCsvQuoteChar(boolean forceCsvQuoteChar) { + this.forceCsvQuoteChar = forceCsvQuoteChar; + } + /** * Load the sql file and then execute it * @throws BuildException on error. @@ -878,7 +890,7 @@ public class SQLExec extends JDBCTask { int columnCount = md.getColumnCount(); if (columnCount > 0) { if (showheaders) { - out.print(md.getColumnName(1)); + out.print(maybeQuote(md.getColumnName(1))); for (int col = 2; col <= columnCount; col++) { out.print(csvColumnSep); out.print(maybeQuote(md.getColumnName(col))); @@ -912,9 +924,7 @@ public class SQLExec extends JDBCTask { } private String maybeQuote(String s) { - if (csvQuoteChar == null || s == null - || (s.indexOf(csvColumnSep) == -1 && s.indexOf(csvQuoteChar) == -1) - ) { + if (csvQuoteChar == null || s == null || (!forceCsvQuoteChar && s.indexOf(csvColumnSep) == -1 && s.indexOf(csvQuoteChar) == -1)) { return s; } StringBuffer sb = new StringBuffer(csvQuoteChar);