Skip to content

Commit

Permalink
fix: test format_null_as_str with conn (#139)
Browse files Browse the repository at this point in the history
* fix: test format_null_as_str with conn

* z
  • Loading branch information
everpcpc authored Aug 28, 2024
1 parent 2892b78 commit 67f935d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
volumes:
- ./data:/data
databend:
image: datafuselabs/databend:nightly
image: datafuselabs/databend
environment:
- QUERY_DEFAULT_USER=databend
- QUERY_DEFAULT_PASSWORD=databend
Expand Down
23 changes: 13 additions & 10 deletions tests/nullable_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"context"
"database/sql"
"fmt"
)
Expand All @@ -16,18 +17,19 @@ func (s *DatabendTestSuite) TestNullable() {
s.r.Equal([][]interface{}{{int64(1), nil, nil, "NULL", "NULL", nil, nil, nil, nil}}, result)
s.r.NoError(rows.Close())

_, err = s.db.Exec("SET GLOBAL format_null_as_str=0")
ctx := context.TODO()
conn, err := s.db.Conn(ctx)
s.r.Nil(err)

rows, err = s.db.Query(fmt.Sprintf("SELECT * FROM %s", s.table))
_, err = conn.ExecContext(ctx, "SET format_null_as_str=0")
s.r.Nil(err)

rows, err = conn.QueryContext(ctx, fmt.Sprintf("SELECT * FROM %s", s.table))
s.r.Nil(err)
result, err = scanValues(rows)
s.r.Nil(err)
s.r.Equal([][]interface{}{{int64(1), nil, nil, nil, nil, nil, nil, nil, nil}}, result)
s.r.NoError(rows.Close())

_, err = s.db.Exec("UNSET format_null_as_str")
s.r.Nil(err)
}

func (s *DatabendTestSuite) TestQueryNullAsStr() {
Expand All @@ -40,16 +42,17 @@ func (s *DatabendTestSuite) TestQueryNullAsStr() {
}

func (s *DatabendTestSuite) TestQueryNull() {
_, err := s.db.Exec("SET GLOBAL format_null_as_str=0")
ctx := context.TODO()
conn, err := s.db.Conn(ctx)
s.r.Nil(err)

row := s.db.QueryRow("SELECT NULL")
_, err = conn.ExecContext(ctx, "SET format_null_as_str=0")
s.r.Nil(err)

row := conn.QueryRowContext(ctx, "SELECT NULL")
var val sql.NullString
err = row.Scan(&val)
s.r.Nil(err)
s.r.False(val.Valid)
s.r.Equal("", val.String)

_, err = s.db.Exec("UNSET format_null_as_str")
s.r.Nil(err)
}

0 comments on commit 67f935d

Please sign in to comment.