Browse Source

Added option to force the csv quote char

master
Francesco Steccanella Stefan Bodewig 8 years ago
parent
commit
a20c41951b
1 changed files with 14 additions and 4 deletions
  1. +14
    -4
      src/main/org/apache/tools/ant/taskdefs/SQLExec.java

+ 14
- 4
src/main/org/apache/tools/ant/taskdefs/SQLExec.java View File

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


Loading…
Cancel
Save