Compare commits

..

4 Commits

Author SHA1 Message Date
3e96fdbb35 Remove ineffectual assignments 2024-02-09 09:50:02 +05:00
143ba6aae2 Use money type in tests 2024-02-09 09:49:22 +05:00
81729ffcd0 Remove spaces before parsing float types 2024-02-09 09:46:09 +05:00
ab95f49c96 Implement money type as numeric field 2024-02-09 09:45:27 +05:00
3 changed files with 9 additions and 7 deletions

View File

@ -41,8 +41,10 @@ func (ft FieldType) ParseValue(reader Reader, s string) (any, error) {
return s, nil
case Integer:
return strconv.ParseInt(s, 10, 64)
case Float:
return strconv.ParseFloat(strings.ReplaceAll(s, ",", "."), 64)
case Float, Money:
s = strings.ReplaceAll(s, ",", ".")
s = strings.ReplaceAll(s, " ", "")
return strconv.ParseFloat(s, 64)
case Date:
if i, ok := reader.(CustomDateParser); ok {
t, err := i.ParseDate(s)
@ -77,7 +79,7 @@ func (ft FieldType) SqlFieldType() string {
case Float:
return "float"
case Money:
panic("do not implemented - see https://github.com/denisenkom/go-mssqldb/issues/460") // TODO: https://github.com/denisenkom/go-mssqldb/issues/460
return "numeric(15, 2)" // TODO: https://github.com/denisenkom/go-mssqldb/issues/460
case Date:
return "date"
case Timestamp:

View File

@ -17,7 +17,7 @@ func TestCsvReaderBasic(t *testing.T) {
encoding: "win1251",
comma: rune(";"[0]),
skipRows: 3,
fieldsTypes: "s ttffsssss",
fieldsTypes: "s ttmmsssss",
dateFormat: "02.01.2006",
timestampFormat: "02.01.2006 15:04:05",
timezone: time.Local}
@ -34,7 +34,7 @@ func TestCsvReaderBasic(t *testing.T) {
t2 := time.Date(2023, 03, 20, 0, 0, 0, 0, time.Local)
assert.Equal(t, []any{"307814009186", t1, t2, 499.00, 488.52, "522598******7141", "REZE64", "Покупка", "35068281112", "307817403283"}, row)
row, err = csvReader.GetRow(false)
_, err = csvReader.GetRow(false)
assert.Equal(t, err, io.EOF)
err = csvReader.Close()

View File

@ -14,7 +14,7 @@ func TestDbfReaderBasic(t *testing.T) {
assert.NoError(t, err)
options := &Options{
fieldsTypes: "sssssstdffsss",
fieldsTypes: "sssssstdmmsss",
timezone: time.Local,
encoding: "cp866"}
@ -30,7 +30,7 @@ func TestDbfReaderBasic(t *testing.T) {
t2 := time.Date(2023, 02, 21, 0, 0, 0, 0, time.Local)
assert.Equal(t, []any{"719089383780", "44", "8644", "570000009312", "STOLOVAYA TSPP", "844417", t1, t2, 1757.08, 1713.15, "536829XXXXXX9388", "UM1TS8", "D"}, row)
row, err = dbfReader.GetRow(false)
_, err = dbfReader.GetRow(false)
assert.Equal(t, err, io.EOF)
err = dbfReader.Close()