From a20c41951b850644b2b2cc3cbf17c696e6e0529c Mon Sep 17 00:00:00 2001
From: Francesco Steccanella
Date: Mon, 6 Feb 2017 10:57:51 +0100
Subject: [PATCH 1/3] Added option to force the csv quote char
---
.../org/apache/tools/ant/taskdefs/SQLExec.java | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
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);
From 474d23b554cef3164e5edc65ab1d1a52727b9b42 Mon Sep 17 00:00:00 2001
From: Francesco Steccanella
Date: Thu, 16 Feb 2017 12:13:40 +0100
Subject: [PATCH 2/3] Added forceCsvQuoteChar option
---
manual/Tasks/sql.html | 7 +++++++
1 file changed, 7 insertions(+)
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
From 54f5c5fbbd51f2f7bf239756010f49fdfc99dd55 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
Date: Fri, 17 Feb 2017 06:51:47 +0100
Subject: [PATCH 3/3] Record new forceCsvQuoteChar by Francesco Steccanella
closes #32
---
CONTRIBUTORS | 1 +
WHATSNEW | 7 +++++++
contributors.xml | 4 ++++
3 files changed, 12 insertions(+)
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 781ed0137..2c10b1efe 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -1,6 +1,13 @@
Changes from Ant 1.9.9 TO Ant 1.9.10
====================================
+Other changes:
+--------------
+
+ * Added forceCsvQuoteChar option to task. When enabled the
+ values always get quoted.
+ Github Pull Request #32
+
Changes from Ant 1.9.8 TO Ant 1.9.9
===================================
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
|