Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
sql: fix how nulls are sent to clients (#783)
Browse files Browse the repository at this point in the history
sql: fix how nulls are sent to clients
  • Loading branch information
ajnavarro committed Jul 4, 2019
2 parents 409efb9 + 688a79f commit 7f8224b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion _integration/go/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestGrafana(t *testing.T) {
},
{
`select @@version_comment limit 1`,
[][]string{{"NULL"}},
[][]string{{""}},
},
{
`describe table mytable`,
Expand Down
2 changes: 2 additions & 0 deletions engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ var queries = []struct {
{"ndbinfo_version", ""},
{"sql_select_limit", math.MaxInt32},
{"transaction_isolation", "READ UNCOMMITTED"},
{"version", ""},
{"version_comment", ""},
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions sql/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func DefaultSessionConfig() map[string]TypedValue {
"ndbinfo_version": TypedValue{Text, ""},
"sql_select_limit": TypedValue{Int32, math.MaxInt32},
"transaction_isolation": TypedValue{Text, "READ UNCOMMITTED"},
"version": TypedValue{Text, ""},
"version_comment": TypedValue{Text, ""},
}
}

Expand Down
16 changes: 8 additions & 8 deletions sql/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (t numberT) Type() query.Type {
// SQL implements Type interface.
func (t numberT) SQL(v interface{}) (sqltypes.Value, error) {
if v == nil {
return sqltypes.MakeTrusted(t.t, nil), nil
return sqltypes.NULL, nil
}

switch t.t {
Expand Down Expand Up @@ -441,7 +441,7 @@ var TimestampLayouts = []string{
// SQL implements Type interface.
func (t timestampT) SQL(v interface{}) (sqltypes.Value, error) {
if v == nil {
return sqltypes.MakeTrusted(sqltypes.Timestamp, nil), nil
return sqltypes.NULL, nil
}

v, err := t.Convert(v)
Expand Down Expand Up @@ -517,7 +517,7 @@ func (t dateT) Type() query.Type {

func (t dateT) SQL(v interface{}) (sqltypes.Value, error) {
if v == nil {
return sqltypes.MakeTrusted(sqltypes.Timestamp, nil), nil
return sqltypes.NULL, nil
}

v, err := t.Convert(v)
Expand Down Expand Up @@ -619,7 +619,7 @@ func (t textT) Type() query.Type {
// SQL implements Type interface.
func (t textT) SQL(v interface{}) (sqltypes.Value, error) {
if v == nil {
return sqltypes.MakeTrusted(sqltypes.Text, nil), nil
return sqltypes.NULL, nil
}

v, err := t.Convert(v)
Expand Down Expand Up @@ -656,7 +656,7 @@ func (t booleanT) Type() query.Type {
// SQL implements Type interface.
func (t booleanT) SQL(v interface{}) (sqltypes.Value, error) {
if v == nil {
return sqltypes.MakeTrusted(sqltypes.Bit, nil), nil
return sqltypes.NULL, nil
}

b := []byte{'0'}
Expand Down Expand Up @@ -716,7 +716,7 @@ func (t blobT) Type() query.Type {
// SQL implements Type interface.
func (t blobT) SQL(v interface{}) (sqltypes.Value, error) {
if v == nil {
return sqltypes.MakeTrusted(sqltypes.Blob, nil), nil
return sqltypes.NULL, nil
}

v, err := t.Convert(v)
Expand Down Expand Up @@ -760,7 +760,7 @@ func (t jsonT) Type() query.Type {
// SQL implements Type interface.
func (t jsonT) SQL(v interface{}) (sqltypes.Value, error) {
if v == nil {
return sqltypes.MakeTrusted(sqltypes.TypeJSON, nil), nil
return sqltypes.NULL, nil
}

v, err := t.Convert(v)
Expand Down Expand Up @@ -867,7 +867,7 @@ func (t arrayT) Type() query.Type {

func (t arrayT) SQL(v interface{}) (sqltypes.Value, error) {
if v == nil {
return sqltypes.MakeTrusted(sqltypes.TypeJSON, nil), nil
return sqltypes.NULL, nil
}

v, err := t.Convert(v)
Expand Down
2 changes: 1 addition & 1 deletion sql/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestIsNull(t *testing.T) {
require.True(t, IsNull(nil))

n := numberT{sqltypes.Uint64}
require.Equal(t, sqltypes.MakeTrusted(sqltypes.Uint64, nil), mustSQL(n.SQL(nil)))
require.Equal(t, sqltypes.NULL, mustSQL(n.SQL(nil)))
require.Equal(t, sqltypes.NewUint64(0), mustSQL(n.SQL(uint64(0))))
}

Expand Down

0 comments on commit 7f8224b

Please sign in to comment.