Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#46620
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
wshwsh12 authored and ti-chi-bot committed Sep 6, 2023
1 parent 3652a93 commit 85713bd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
46 changes: 46 additions & 0 deletions expression/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7946,3 +7946,49 @@ func TestIfFunctionWithNull(t *testing.T) {
tk.MustQuery("select min(if(apply_to_now_days <= 30,loan,null)) as min, max(if(apply_to_now_days <= 720,loan,null)) as max from (select loan, datediff(from_unixtime(unix_timestamp('2023-05-18 18:43:43') + 18000), from_unixtime(apply_time/1000 + 18000)) as apply_to_now_days from orders) t1;").Sort().Check(
testkit.Rows("20000 35100"))
}
<<<<<<< HEAD
=======

func TestIssue41733AndIssue45410(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("create database testIssue41733")
defer tk.MustExec("drop database testIssue41733")
tk.MustExec("use testIssue41733")

tk.MustExec("create table t_tiny (c0 TINYINT UNSIGNED)")
tk.MustExec("INSERT IGNORE INTO t_tiny(c0) VALUES (1E9)")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1"))
tk.MustQuery("select * from t_tiny;").Check(testkit.Rows("255"))

tk.MustExec("create table t_small (c0 SMALLINT UNSIGNED)")
tk.MustExec("INSERT IGNORE INTO t_small(c0) VALUES (1E9)")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1"))
tk.MustQuery("select * from t_small;").Check(testkit.Rows("65535"))

tk.MustExec("create table t_medium (c0 MEDIUMINT UNSIGNED)")
tk.MustExec("INSERT IGNORE INTO t_medium(c0) VALUES (1E9)")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1"))
tk.MustQuery("select * from t_medium;").Check(testkit.Rows("16777215"))

tk.MustExec("create table t_int (c0 INT UNSIGNED)")
tk.MustExec("INSERT IGNORE INTO t_int(c0) VALUES (1E20)")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1"))
tk.MustQuery("select * from t_int;").Check(testkit.Rows("4294967295"))

tk.MustExec("create table t_big (c0 BIGINT UNSIGNED)")
tk.MustExec("INSERT IGNORE INTO t_big(c0) VALUES (1E20)")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1"))
tk.MustQuery("select * from t_big;").Check(testkit.Rows("18446744073709551615"))

// Issue 45410
tk.MustExec("create database testIssue45410")
defer tk.MustExec("drop database testIssue45410")
tk.MustExec("use testIssue45410")

tk.MustExec("DROP TABLE IF EXISTS t1;")
tk.MustExec("CREATE TABLE t1 (c1 TINYINT(1) UNSIGNED NOT NULL );")
tk.MustExec("INSERT INTO t1 VALUES (0);")
tk.MustQuery("SELECT c1>=CAST('-787360724' AS TIME) FROM t1;").Check(testkit.Rows("1"))
}
>>>>>>> ca696229234 (expression: fix wrong result for unsigned non-const int cmp const duration (#46620))
7 changes: 4 additions & 3 deletions types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,9 +1214,10 @@ func (d *Datum) convertToUint(sc *stmtctx.StatementContext, target *FieldType) (
case KindMysqlDuration:
dec := d.GetMysqlDuration().ToNumber()
err = dec.Round(dec, 0, ModeHalfUp)
ival, err1 := dec.ToInt()
if err1 == nil {
val, err = ConvertIntToUint(sc, ival, upperBound, tp)
var err1 error
val, err1 = ConvertDecimalToUint(sc, dec, upperBound, tp)
if err == nil {
err = err1
}
case KindMysqlDecimal:
val, err = ConvertDecimalToUint(sc, d.GetMysqlDecimal(), upperBound, tp)
Expand Down

0 comments on commit 85713bd

Please sign in to comment.