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
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
  • Loading branch information
erizocosmico committed Jul 3, 2019
1 parent 8702d43 commit ad130ae
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
6 changes: 4 additions & 2 deletions engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ var queries = []struct {
{"ndbinfo_version", ""},
{"sql_select_limit", math.MaxInt32},
{"transaction_isolation", "READ UNCOMMITTED"},
{"version", ""},
{"version_comment", ""},
},
},
{
Expand Down Expand Up @@ -1237,8 +1239,8 @@ var queries = []struct {
{
`SELECT ARRAY_LENGTH("foo")`,
[]sql.Row{{nil}},
},
{
},
{
`SELECT * FROM mytable WHERE NULL AND i = 3`,
[]sql.Row{},
},
Expand Down
2 changes: 1 addition & 1 deletion server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"sync"
"time"

errors "gopkg.in/src-d/go-errors.v1"
sqle "github.com/src-d/go-mysql-server"
"github.com/src-d/go-mysql-server/auth"
"github.com/src-d/go-mysql-server/sql"
errors "gopkg.in/src-d/go-errors.v1"

"github.com/sirupsen/logrus"
"vitess.io/vitess/go/mysql"
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 @@ -303,7 +303,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 @@ -429,7 +429,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 @@ -505,7 +505,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 @@ -562,7 +562,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 @@ -599,7 +599,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 @@ -659,7 +659,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 @@ -703,7 +703,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 @@ -810,7 +810,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 ad130ae

Please sign in to comment.