From e0f7073d964077d6089b7702840b3c32bb0b5229 Mon Sep 17 00:00:00 2001 From: "Ryan P. Brewster" Date: Thu, 18 Aug 2022 14:31:46 -0400 Subject: [PATCH 1/4] Add timestamp tests --- e2etests/timestamp_test.go | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 e2etests/timestamp_test.go diff --git a/e2etests/timestamp_test.go b/e2etests/timestamp_test.go new file mode 100644 index 0000000000..b34d2fa4e2 --- /dev/null +++ b/e2etests/timestamp_test.go @@ -0,0 +1,43 @@ +package e2etests + +import ( + "testing" + "time" + + connector "database/sql" + + _ "github.com/go-sql-driver/mysql" + + sqle "github.com/dolthub/go-mysql-server" + "github.com/dolthub/go-mysql-server/memory" + "github.com/dolthub/go-mysql-server/server" + "github.com/dolthub/go-mysql-server/sql" + "github.com/dolthub/go-mysql-server/sql/analyzer" + "github.com/stretchr/testify/require" +) + +func Test_TimestampBindings_CanBeConverted(t *testing.T) { + provider := sql.NewDatabaseProvider( + memory.NewDatabase("mydb"), + ) + engine := sqle.New(analyzer.NewDefault(provider), &sqle.Config{ + IncludeRootAccount: true, + }) + cfg := server.Config{ + Protocol: "tcp", + Address: "localhost:3306", + } + srv, err := server.NewDefaultServer(cfg, engine) + require.NoError(t, err) + go srv.Start() + defer srv.Close() + + db, err := connector.Open("mysql", "root:@tcp(localhost:3306)/mydb") + require.NoError(t, err) + + _, err = db.Exec("CREATE TABLE mytable (t TIMESTAMP)") + require.NoError(t, err) + + _, err = db.Exec("INSERT INTO mytable (t) VALUES (?)", time.Now()) + require.NoError(t, err) +} From dd12685a7fae3be3f91f11394653bbfca95d16e4 Mon Sep 17 00:00:00 2001 From: "Ryan P. Brewster" Date: Thu, 18 Aug 2022 14:36:23 -0400 Subject: [PATCH 2/4] fix test --- e2etests/timestamp_test.go | 2 ++ sql/datetimetype.go | 3 +++ 2 files changed, 5 insertions(+) diff --git a/e2etests/timestamp_test.go b/e2etests/timestamp_test.go index b34d2fa4e2..cf6a086237 100644 --- a/e2etests/timestamp_test.go +++ b/e2etests/timestamp_test.go @@ -38,6 +38,8 @@ func Test_TimestampBindings_CanBeConverted(t *testing.T) { _, err = db.Exec("CREATE TABLE mytable (t TIMESTAMP)") require.NoError(t, err) + // All we are doing in this test is ensuring that writing a timestamp to the + // database does not throw an error. _, err = db.Exec("INSERT INTO mytable (t) VALUES (?)", time.Now()) require.NoError(t, err) } diff --git a/sql/datetimetype.go b/sql/datetimetype.go index 90b6911d1a..ad421ecb56 100644 --- a/sql/datetimetype.go +++ b/sql/datetimetype.go @@ -211,6 +211,9 @@ func ConvertToTime(v interface{}, t datetimeType) (time.Time, error) { func (t datetimeType) ConvertWithoutRangeCheck(v interface{}) (time.Time, error) { var res time.Time + if bs, ok := v.([]byte); ok { + v = string(bs) + } switch value := v.(type) { case string: if value == zeroDateStr || value == zeroTimestampDatetimeStr { From a3c77e3db35c1e1578a07056acfee085f80a9c0d Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Thu, 18 Aug 2022 14:46:11 -0700 Subject: [PATCH 3/4] Adding license header comments --- e2etests/timestamp_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/e2etests/timestamp_test.go b/e2etests/timestamp_test.go index cf6a086237..cb95bf39e1 100644 --- a/e2etests/timestamp_test.go +++ b/e2etests/timestamp_test.go @@ -1,3 +1,17 @@ +// Copyright 2022 Dolthub, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package e2etests import ( From 888146532dc7936ef61e6d6defbebac5f6e1f302 Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Thu, 18 Aug 2022 14:46:37 -0700 Subject: [PATCH 4/4] Reordering imports to keep format checker happy --- e2etests/timestamp_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/e2etests/timestamp_test.go b/e2etests/timestamp_test.go index cb95bf39e1..9184a3d9bf 100644 --- a/e2etests/timestamp_test.go +++ b/e2etests/timestamp_test.go @@ -15,19 +15,18 @@ package e2etests import ( + connector "database/sql" "testing" "time" - connector "database/sql" - _ "github.com/go-sql-driver/mysql" + "github.com/stretchr/testify/require" sqle "github.com/dolthub/go-mysql-server" "github.com/dolthub/go-mysql-server/memory" "github.com/dolthub/go-mysql-server/server" "github.com/dolthub/go-mysql-server/sql" "github.com/dolthub/go-mysql-server/sql/analyzer" - "github.com/stretchr/testify/require" ) func Test_TimestampBindings_CanBeConverted(t *testing.T) {