Skip to content

Commit

Permalink
executor, types: fix bug of insert into unsigned float/double (#6939) (
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu authored and zz-jason committed Jul 2, 2018
1 parent 79df983 commit b74990f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 9 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ func (s *testSuite) TestInsert(c *C) {
tk.MustQuery("select * from t").Check(testkit.Rows("17:37:09.055870", "17:37:09.055000", "17:37:09.055870"))
_, err = tk.Exec("insert into t value(-20070219173709.055870)")
c.Assert(err.Error(), Equals, "[types:1292]Incorrect time value '-20070219173709.055870'")

tk.MustExec("drop table if exists t")
tk.MustExec("set @@sql_mode=''")
tk.MustExec("create table t(a float unsigned, b double unsigned)")
tk.MustExec("insert into t value(-1.1, -1.1), (-2.1, -2.1), (0, 0), (1.1, 1.1)")
tk.MustQuery("show warnings").
Check(testkit.Rows("Warning 1690 constant -1.1 overflows float", "Warning 1690 constant -1.1 overflows double",
"Warning 1690 constant -2.1 overflows float", "Warning 1690 constant -2.1 overflows double"))
tk.MustQuery("select * from t").Check(testkit.Rows("0 0", "0 0", "0 0", "1.1 1.1"))
}

func (s *testSuite) TestInsertAutoInc(c *C) {
Expand Down
9 changes: 7 additions & 2 deletions types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,14 @@ func ProduceFloatWithSpecifiedTp(f float64, target *FieldType, sc *stmtctx.State
// If no D is set, we will handle it like origin float whether M is set or not.
if target.Flen != UnspecifiedLength && target.Decimal != UnspecifiedLength {
f, err = TruncateFloat(f, target.Flen, target.Decimal)
err = sc.HandleOverflow(err, err)
if err = sc.HandleOverflow(err, err); err != nil {
return f, errors.Trace(err)
}
}
if mysql.HasUnsignedFlag(target.Flag) && f < 0 {
return 0, overflow(f, target.Tp)
}
return f, errors.Trace(err)
return f, nil
}

func (d *Datum) convertToString(sc *stmtctx.StatementContext, target *FieldType) (Datum, error) {
Expand Down

0 comments on commit b74990f

Please sign in to comment.