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

parser: create integer type field with specified length should have warings #939

Merged
merged 6 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -9791,6 +9791,10 @@ NumericType:
// TODO: check flen 0
x := types.NewFieldType($1.(byte))
x.Flen = $2.(int)
if $2.(int) != types.UnspecifiedLength {
yylex.AppendError(yylex.Errorf("Integer display width is deprecated and will be removed in a future release."))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use ErrWarnDeprecatedIntegerDisplayWidth directly?

Copy link
Contributor Author

@AilinKid AilinKid Jul 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can't use a terror class directly in scanner here

ErrWarnDeprecatedIntegerDisplayWidth is used in TiDB to append warnings in statement context to replace the raw warning, it contains the error code 1681, error message.

the raw message is like: "You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use near ''%s" Integer display width is deprecated and will be removed in a future release" and the fault error code is 1064

parser.lastErrorAsWarn()
}
for _, o := range $3.([]*ast.TypeOpt) {
if o.IsUnsigned {
x.Flag |= mysql.UnsignedFlag
Expand Down
4 changes: 4 additions & 0 deletions yy_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ var (
ErrUnknownAlterAlgorithm = terror.ClassParser.New(mysql.ErrUnknownAlterAlgorithm, mysql.MySQLErrName[mysql.ErrUnknownAlterAlgorithm])
// ErrWrongValue returns for wrong value
ErrWrongValue = terror.ClassParser.New(mysql.ErrWrongValue, mysql.MySQLErrName[mysql.ErrWrongValue])
// ErrWarnDeprecatedSyntaxNoReplacement return when the syntax was deprecated and there is no replacement.
ErrWarnDeprecatedSyntaxNoReplacement = terror.ClassParser.New(mysql.ErrWarnDeprecatedSyntaxNoReplacement, mysql.MySQLErrName[mysql.ErrWarnDeprecatedSyntaxNoReplacement])
// ErrWarnDeprecatedIntegerDisplayWidth share the same code 1681, and it will be returned when length is specified in integer.
ErrWarnDeprecatedIntegerDisplayWidth = terror.ClassParser.New(mysql.ErrWarnDeprecatedSyntaxNoReplacement, "Integer display width is deprecated and will be removed in a future release.")
// SpecFieldPattern special result field pattern
SpecFieldPattern = regexp.MustCompile(`(\/\*!(M?[0-9]{5,6})?|\*\/)`)
specCodeStart = regexp.MustCompile(`^\/\*!(M?[0-9]{5,6})?[ \t]*`)
Expand Down