mirror of
https://github.com/nxshock/mssqlbulkloader.git
synced 2024-11-27 00:11:02 +05:00
Enable lazy quotes for CSV files
This commit is contained in:
parent
3e96fdbb35
commit
c1958bafb8
@ -35,6 +35,7 @@ func newCsvReader(r io.Reader, options *Options) (*CsvReader, error) {
|
||||
re := csv.NewReader(bufReader)
|
||||
re.Comma = options.comma
|
||||
re.FieldsPerRecord = len(options.fieldsTypes)
|
||||
re.LazyQuotes = true
|
||||
|
||||
csvReader := &CsvReader{
|
||||
reader: re,
|
||||
|
@ -40,3 +40,37 @@ func TestCsvReaderBasic(t *testing.T) {
|
||||
err = csvReader.Close()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestCsvReaderBasicQuotes(t *testing.T) {
|
||||
f, err := os.Open("testdata/csv/9729337841_20032023_084313668.csv")
|
||||
assert.NoError(t, err)
|
||||
|
||||
options := &Options{
|
||||
encoding: "utf8",
|
||||
comma: rune(";"[0]),
|
||||
fieldsTypes: "s ",
|
||||
dateFormat: "02.01.2006",
|
||||
timestampFormat: "02.01.2006 15:04:05",
|
||||
timezone: time.Local}
|
||||
|
||||
csvReader, err := NewCsvReader(f, options)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, []string{"Территориальный банк"}, csvReader.GetHeader())
|
||||
|
||||
row, err := csvReader.GetRow(false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, []any{`ПАО "Сбербанк"`}, row)
|
||||
|
||||
row, err = csvReader.GetRow(false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, []any{`ПАО "Сбербанк"`}, row)
|
||||
|
||||
_, err = csvReader.GetRow(false)
|
||||
assert.Equal(t, err, io.EOF)
|
||||
|
||||
err = csvReader.Close()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
3
testdata/csv/9729337841_20032023_084313668.csv
vendored
Normal file
3
testdata/csv/9729337841_20032023_084313668.csv
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
Территориальный банк;ГОСБ;Номер мерчанта;Наименование ТСТ;Номер терминала;Дата операции;Дата ПП;Сумма операции;Сумма расчета;Номер карты;Код авторизации;Тип операции;Доп. информация_1;Доп. информация_2
|
||||
"ПАО ""Сбербанк""";Киевское ОСБ;781000815902;WINK;28403560;19.03.2023 17:49:35;20.03.2023 00:00:00;499,00;488,52;522598******7141;REZE64;Покупка;35068281112;307817403283
|
||||
ПАО "Сбербанк";Киевское ОСБ;781000815902;WINK;28403560;19.03.2023 17:49:35;20.03.2023 00:00:00;499,00;488,52;522598******7141;REZE64;Покупка;35068281112;307817403283
|
Can't render this file because it contains an unexpected character in line 3 and column 8.
|
Loading…
Reference in New Issue
Block a user