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

Adding test for preparing time.Time types #2423

Merged
merged 19 commits into from
Mar 29, 2024
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
2 changes: 1 addition & 1 deletion engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func (e *Engine) bindExecuteQueryNode(ctx *sql.Context, query string, eq *plan.E
}
bindings[fmt.Sprintf("v%d", i+1)], err = sqltypes.BuildBindVariable(val)
if err != nil {
return nil, nil
return nil, err
}
} else {
bindings[fmt.Sprintf("v%d", i)] = sqltypes.StringBindVariable(name.String())
Expand Down
115 changes: 115 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -6968,6 +6968,121 @@ var PreparedScriptTests = []ScriptTest{
},
},
},
{
Name: "prepare with time type binding",
SetUpScript: []string{
"create table t (d date, dt datetime, t time, ts timestamp);",
"set @d = date('2001-02-03');",
"set @dt = datetime('2001-02-03 12:34:56');",
"set @t = time('12:34:56');",
"set @ts = timestamp('2001-02-03 12:34:56');",
"prepare s from 'select ?';",
"prepare sd from 'insert into t(d) values(?)';",
"prepare sdt from 'insert into t(dt) values(?)';",
"prepare st from 'insert into t(t) values(?)';",
"prepare sts from 'insert into t(ts) values(?)';",
},
Assertions: []ScriptTestAssertion{
{
Query: "execute s using @d;",
Expected: []sql.Row{
{"2001-02-03"},
},
},
{
Query: "execute s using @dt;",
Expected: []sql.Row{
{"2001-02-03 12:34:56 +0000 UTC"},
},
},
{
// types.Timespan not supported as bindvar
Skip: true,
Query: "execute s using @t;",
Expected: []sql.Row{
{"12:34:56"},
},
},
{
Query: "execute s using @ts;",
Expected: []sql.Row{
{"2001-02-03 12:34:56 +0000 UTC"},
},
},
{
SkipResultCheckOnServerEngine: true,
Query: "execute sd using @d;",
Expected: []sql.Row{
{types.NewOkResult(1)},
},
},
{
SkipResultCheckOnServerEngine: true,
Query: "execute sdt using @dt;",
Expected: []sql.Row{
{types.NewOkResult(1)},
},
},
{
// types.Timespan not supported as bindvar
Skip: true,
SkipResultCheckOnServerEngine: true,
Query: "execute st using @t;",
Expected: []sql.Row{
{types.NewOkResult(1)},
},
},
{
SkipResultCheckOnServerEngine: true,
Query: "execute sts using @ts;",
Expected: []sql.Row{
{types.NewOkResult(1)},
},
},
{
// TODO: should also select t when we fix that
Query: "select d, dt, ts from t",
Expected: []sql.Row{
{time.Date(2001, time.February, 3, 0, 0, 0, 0, time.UTC), nil, nil},
{nil, time.Date(2001, time.February, 3, 12, 34, 56, 0, time.UTC), nil},
{nil, nil, time.Date(2001, time.February, 3, 12, 34, 56, 0, time.UTC)},
},
},
},
},
{
Name: "prepare with decimal type binding",
SetUpScript: []string{
"create table t (d decimal);",
"set @d = cast(123.45 as Decimal(5,2));",
"prepare s from 'select ?';",
"prepare sd from 'insert into t values(?)';",
},
Assertions: []ScriptTestAssertion{
{
Skip: true,
Query: "execute s using @d;",
Expected: []sql.Row{
{"123.45"},
},
},
{
Skip: true,
SkipResultCheckOnServerEngine: true,
Query: "execute sd using @d;",
Expected: []sql.Row{
{"123.45"},
},
},
{
Skip: true,
Query: "select * from t",
Expected: []sql.Row{
{"123.45"},
},
},
},
},
{
Name: "prepare insert",
SetUpScript: []string{
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
github.com/dolthub/vitess v0.0.0-20240325235243-65f4774a8706
github.com/dolthub/vitess v0.0.0-20240329223145-3e53a7bee1da
github.com/go-kit/kit v0.10.0
github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d
github.com/gocraft/dbr/v2 v2.7.2
Expand All @@ -15,7 +15,7 @@ require (
github.com/lestrrat-go/strftime v1.0.4
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0
github.com/shopspring/decimal v1.2.0
github.com/shopspring/decimal v1.3.1
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.8.2
go.opentelemetry.io/otel v1.7.0
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTE
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI=
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE=
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
github.com/dolthub/vitess v0.0.0-20240325235243-65f4774a8706 h1:nlmIlkMuCXzp/h5hoKh4mWW5ePqRlhwlJJQRLMtN3B4=
github.com/dolthub/vitess v0.0.0-20240325235243-65f4774a8706/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dolthub/vitess v0.0.0-20240329220943-04e0d9e0dcf3 h1:gzlMfGaN0vj+M2Tkv9pREGDMOpBCNFt8C4gWKSx2ew4=
github.com/dolthub/vitess v0.0.0-20240329220943-04e0d9e0dcf3/go.mod h1:Xy89nzEyIwlMCiFWOJPmlnORpDFz5wFgEdYGfUwbIQ0=
github.com/dolthub/vitess v0.0.0-20240329223145-3e53a7bee1da h1:EZJqfIEHLV/eRtlxMhep2Jj/JpHSnZBiKFFLFbnmsSo=
github.com/dolthub/vitess v0.0.0-20240329223145-3e53a7bee1da/go.mod h1:Xy89nzEyIwlMCiFWOJPmlnORpDFz5wFgEdYGfUwbIQ0=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
Expand Down Expand Up @@ -268,8 +270,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
Expand Down
Loading