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

sql: fix how nulls are sent to clients #783

Merged
merged 1 commit into from
Jul 4, 2019
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 _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
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, ""},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add the real version here to maintain consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What version should we put? A fake mysql version? It might not be consistent with VERSION() though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cannot use the same param as VERSION() is using here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the thing, VERSION() doesn't even exist in plain go-mysql-server. It's registered in gitbase with a specific version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, right, I mix both. Sorry for the noise.

"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