-
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
fix compatibility bug with convert string to int return wrong result #7483
Changes from 2 commits
b9fbedc
dca12b6
4995e15
41ef134
da7a1a6
42aaffb
02d161d
1b5e5cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,13 +236,13 @@ func getValidIntPrefix(sc *stmtctx.StatementContext, str string) (string, error) | |
if err != nil { | ||
return floatPrefix, errors.Trace(err) | ||
} | ||
return floatStrToIntStr(floatPrefix) | ||
return floatStrToIntStr(sc, floatPrefix, str) | ||
} | ||
|
||
// floatStrToIntStr converts a valid float string into valid integer string which can be parsed by | ||
// strconv.ParseInt, we can't parse float first then convert it to string because precision will | ||
// be lost. | ||
func floatStrToIntStr(validFloat string) (string, error) { | ||
func floatStrToIntStr(sc *stmtctx.StatementContext, validFloat string, oriStr string) (string, error) { | ||
var dotIdx = -1 | ||
var eIdx = -1 | ||
for i := 0; i < len(validFloat); i++ { | ||
|
@@ -275,7 +275,8 @@ func floatStrToIntStr(validFloat string) (string, error) { | |
} | ||
if exp > 0 && int64(intCnt) > (math.MaxInt64-int64(exp)) { | ||
// (exp + incCnt) overflows MaxInt64. | ||
return validFloat, ErrOverflow.GenByArgs("BIGINT", validFloat) | ||
sc.AppendError(ErrOverflow.GenByArgs("BIGINT", oriStr)) | ||
return validFloat[:eIdx], nil | ||
} | ||
intCnt += exp | ||
if intCnt <= 0 { | ||
|
@@ -292,7 +293,8 @@ func floatStrToIntStr(validFloat string) (string, error) { | |
extraZeroCount := intCnt - len(digits) | ||
if extraZeroCount > 20 { | ||
// Return overflow to avoid allocating too much memory. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we update this comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CodeRushing Please update this comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zz-jason already updated |
||
return validFloat, ErrOverflow.GenByArgs("BIGINT", validFloat) | ||
sc.AppendError(ErrOverflow.GenByArgs("BIGINT", oriStr)) | ||
return validFloat[:eIdx], nil | ||
} | ||
validInt = string(digits) + strings.Repeat("0", extraZeroCount) | ||
} | ||
|
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.
This means the previous error message is wrong?
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, the error message in this case is like below
mysql> show warnings;
+---------+------+-------------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: '125e342.83' |
+---------+------+-------------------------------------------------+
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.
So why
AppendError
? Shouldn't weAppendWarning
?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, it's should be AppendWarning. Already Fixed