-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support nullable api response data (#133)
- Loading branch information
Showing
18 changed files
with
523 additions
and
492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package tests | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
) | ||
|
||
func (s *DatabendTestSuite) TestNullable() { | ||
_, err := s.db.Exec(fmt.Sprintf("INSERT INTO %s (i64) VALUES (?)", s.table), int64(1)) | ||
s.r.Nil(err) | ||
|
||
rows, err := s.db.Query(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, "NULL", "NULL", nil, nil, nil, nil}}, result) | ||
s.r.NoError(rows.Close()) | ||
|
||
_, err = s.db.Exec("SET GLOBAL format_null_as_str=0") | ||
s.r.Nil(err) | ||
|
||
rows, err = s.db.Query(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() { | ||
row := s.db.QueryRow("SELECT NULL") | ||
var val sql.NullString | ||
err := row.Scan(&val) | ||
s.r.Nil(err) | ||
s.r.True(val.Valid) | ||
s.r.Equal("NULL", val.String) | ||
} | ||
|
||
func (s *DatabendTestSuite) TestQueryNull() { | ||
_, err := s.db.Exec("SET GLOBAL format_null_as_str=0") | ||
s.r.Nil(err) | ||
|
||
row := s.db.QueryRow("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) | ||
} |
Oops, something went wrong.