Skip to content

Commit

Permalink
expression: the quote func for null arg should map to "NULL" string (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoxingliang authored and SunRunAway committed Nov 22, 2019
1 parent 211d45a commit fe2f252
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion expression/builtin_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@ func (s *testEvaluatorSuite) TestQuote(c *C) {
{`萌萌哒(๑•ᴗ•๑)😊`, `'萌萌哒(๑•ᴗ•๑)😊'`},
{`㍿㌍㍑㌫`, `'㍿㌍㍑㌫'`},
{string([]byte{0, 26}), `'\0\Z'`},
{nil, nil},
{nil, "NULL"},
}

for _, t := range tbl {
Expand Down
22 changes: 8 additions & 14 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,14 @@ func (s *testIntegrationSuite) TestStringBuiltin(c *C) {
result = tk.MustQuery(`select quote("aaaa"), quote(""), quote("\"\""), quote("\n\n");`)
result.Check(testkit.Rows("'aaaa' '' '\"\"' '\n\n'"))
result = tk.MustQuery(`select quote(0121), quote(0000), quote("中文"), quote(NULL);`)
result.Check(testkit.Rows("'121' '0' '中文' <nil>"))
result.Check(testkit.Rows("'121' '0' '中文' NULL"))
tk.MustQuery(`select quote(null) is NULL;`).Check(testkit.Rows(`0`))
tk.MustQuery(`select quote(null) is NOT NULL;`).Check(testkit.Rows(`1`))
tk.MustQuery(`select length(quote(null));`).Check(testkit.Rows(`4`))
tk.MustQuery(`select quote(null) REGEXP binary 'null'`).Check(testkit.Rows(`0`))
tk.MustQuery(`select quote(null) REGEXP binary 'NULL'`).Check(testkit.Rows(`1`))
tk.MustQuery(`select quote(null) REGEXP 'NULL'`).Check(testkit.Rows(`1`))
tk.MustQuery(`select quote(null) REGEXP 'null'`).Check(testkit.Rows(`1`))

// for convert
result = tk.MustQuery(`select convert("123" using "binary"), convert("中文" using "binary"), convert("中文" using "utf8"), convert("中文" using "utf8mb4"), convert(cast("中文" as binary) using "utf8");`)
Expand Down Expand Up @@ -4477,16 +4484,3 @@ func (s *testIntegrationSuite) TestIssue11309And11319(c *C) {
tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_HOUR)`).Check(testkit.Rows("2007-03-31 00:08:28"))
tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 YEAR_MONTH)`).Check(testkit.Rows("2009-05-28 22:08:28"))
}


func (s *testIntegrationSuite) TestQuote(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustQuery(`select quote(null) is NULL;`).Check(testkit.Rows(`0`))
tk.MustQuery(`select quote(null) is NOT NULL;`).Check(testkit.Rows(`1`))
tk.MustQuery(`select length(quote(null));`).Check(testkit.Rows(`4`))
tk.MustQuery(`select quote(null) REGEXP binary 'null'`).Check(testkit.Rows(`0`))
tk.MustQuery(`select quote(null) REGEXP binary 'NULL'`).Check(testkit.Rows(`1`))
tk.MustQuery(`select quote(null) REGEXP 'NULL'`).Check(testkit.Rows(`1`))
tk.MustQuery(`select quote(null) REGEXP 'null'`).Check(testkit.Rows(`1`))
}

0 comments on commit fe2f252

Please sign in to comment.