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

bugfix: literalTime use t.UTC() , This behavior is different from the original sql.DB #106

Merged
merged 3 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion sql_dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ func (d *sqlDialect) literalTime(b sb.SQLBuilder, t time.Time) {
d.placeHolderSQL(b, t)
return
}
d.Literal(b, t.UTC().Format(d.dialectOptions.TimeFormat))
d.Literal(b, t.Format(d.dialectOptions.TimeFormat))
}

// Generates SQL for a Float Value
Expand Down
38 changes: 23 additions & 15 deletions sql_dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package goqu
import (
"database/sql/driver"
"fmt"
"github.com/stretchr/testify/require"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File is not goimports-ed (from goimports)

Suggested change
"github.com/stretchr/testify/require"

"regexp"
"testing"
"time"
Expand Down Expand Up @@ -1175,28 +1176,35 @@ func (dts *dialectTestSuite) TestLiteral_BoolTypes() {
func (dts *dialectTestSuite) TestLiteral_TimeTypes() {
t := dts.T()
d := sqlDialect{DefaultDialectOptions()}
now := time.Now().UTC()
var nt *time.Time
asiaShanghai, err := time.LoadLocation("Asia/Shanghai")
require.NoError(t, err)
testDatas := []time.Time{
time.Now().UTC(),
time.Now().In(asiaShanghai),
}

b := sb.NewSQLBuilder(false)
d.Literal(b.Clear(), now)
dts.assertNotPreparedSQL(t, b, "'"+now.Format(time.RFC3339Nano)+"'")
for _, now := range testDatas {
b := sb.NewSQLBuilder(false)
d.Literal(b.Clear(), now)
dts.assertNotPreparedSQL(t, b, "'"+now.Format(time.RFC3339Nano)+"'")

d.Literal(b.Clear(), &now)
dts.assertNotPreparedSQL(t, b, "'"+now.Format(time.RFC3339Nano)+"'")
d.Literal(b.Clear(), &now)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a reference for the variable on range scope now (from scopelint)

dts.assertNotPreparedSQL(t, b, "'"+now.Format(time.RFC3339Nano)+"'")

d.Literal(b.Clear(), nt)
dts.assertNotPreparedSQL(t, b, "NULL")
d.Literal(b.Clear(), nt)
dts.assertNotPreparedSQL(t, b, "NULL")

b = sb.NewSQLBuilder(true)
d.Literal(b.Clear(), now)
dts.assertPreparedSQL(t, b, "?", []interface{}{now})
b = sb.NewSQLBuilder(true)
d.Literal(b.Clear(), now)
dts.assertPreparedSQL(t, b, "?", []interface{}{now})

d.Literal(b.Clear(), &now)
dts.assertPreparedSQL(t, b, "?", []interface{}{now})
d.Literal(b.Clear(), &now)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a reference for the variable on range scope now (from scopelint)

dts.assertPreparedSQL(t, b, "?", []interface{}{now})

d.Literal(b.Clear(), nt)
dts.assertPreparedSQL(t, b, "NULL", emptyArgs)
d.Literal(b.Clear(), nt)
dts.assertPreparedSQL(t, b, "NULL", emptyArgs)
}
}

func (dts *dialectTestSuite) TestLiteral_NilTypes() {
Expand Down