MySQL cast expressions. Simplified.
This commit is contained in:
parent
53dbcd9bfc
commit
c342f296ca
10 changed files with 103 additions and 81 deletions
|
|
@ -12,31 +12,40 @@ import (
|
|||
func TestCast(t *testing.T) {
|
||||
|
||||
query := SELECT(
|
||||
CAST(String("test")).AS("CHAR CHARACTER SET utf8").AS("result.AS1"),
|
||||
CAST(String("2011-02-02")).AS_DATE().AS("result.date"),
|
||||
CAST(String("14:06:10")).AS_TIME().AS("result.time"),
|
||||
CAST(String("2011-02-02 14:06:10")).AS_DATETIME().AS("result.datetime"),
|
||||
CAST(Int(150)).AS_CHAR().AS("result.char"),
|
||||
|
||||
CAST(Int(150)).AS_CHAR().AS("result.char1"),
|
||||
CAST(Int(150)).AS_CHAR(30).AS("result.char2"),
|
||||
|
||||
CAST(Int(5).SUB(Int(10))).AS_SIGNED().AS("result.signed"),
|
||||
CAST(Int(5).ADD(Int(10))).AS_UNSIGNED().AS("result.unsigned"),
|
||||
CAST(String("Some text")).AS_BINARY().AS("result.binary"),
|
||||
).FROM(AllTypes)
|
||||
|
||||
testutils.AssertStatementSql(t, query, `
|
||||
SELECT CAST(? AS DATE) AS "result.date",
|
||||
SELECT CAST(? AS CHAR CHARACTER SET utf8) AS "result.AS1",
|
||||
CAST(? AS DATE) AS "result.date",
|
||||
CAST(? AS TIME) AS "result.time",
|
||||
CAST(? AS DATETIME) AS "result.datetime",
|
||||
CAST(? AS CHAR) AS "result.char",
|
||||
CAST(? AS CHAR) AS "result.char1",
|
||||
CAST(? AS CHAR(30)) AS "result.char2",
|
||||
CAST((? - ?) AS SIGNED) AS "result.signed",
|
||||
CAST((? + ?) AS UNSIGNED) AS "result.unsigned",
|
||||
CAST(? AS BINARY) AS "result.binary"
|
||||
FROM test_sample.all_types;
|
||||
`, "2011-02-02", "14:06:10", "2011-02-02 14:06:10", int64(150), int64(5), int64(10), int64(5), int64(10), "Some text")
|
||||
`, "test", "2011-02-02", "14:06:10", "2011-02-02 14:06:10", int64(150), int64(150), int64(5),
|
||||
int64(10), int64(5), int64(10), "Some text")
|
||||
|
||||
type Result struct {
|
||||
As1 string
|
||||
Date time.Time
|
||||
Time time.Time
|
||||
DateTime time.Time
|
||||
Char string
|
||||
Char1 string
|
||||
Char2 string
|
||||
Signed int
|
||||
Unsigned int
|
||||
Binary string
|
||||
|
|
@ -49,10 +58,12 @@ FROM test_sample.all_types;
|
|||
assert.NilError(t, err)
|
||||
|
||||
assert.DeepEqual(t, dest, Result{
|
||||
As1: "test",
|
||||
Date: *testutils.Date("2011-02-02"),
|
||||
Time: *testutils.TimeWithoutTimeZone("14:06:10"),
|
||||
DateTime: *testutils.TimestampWithoutTimeZone("2011-02-02 14:06:10", 0),
|
||||
Char: "150",
|
||||
Char1: "150",
|
||||
Char2: "150",
|
||||
Signed: -5,
|
||||
Unsigned: 15,
|
||||
Binary: "Some text",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue