Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test format_null_as_str with conn #139

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}