Skip to content

Commit 5b35094

Browse files
committed
fix ifnull typing
1 parent fead863 commit 5b35094

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

server/handler_test.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ func TestHandlerComPrepareExecuteWithPreparedDisabled(t *testing.T) {
537537

538538
for _, test := range []testcase{
539539
{
540-
name: "select statement returns nil schema",
540+
name: "select statement returns nil schema bug",
541541
prepare: &mysql.PrepareData{
542542
StatementID: 0,
543543
PrepareStmt: "select c1 from test where c1 < ?",
@@ -555,6 +555,40 @@ func TestHandlerComPrepareExecuteWithPreparedDisabled(t *testing.T) {
555555
{0}, {1}, {2}, {3}, {4},
556556
},
557557
},
558+
{
559+
name: "ifnull typing",
560+
prepare: &mysql.PrepareData{
561+
StatementID: 0,
562+
PrepareStmt: "select ifnull(not null, 1000) as a",
563+
ParamsCount: 0,
564+
ParamsType: nil,
565+
ColumnNames: nil,
566+
BindVars: nil,
567+
},
568+
schema: []*query.Field{
569+
{Name: "a", OrgName: "a", Table: "", OrgTable: "", Database: "", Type: query.Type_INT16, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 6, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)},
570+
},
571+
expected: []sql.Row{
572+
{1000},
573+
},
574+
},
575+
{
576+
name: "ifnull typing negative",
577+
prepare: &mysql.PrepareData{
578+
StatementID: 0,
579+
PrepareStmt: "select ifnull(not null, -129) as a",
580+
ParamsCount: 0,
581+
ParamsType: nil,
582+
ColumnNames: nil,
583+
BindVars: nil,
584+
},
585+
schema: []*query.Field{
586+
{Name: "a", OrgName: "a", Table: "", OrgTable: "", Database: "", Type: query.Type_INT16, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 6, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)},
587+
},
588+
expected: []sql.Row{
589+
{-129},
590+
},
591+
},
558592
} {
559593
t.Run(test.name, func(t *testing.T) {
560594
handler.ComInitDB(dummyConn, "test")

sql/expression/boolean.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ func NewNot(child sql.Expression) *Not {
3636

3737
// Type implements the Expression interface.
3838
func (e *Not) Type() sql.Type {
39+
if types.IsNull(e.Child) {
40+
return types.Null
41+
}
3942
return types.Boolean
4043
}
4144

0 commit comments

Comments
 (0)