diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 1988638ee..17022c788 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -125,6 +125,7 @@ Erik Hatcher Erik Langenbach Erik Meade Ernst de Haan +Francesco Steccanella Frank Harnack Frank Somers Frank Zeyda diff --git a/WHATSNEW b/WHATSNEW index 1ce71737e..866080ce5 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -1,6 +1,13 @@ Changes from Ant 1.10.1 TO Ant 1.10.2 ===================================== +Other changes: +-------------- + + * Added forceCsvQuoteChar option to task. When enabled the + values always get quoted. + Github Pull Request #32 + Changes from Ant 1.10.0 TO Ant 1.10.1 ===================================== diff --git a/contributors.xml b/contributors.xml index 1356f3801..ee049cb17 100644 --- a/contributors.xml +++ b/contributors.xml @@ -523,6 +523,10 @@ Ernst de Haan + + Francesco + Steccanella + Frank Harnack diff --git a/manual/Tasks/sql.html b/manual/Tasks/sql.html index e5f4db837..bade59024 100644 --- a/manual/Tasks/sql.html +++ b/manual/Tasks/sql.html @@ -262,6 +262,13 @@ and abort execution and transaction and fail task.

ever occurs) + + forceCsvQuoteChar + If true, quoting always occurs + No, default is not set (i.e. quoting + occurs only where needed) + + errorproperty The name of a property to set in the event of an diff --git a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java index c4076bc20..d9b7fb460 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. @@ -859,7 +871,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))); @@ -893,9 +905,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);