Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: the quote function should treat null expr as NULL literal string instead of NULL (#11592) #11619

Merged
merged 5 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
expression: the quote func for null arg should map to "NULL" string
  • Loading branch information
gaoxingliang authored and root committed Aug 5, 2019
commit a901d38b9ab4f70d6b198314b320974516e27ed3
7 changes: 6 additions & 1 deletion expression/builtin_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -2696,10 2696,15 @@ func (b *builtinQuoteSig) Clone() builtinFunc {
// See https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_quote
func (b *builtinQuoteSig) evalString(row chunk.Row) (string, bool, error) {
str, isNull, err := b.args[0].EvalString(b.ctx, row)
if isNull || err != nil {

if err != nil {
return "", true, err
} else if isNull {
// If the argument is NULL, the return value is the word “NULL” without enclosing single quotation marks.
return "NULL", false, err
}


runes := []rune(str)
buffer := bytes.NewBufferString("")
buffer.WriteRune('\'')
Expand Down
13 changes: 13 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4699,3 4699,16 @@ 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`))
}