You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2017/02/17 05:53:07 UTC

[2/3] ant git commit: Added option to force the csv quote char

Added option to force the csv quote char


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/a20c4195
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/a20c4195
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/a20c4195

Branch: refs/heads/1.9.x
Commit: a20c41951b850644b2b2cc3cbf17c696e6e0529c
Parents: 05d6972
Author: Francesco Steccanella <fs...@gmail.com>
Authored: Mon Feb 6 10:57:51 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Fri Feb 17 06:49:14 2017 +0100

----------------------------------------------------------------------
 .../org/apache/tools/ant/taskdefs/SQLExec.java    | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/a20c4195/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
index 6d1e514..d913566 100644
--- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
+++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
@@ -274,6 +274,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
      * @param srcFile the file containing the SQL command.
@@ -587,6 +592,13 @@ public class SQLExec extends JDBCTask {
     }
 
     /**
+     * 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);