-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
parser: parse error compatible #4238
Conversation
mxlxm
commented
Aug 18, 2017
- add ParseErrorWith function to return mysql compatible parse error.
- error on unclose comment, fix Some incorrect SQLs in prepare doesn't return the parse error #3738.
mysql/const.go
Outdated
@@ -62,6 +62,9 @@ const ( | |||
MaxKeyParts int = 16 | |||
) | |||
|
|||
// ErrTextLength error text length limit. | |||
const ErrTextLength = 80 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it is 80 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested with mysql:
sql prepare p from "delete from t where a=1 /*' ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc";
and got response like:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/*' cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' at line 1
only keep nearest 80 bytes.
@@ -1551,6 +1551,8 @@ func (s *testParserSuite) TestComment(c *C) { | |||
{"START TRANSACTION /*!40108 WITH CONSISTENT SNAPSHOT */", true}, | |||
// for comment in query | |||
{"/*comment*/ /*comment*/ select c /* this is a comment */ from t;", true}, | |||
// for unclosed comment | |||
{"delete from t where a = 7 or 1=1/*' and b = 'p'", false}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add more tests for error messages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.
@@ -90,7 +90,7 @@ func (s *Scanner) Errors() []error { | |||
|
|||
// reset resets the sql string to be scanned. | |||
func (s *Scanner) reset(sql string) { | |||
s.r = reader{s: sql} | |||
s.r = reader{s: sql, p: Pos{Line: 1}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a bug fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, sql line counter should always start with 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
/ok-to-test |
@zz-jason PTAL |
/run-all-tests |
/run-all-test |
/ok-to-test |
/run-all-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM