-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First release
- Loading branch information
Showing
14 changed files
with
542 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# ChangeLog | ||
|
||
## 0.1.1 (2018-10-19) | ||
## 0.1.1 (2018-11-03) | ||
|
||
* First release | ||
* Created by converting https://github.com/hiroyuki-sato/digdag-plugin-mysql to mssql version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
seq,col1 | ||
1,10 | ||
2,20 | ||
col1 | ||
10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1')begin | ||
create table t1(col1 int); | ||
end | ||
|
||
insert into t1 values(10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
select * from t1; |
124 changes: 124 additions & 0 deletions
124
src/main/java/com/github/kulmam92/digdag/plugin/mssql/CsvWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package com.github.kulmam92.digdag.plugin.mssql; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.io.Closeable; | ||
import java.util.List; | ||
import java.util.concurrent.Exchanger; | ||
|
||
class CsvWriter | ||
implements Closeable | ||
{ | ||
private final Writer out; | ||
|
||
CsvWriter(Writer out) | ||
{ | ||
this.out = out; | ||
} | ||
|
||
void addCsvHeader(List<String> columnNames) | ||
throws IOException | ||
{ | ||
boolean first = true; | ||
for (String columnName : columnNames) { | ||
if (first) { first = false; } | ||
else { out.write(DELIMITER_CHAR); } | ||
addCsvText(columnName); | ||
} | ||
out.write("\r\n"); | ||
} | ||
|
||
void addCsvRow(List<String> row) | ||
throws IOException | ||
{ | ||
for (int i = 0; i < row.size(); i++) { | ||
if (i > 0) { | ||
out.write(DELIMITER_CHAR); | ||
} | ||
String v = row.get(i); | ||
addCsvText(v); | ||
} | ||
out.write("\r\n"); | ||
} | ||
|
||
private void addCsvText(String value) | ||
throws IOException | ||
{ | ||
if (value != null) { | ||
out.write(escapeAndQuoteCsvValue(value)); | ||
} | ||
} | ||
|
||
private static final char DELIMITER_CHAR = ','; | ||
private static final char ESCAPE_CHAR = '"'; | ||
private static final char QUOTE_CHAR = '"'; | ||
|
||
private String escapeAndQuoteCsvValue(String v) | ||
{ | ||
if (v.isEmpty()) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(QUOTE_CHAR); | ||
sb.append(QUOTE_CHAR); | ||
return sb.toString(); | ||
} | ||
|
||
StringBuilder escapedValue = new StringBuilder(); | ||
char previousChar = ' '; | ||
|
||
boolean isRequireQuote = false; | ||
|
||
for (int i = 0; i < v.length(); i++) { | ||
char c = v.charAt(i); | ||
|
||
if (c == QUOTE_CHAR) { | ||
escapedValue.append(ESCAPE_CHAR); | ||
escapedValue.append(c); | ||
isRequireQuote = true; | ||
} | ||
else if (c == '\r') { | ||
escapedValue.append('\n'); | ||
isRequireQuote = true; | ||
} | ||
else if (c == '\n') { | ||
if (previousChar != '\r') { | ||
escapedValue.append('\n'); | ||
isRequireQuote = true; | ||
} | ||
} | ||
else if (c == DELIMITER_CHAR) { | ||
escapedValue.append(c); | ||
isRequireQuote = true; | ||
} | ||
else { | ||
escapedValue.append(c); | ||
} | ||
previousChar = c; | ||
} | ||
|
||
if (isRequireQuote) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(QUOTE_CHAR); | ||
sb.append(escapedValue); | ||
sb.append(QUOTE_CHAR); | ||
return sb.toString(); | ||
} | ||
else { | ||
return escapedValue.toString(); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() | ||
throws IOException | ||
{ | ||
out.close(); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "CSVWriter{" + | ||
"out=" + out + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.