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

Commit 7f8224b

Browse files
authored
sql: fix how nulls are sent to clients (#783)
sql: fix how nulls are sent to clients
2 parents 409efb9 + 688a79f commit 7f8224b

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

_integration/go/mysql_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestGrafana(t *testing.T) {
7474
},
7575
{
7676
`select @@version_comment limit 1`,
77-
[][]string{{"NULL"}},
77+
[][]string{{""}},
7878
},
7979
{
8080
`describe table mytable`,

engine_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,8 @@ var queries = []struct {
650650
{"ndbinfo_version", ""},
651651
{"sql_select_limit", math.MaxInt32},
652652
{"transaction_isolation", "READ UNCOMMITTED"},
653+
{"version", ""},
654+
{"version_comment", ""},
653655
},
654656
},
655657
{

sql/session.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ func DefaultSessionConfig() map[string]TypedValue {
175175
"ndbinfo_version": TypedValue{Text, ""},
176176
"sql_select_limit": TypedValue{Int32, math.MaxInt32},
177177
"transaction_isolation": TypedValue{Text, "READ UNCOMMITTED"},
178+
"version": TypedValue{Text, ""},
179+
"version_comment": TypedValue{Text, ""},
178180
}
179181
}
180182

sql/type.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func (t numberT) Type() query.Type {
315315
// SQL implements Type interface.
316316
func (t numberT) SQL(v interface{}) (sqltypes.Value, error) {
317317
if v == nil {
318-
return sqltypes.MakeTrusted(t.t, nil), nil
318+
return sqltypes.NULL, nil
319319
}
320320

321321
switch t.t {
@@ -441,7 +441,7 @@ var TimestampLayouts = []string{
441441
// SQL implements Type interface.
442442
func (t timestampT) SQL(v interface{}) (sqltypes.Value, error) {
443443
if v == nil {
444-
return sqltypes.MakeTrusted(sqltypes.Timestamp, nil), nil
444+
return sqltypes.NULL, nil
445445
}
446446

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

518518
func (t dateT) SQL(v interface{}) (sqltypes.Value, error) {
519519
if v == nil {
520-
return sqltypes.MakeTrusted(sqltypes.Timestamp, nil), nil
520+
return sqltypes.NULL, nil
521521
}
522522

523523
v, err := t.Convert(v)
@@ -619,7 +619,7 @@ func (t textT) Type() query.Type {
619619
// SQL implements Type interface.
620620
func (t textT) SQL(v interface{}) (sqltypes.Value, error) {
621621
if v == nil {
622-
return sqltypes.MakeTrusted(sqltypes.Text, nil), nil
622+
return sqltypes.NULL, nil
623623
}
624624

625625
v, err := t.Convert(v)
@@ -656,7 +656,7 @@ func (t booleanT) Type() query.Type {
656656
// SQL implements Type interface.
657657
func (t booleanT) SQL(v interface{}) (sqltypes.Value, error) {
658658
if v == nil {
659-
return sqltypes.MakeTrusted(sqltypes.Bit, nil), nil
659+
return sqltypes.NULL, nil
660660
}
661661

662662
b := []byte{'0'}
@@ -716,7 +716,7 @@ func (t blobT) Type() query.Type {
716716
// SQL implements Type interface.
717717
func (t blobT) SQL(v interface{}) (sqltypes.Value, error) {
718718
if v == nil {
719-
return sqltypes.MakeTrusted(sqltypes.Blob, nil), nil
719+
return sqltypes.NULL, nil
720720
}
721721

722722
v, err := t.Convert(v)
@@ -760,7 +760,7 @@ func (t jsonT) Type() query.Type {
760760
// SQL implements Type interface.
761761
func (t jsonT) SQL(v interface{}) (sqltypes.Value, error) {
762762
if v == nil {
763-
return sqltypes.MakeTrusted(sqltypes.TypeJSON, nil), nil
763+
return sqltypes.NULL, nil
764764
}
765765

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

868868
func (t arrayT) SQL(v interface{}) (sqltypes.Value, error) {
869869
if v == nil {
870-
return sqltypes.MakeTrusted(sqltypes.TypeJSON, nil), nil
870+
return sqltypes.NULL, nil
871871
}
872872

873873
v, err := t.Convert(v)

sql/type_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestIsNull(t *testing.T) {
1313
require.True(t, IsNull(nil))
1414

1515
n := numberT{sqltypes.Uint64}
16-
require.Equal(t, sqltypes.MakeTrusted(sqltypes.Uint64, nil), mustSQL(n.SQL(nil)))
16+
require.Equal(t, sqltypes.NULL, mustSQL(n.SQL(nil)))
1717
require.Equal(t, sqltypes.NewUint64(0), mustSQL(n.SQL(uint64(0))))
1818
}
1919

0 commit comments

Comments
 (0)