Merge pull request #351 from pingcap/shenli/issue-312
*: Check float length in parser
This commit is contained in:
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user