Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add end-to-end tests for timestamp insertion, and patch the conversion issue #1201

Merged
merged 4 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions e2etests/timestamp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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
fulghum marked this conversation as resolved.
Show resolved Hide resolved

import (
connector "database/sql"
"testing"
"time"

_ "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"
)

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)

// 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)
}
3 changes: 3 additions & 0 deletions sql/datetimetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down