Skip to content

Commit

Permalink
lexer: support sql_mode 'NO_BACKSLASH_ESCAPES' (#5073)
Browse files Browse the repository at this point in the history
  • Loading branch information
spongedu authored and breezewish committed Nov 13, 2017
1 parent 20dc896 commit 294e348
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions mysql/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ func (m SQLMode) HasRealAsFloatMode() bool {
return m&ModeRealAsFloat == ModeRealAsFloat
}

// HasNoBackslashEscapesMode detects if 'NO_BACKSLASH_ESCAPES' mode is set in SQLMode
func (m SQLMode) HasNoBackslashEscapesMode() bool {
return m&ModeNoBackslashEscapes == ModeNoBackslashEscapes
}

// consts for sql modes.
const (
ModeNone SQLMode = 0
Expand Down
10 changes: 10 additions & 0 deletions mysql/const_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,13 @@ func (s *testMySQLConstSuite) TestHighNotPrecedenceMode(c *C) {
r = tk.MustQuery(`SELECT NOT 1 BETWEEN -5 AND 5;`)
r.Check(testkit.Rows("1"))
}

func (s *testMySQLConstSuite) TestNoBackslashEscapesMode(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set sql_mode=''")
r := tk.MustQuery("SELECT '\\\\'")
r.Check(testkit.Rows("\\"))
tk.MustExec("set sql_mode='NO_BACKSLASH_ESCAPES'")
r = tk.MustQuery("SELECT '\\\\'")
r.Check(testkit.Rows("\\\\"))
}
2 changes: 1 addition & 1 deletion parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ func (s *Scanner) scanString() (tok int, pos Pos, lit string) {
}
str := mb.r.data(&pos)
mb.setUseBuf(str[1 : len(str)-1])
} else if ch0 == '\\' {
} else if ch0 == '\\' && !s.sqlMode.HasNoBackslashEscapesMode() {
mb.setUseBuf(mb.r.data(&pos)[1:])
ch0 = handleEscape(s)
}
Expand Down

0 comments on commit 294e348

Please sign in to comment.