Skip to content

Commit b207193

Browse files
committed
update and add more tests
1 parent abfb060 commit b207193

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

enginetest/queries/function_queries.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,4 +2105,12 @@ var FunctionQueryTests = []QueryTest{
21052105
Query: "select date('0000-01-01')",
21062106
Expected: []sql.Row{{"0000-01-01"}},
21072107
},
2108+
{
2109+
Query: "select date('0000-00-00')",
2110+
Expected: []sql.Row{{"0000-00-00"}},
2111+
},
2112+
{
2113+
Query: "select date(0)",
2114+
Expected: []sql.Row{{"0000-00-00"}},
2115+
},
21082116
}

enginetest/queries/insert_queries.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,25 @@ var InsertScripts = []ScriptTest{
23492349
},
23502350
},
23512351
},
2352+
{
2353+
Name: "inserting zero date",
2354+
SetUpScript: []string{
2355+
"create table t(d date)",
2356+
"insert into t values ('0000-00-00')",
2357+
"create table t2(d datetime)",
2358+
"insert into t2 values ('0000-00-00')",
2359+
},
2360+
Assertions: []ScriptTestAssertion{
2361+
{
2362+
Query: "select * from t",
2363+
Expected: []sql.Row{{types.ZeroTime}},
2364+
},
2365+
{
2366+
Query: "select * from t2",
2367+
Expected: []sql.Row{{types.ZeroTime}},
2368+
},
2369+
},
2370+
},
23522371
}
23532372

23542373
var InsertDuplicateKeyKeyless = []ScriptTest{

sql/expression/function/time.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,14 @@ func (d *Date) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
13001300
return nil
13011301
}
13021302

1303-
return v.(time.Time).Format("2006-01-02")
1303+
date, ok := v.(time.Time)
1304+
if !ok {
1305+
return nil
1306+
}
1307+
if date.Equal(types.ZeroTime) {
1308+
return types.ZeroDateStr
1309+
}
1310+
return date.Format("2006-01-02")
13041311
})
13051312
}
13061313

sql/rowexec/update_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
package rowexec
1616

1717
import (
18-
"testing"
19-
"time"
20-
2118
"github.com/dolthub/vitess/go/sqltypes"
2219
"github.com/stretchr/testify/require"
20+
"testing"
2321

2422
"github.com/dolthub/go-mysql-server/memory"
2523
"github.com/dolthub/go-mysql-server/sql"
@@ -55,7 +53,7 @@ func TestUpdateIgnoreConversions(t *testing.T) {
5553
colType: types.Datetime,
5654
value: "dadasd",
5755
valueType: types.Text,
58-
expected: time.Unix(-62167219200, 0).UTC(),
56+
expected: types.ZeroTime,
5957
},
6058
{
6159
name: "inserting a negative into an unsigned int results in 0",

0 commit comments

Comments
 (0)