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

*: Check float length in parser #351

Merged
merged 1 commit into from
Oct 12, 2015
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
10 changes: 10 additions & 0 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -3681,6 +3681,16 @@ NumericType:
fopt := $2.(*coldef.FloatOpt)
x := types.NewFieldType($1.(byte))
x.Flen = fopt.Flen
if x.Tp == mysql.TypeFloat {
// Fix issue #312
if x.Flen > 53 {
yylex.(*lexer).errf("Float len(%d) should not be greater than 53", x.Flen)
return 1
}
if x.Flen > 24 {
x.Tp = mysql.TypeDouble
}
}
x.Decimal =fopt.Decimal
for _, o := range $3.([]*field.Opt) {
if o.IsUnsigned {
Expand Down
4 changes: 4 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ func (s *testParserSuite) TestParser0(c *C) {
{`select * from t as a`, true},
{"select 1 full, 1 row, 1 abs", true},
{"select * from t full, t1 row, t2 abs", true},

// For https://github.com/pingcap/tidb/issues/312
{`create table t (c float(53));`, true},
{`create table t (c float(54));`, false},
}

for _, t := range table {
Expand Down
38 changes: 38 additions & 0 deletions stmt/stmts/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,44 @@ func (s *testStmtSuite) TestCreateTable(c *C) {

// Test "if not exist"
mustExec(c, s.testDB, "CREATE TABLE if not exists test(id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id));")

// Testcase for https://github.com/pingcap/tidb/issues/312
mustExec(c, s.testDB, `create table issue312_1 (c float(24));`)
mustExec(c, s.testDB, `create table issue312_2 (c float(25));`)
tx = mustBegin(c, s.testDB)
rows, err := tx.Query(`desc issue312_1`)
c.Assert(err, IsNil)
for rows.Next() {
var (
c1 string
c2 string
c3 string
c4 string
c5 string
c6 string
)
rows.Scan(&c1, &c2, &c3, &c4, &c5, &c6)
c.Assert(c2, Equals, "float")
}
rows.Close()
mustCommit(c, tx)
tx = mustBegin(c, s.testDB)
rows, err = tx.Query(`desc issue312_2`)
c.Assert(err, IsNil)
for rows.Next() {
var (
c1 string
c2 string
c3 string
c4 string
c5 string
c6 string
)
rows.Scan(&c1, &c2, &c3, &c4, &c5, &c6)
c.Assert(c2, Equals, "double")
}
rows.Close()
mustCommit(c, tx)
}

func (s *testStmtSuite) TestCreateIndex(c *C) {
Expand Down