Skip to content

Commit

Permalink
Merge pull request #127 from mailru/finnan444-fix/nullable-date-time-…
Browse files Browse the repository at this point in the history
…parse

Finnan444 fix/nullable date time parse
  • Loading branch information
DoubleDi committed Jun 4, 2021
2 parents a4341c0 + cc0473d commit 0355cf7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -5,8 +5,10 @@ Yet another Golang SQL database driver for [Yandex ClickHouse](https://clickhous
## Key features

* Uses official http interface
* Compatibility with database/sql
* Compatibility with [dbr](https://github.com/mailru/dbr)
* Compatibility with [chproxy](https://github.com/Vertamedia/chproxy)
* Compatibility with [clickhouse-bulk](https://github.com/nikepan/clickhouse-bulk)

## DSN
```
Expand Down Expand Up @@ -183,7 +185,7 @@ func main() {
}

ctx := context.Background()
rows, err := connect.QueryContext(context.WithValue(ctx, clickhouse.QueryID, "dummy-query-id"), `
rows, err = connect.QueryContext(context.WithValue(ctx, clickhouse.QueryID, "dummy-query-id"), `
SELECT
country_code,
os_id,
Expand Down
5 changes: 4 additions & 1 deletion dataparser.go
Expand Up @@ -184,7 +184,10 @@ func (p *nullableParser) Parse(s io.RuneScanner) (driver.Value, error) {
for {
r, _, err := s.ReadRune()
if err != nil {
return nil, nil
if err != io.EOF {
return nil, fmt.Errorf("unexpected error on ReadRune: %v", err)
}
break
}

runes += string(r)
Expand Down
18 changes: 18 additions & 0 deletions dataparser_test.go
Expand Up @@ -476,6 +476,24 @@ func TestParseDataNewNullableArray(t *testing.T) {
inputdata: `\N`,
output: nil,
},
{
name: "nullable null date",
inputtype: "Nullable(Date)",
inputdata: `\N`,
output: nil,
},
{
name: "nullable not null datetime",
inputtype: "Nullable(DateTime)",
inputdata: "2018-01-02 12:34:56",
output: time.Date(2018, 1, 2, 12, 34, 56, 0, time.UTC),
},
{
name: "nullable not null date",
inputtype: "Nullable(Date)",
inputdata: "2018-01-02",
output: time.Date(2018, 1, 2, 0, 0, 0, 0, time.UTC),
},
{
name: "nullable null enum",
inputtype: "Nullable(Enum8('hello' = 1, 'world' = 2))",
Expand Down

0 comments on commit 0355cf7

Please sign in to comment.