• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang variable.StatementContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/pingcap/tidb/sessionctx/variable.StatementContext的典型用法代码示例。如果您正苦于以下问题:Golang StatementContext类的具体用法?Golang StatementContext怎么用?Golang StatementContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了StatementContext类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: compareForTest

func compareForTest(a, b interface{}) (int, error) {
	sc := new(variable.StatementContext)
	sc.IgnoreTruncate = true
	aDatum := NewDatum(a)
	bDatum := NewDatum(b)
	return aDatum.CompareDatum(sc, bDatum)
}
开发者ID:pingcap,项目名称:tidb,代码行数:7,代码来源:compare_test.go


示例2: TestCompareDatum

func (s *testCompareSuite) TestCompareDatum(c *C) {
	defer testleak.AfterTest(c)()
	cmpTbl := []struct {
		lhs Datum
		rhs Datum
		ret int // 0, 1, -1
	}{
		{MaxValueDatum(), NewDatum("00:00:00"), 1},
		{MinNotNullDatum(), NewDatum("00:00:00"), -1},
		{Datum{}, NewDatum("00:00:00"), -1},
		{Datum{}, Datum{}, 0},
		{MinNotNullDatum(), MinNotNullDatum(), 0},
		{MaxValueDatum(), MaxValueDatum(), 0},
		{Datum{}, MinNotNullDatum(), -1},
		{MinNotNullDatum(), MaxValueDatum(), -1},
	}
	sc := new(variable.StatementContext)
	sc.IgnoreTruncate = true
	for i, t := range cmpTbl {
		comment := Commentf("%d %v %v", i, t.lhs, t.rhs)
		ret, err := t.lhs.CompareDatum(sc, t.rhs)
		c.Assert(err, IsNil)
		c.Assert(ret, Equals, t.ret, comment)

		ret, err = t.rhs.CompareDatum(sc, t.lhs)
		c.Assert(err, IsNil)
		c.Assert(ret, Equals, -t.ret, comment)
	}
}
开发者ID:pingcap,项目名称:tidb,代码行数:29,代码来源:compare_test.go


示例3: TestToFloat32

func (ts *testTypeConvertSuite) TestToFloat32(c *C) {
	ft := NewFieldType(mysql.TypeFloat)
	var datum = NewFloat64Datum(281.37)
	sc := new(variable.StatementContext)
	sc.IgnoreTruncate = true
	converted, err := datum.ConvertTo(sc, ft)
	c.Assert(err, IsNil)
	c.Assert(converted.Kind(), Equals, KindFloat32)
	c.Assert(converted.GetFloat32(), Equals, float32(281.37))

	datum.SetString("281.37")
	converted, err = datum.ConvertTo(sc, ft)
	c.Assert(err, IsNil)
	c.Assert(converted.Kind(), Equals, KindFloat32)
	c.Assert(converted.GetFloat32(), Equals, float32(281.37))

	ft = NewFieldType(mysql.TypeDouble)
	datum = NewFloat32Datum(281.37)
	converted, err = datum.ConvertTo(sc, ft)
	c.Assert(err, IsNil)
	c.Assert(converted.Kind(), Equals, KindFloat64)
	// Convert to float32 and convert back to float64, we will get a different value.
	c.Assert(converted.GetFloat64(), Not(Equals), 281.37)
	c.Assert(converted.GetFloat64(), Equals, datum.GetFloat64())
}
开发者ID:pingcap,项目名称:tidb,代码行数:25,代码来源:datum_test.go


示例4: TestToBool

func (ts *testDatumSuite) TestToBool(c *C) {
	testDatumToBool(c, int(0), 0)
	testDatumToBool(c, int64(0), 0)
	testDatumToBool(c, uint64(0), 0)
	testDatumToBool(c, float32(0.1), 0)
	testDatumToBool(c, float64(0.1), 0)
	testDatumToBool(c, "", 0)
	testDatumToBool(c, "0.1", 0)
	testDatumToBool(c, []byte{}, 0)
	testDatumToBool(c, []byte("0.1"), 0)
	testDatumToBool(c, Hex{Value: 0}, 0)
	testDatumToBool(c, Bit{Value: 0, Width: 8}, 0)
	testDatumToBool(c, Enum{Name: "a", Value: 1}, 1)
	testDatumToBool(c, Set{Name: "a", Value: 1}, 1)

	t, err := ParseTime("2011-11-10 11:11:11.999999", mysql.TypeTimestamp, 6)
	c.Assert(err, IsNil)
	testDatumToBool(c, t, 1)

	td, err := ParseDuration("11:11:11.999999", 6)
	c.Assert(err, IsNil)
	testDatumToBool(c, td, 1)

	ft := NewFieldType(mysql.TypeNewDecimal)
	ft.Decimal = 5
	v, err := Convert(0.1415926, ft)
	c.Assert(err, IsNil)
	testDatumToBool(c, v, 0)
	d := NewDatum(&invalidMockType{})
	sc := new(variable.StatementContext)
	sc.IgnoreTruncate = true
	_, err = d.ToBool(sc)
	c.Assert(err, NotNil)
}
开发者ID:pingcap,项目名称:tidb,代码行数:34,代码来源:datum_test.go


示例5: testEqualDatums

func testEqualDatums(c *C, a []interface{}, b []interface{}, same bool) {
	sc := new(variable.StatementContext)
	sc.IgnoreTruncate = true
	res, err := EqualDatums(sc, MakeDatums(a), MakeDatums(b))
	c.Assert(err, IsNil)
	c.Assert(res, Equals, same, Commentf("a: %v, b: %v", a, b))
}
开发者ID:pingcap,项目名称:tidb,代码行数:7,代码来源:datum_test.go


示例6: testDatumToInt64

func testDatumToInt64(c *C, val interface{}, expect int64) {
	d := NewDatum(val)
	sc := new(variable.StatementContext)
	sc.IgnoreTruncate = true
	b, err := d.ToInt64(sc)
	c.Assert(err, IsNil)
	c.Assert(b, Equals, expect)
}
开发者ID:pingcap,项目名称:tidb,代码行数:8,代码来源:datum_test.go


示例7: testDatumToBool

func testDatumToBool(c *C, in interface{}, res int) {
	datum := NewDatum(in)
	res64 := int64(res)
	sc := new(variable.StatementContext)
	sc.IgnoreTruncate = true
	b, err := datum.ToBool(sc)
	c.Assert(err, IsNil)
	c.Assert(b, Equals, res64)
}
开发者ID:pingcap,项目名称:tidb,代码行数:9,代码来源:datum_test.go


示例8: handleTruncateError

func handleTruncateError(sc *variable.StatementContext) error {
	if sc.IgnoreTruncate {
		return nil
	}
	if !sc.TruncateAsWarning {
		return ErrTruncated
	}
	sc.AppendWarning(ErrTruncated)
	return nil
}
开发者ID:pingcap,项目名称:tidb,代码行数:10,代码来源:datum.go


示例9: testStrToFloat

func testStrToFloat(c *C, str string, expect float64, truncateAsErr bool, expectErr error) {
	sc := new(variable.StatementContext)
	sc.IgnoreTruncate = !truncateAsErr
	val, err := StrToFloat(sc, str)
	if expectErr != nil {
		c.Assert(terror.ErrorEqual(err, expectErr), IsTrue)
	} else {
		c.Assert(err, IsNil)
		c.Assert(val, Equals, expect)
	}
}
开发者ID:pingcap,项目名称:tidb,代码行数:11,代码来源:convert_test.go


示例10: accept

func accept(c *C, tp byte, value interface{}, unsigned bool, expected string) {
	ft := NewFieldType(tp)
	if unsigned {
		ft.Flag |= mysql.UnsignedFlag
	}
	d := NewDatum(value)
	sc := new(variable.StatementContext)
	sc.IgnoreTruncate = true
	casted, err := d.ConvertTo(sc, ft)
	c.Assert(err, IsNil, Commentf("%v", ft))
	if casted.IsNull() {
		c.Assert(expected, Equals, "<nil>")
	} else {
		str, err := casted.ToString()
		c.Assert(err, IsNil)
		c.Assert(str, Equals, expected)
	}
}
开发者ID:pingcap,项目名称:tidb,代码行数:18,代码来源:convert_test.go


示例11: TestCoerceDatum

func (ts *testDatumSuite) TestCoerceDatum(c *C) {
	testCases := []struct {
		a    Datum
		b    Datum
		kind byte
	}{
		{NewIntDatum(1), NewIntDatum(1), KindInt64},
		{NewUintDatum(1), NewDecimalDatum(NewDecFromInt(1)), KindMysqlDecimal},
		{NewFloat64Datum(1), NewDecimalDatum(NewDecFromInt(1)), KindFloat64},
		{NewFloat64Datum(1), NewFloat64Datum(1), KindFloat64},
	}
	sc := new(variable.StatementContext)
	sc.IgnoreTruncate = true
	for _, ca := range testCases {
		x, y, err := CoerceDatum(sc, ca.a, ca.b)
		c.Check(err, IsNil)
		c.Check(x.Kind(), Equals, y.Kind())
		c.Check(x.Kind(), Equals, ca.kind)
	}
}
开发者ID:pingcap,项目名称:tidb,代码行数:20,代码来源:datum_test.go


示例12: resetStmtCtx

// Before every execution, we must clear statement context.
func resetStmtCtx(ctx context.Context, s ast.StmtNode) {
	sessVars := ctx.GetSessionVars()
	sc := new(variable.StatementContext)
	switch s.(type) {
	case *ast.UpdateStmt, *ast.InsertStmt, *ast.DeleteStmt:
		sc.IgnoreTruncate = false
		sc.TruncateAsWarning = !sessVars.StrictSQLMode
		if _, ok := s.(*ast.UpdateStmt); ok {
			sc.InUpdateStmt = true
		}
	default:
		sc.IgnoreTruncate = true
		if show, ok := s.(*ast.ShowStmt); ok {
			if show.Tp == ast.ShowWarnings {
				sc.SetWarnings(sessVars.StmtCtx.GetWarnings())
			}
		}
	}
	sessVars.StmtCtx = sc
}
开发者ID:pingcap,项目名称:tidb,代码行数:21,代码来源:tidb.go


示例13: FlagsToStatementContext

// FlagsToStatementContext creates a StatementContext from a `tipb.SelectRequest.Flags`.
func FlagsToStatementContext(flags uint64) *variable.StatementContext {
	sc := new(variable.StatementContext)
	sc.IgnoreTruncate = (flags & FlagIgnoreTruncate) > 0
	sc.TruncateAsWarning = (flags & FlagTruncateAsWarning) > 0
	return sc
}
开发者ID:pingcap,项目名称:tidb,代码行数:7,代码来源:eval.go


示例14: TestBitOps

func (ts *testDatumSuite) TestBitOps(c *C) {
	testCases := []struct {
		a      Datum
		b      Datum
		bitop  string // bitwise operator
		result Datum
	}{
		// And
		{NewIntDatum(341), NewIntDatum(170), "And", NewIntDatum(0)},
		{NewIntDatum(341), NewUintDatum(170), "And", NewUintDatum(0)},
		{NewUintDatum(341), NewUintDatum(170), "And", NewUintDatum(0)},
		{NewIntDatum(-1), NewFloat64Datum(-2.5), "And", NewUintDatum(18446744073709551613)},
		{NewFloat64Datum(-1.4), NewFloat64Datum(-2.4), "And", NewUintDatum(18446744073709551614)},
		{NewFloat64Datum(-1.5), NewFloat64Datum(-2.5), "And", NewUintDatum(18446744073709551612)},
		// Or
		{NewIntDatum(341), NewIntDatum(170), "Or", NewIntDatum(511)},
		{NewIntDatum(341), NewUintDatum(170), "Or", NewUintDatum(511)},
		{NewUintDatum(341), NewUintDatum(170), "Or", NewUintDatum(511)},
		{NewIntDatum(-1), NewFloat64Datum(-2.5), "Or", NewUintDatum(18446744073709551615)},
		{NewFloat64Datum(-1.4), NewFloat64Datum(-2.4), "Or", NewUintDatum(18446744073709551615)},
		{NewFloat64Datum(-1.5), NewFloat64Datum(-2.5), "Or", NewUintDatum(18446744073709551615)},
		// Xor
		{NewIntDatum(341), NewIntDatum(170), "Xor", NewUintDatum(511)},
		{NewIntDatum(341), NewUintDatum(170), "Xor", NewUintDatum(511)},
		{NewUintDatum(341), NewUintDatum(170), "Xor", NewUintDatum(511)},
		{NewIntDatum(-1), NewFloat64Datum(-2.5), "Xor", NewUintDatum(2)},
		{NewFloat64Datum(-1.4), NewFloat64Datum(-2.4), "Xor", NewUintDatum(1)},
		{NewFloat64Datum(-1.5), NewFloat64Datum(-2.5), "Xor", NewUintDatum(3)},
		// Not
		{NewIntDatum(-1), Datum{}, "Not", NewUintDatum(0)},
		{NewIntDatum(1), Datum{}, "Not", NewUintDatum(18446744073709551614)},
		{NewFloat64Datum(-0.5), Datum{}, "Not", NewUintDatum(0)},
		{NewFloat64Datum(-0.4), Datum{}, "Not", NewUintDatum(18446744073709551615)},
		{NewUintDatum(18446744073709551615), Datum{}, "Not", NewUintDatum(0)},
		// LeftShift
		{NewIntDatum(-1), NewIntDatum(1), "LeftShift", NewUintDatum(18446744073709551614)},
		{NewIntDatum(-1), NewIntDatum(-1), "LeftShift", NewUintDatum(0)},
		{NewIntDatum(1), NewIntDatum(10), "LeftShift", NewUintDatum(1024)},
		{NewFloat64Datum(-1.4), NewFloat64Datum(2.4), "LeftShift", NewUintDatum(18446744073709551612)},
		{NewFloat64Datum(-1.4), NewFloat64Datum(2.5), "LeftShift", NewUintDatum(18446744073709551608)},
		// RightShift
		{NewUintDatum(18446744073709551614), NewIntDatum(1), "RightShift", NewUintDatum(9223372036854775807)},
		{NewIntDatum(-1), NewIntDatum(-1), "RightShift", NewUintDatum(0)},
		{NewIntDatum(1024), NewIntDatum(10), "RightShift", NewUintDatum(1)},
		{NewFloat64Datum(1024), NewFloat64Datum(10.4), "RightShift", NewUintDatum(1)},
		{NewFloat64Datum(1024), NewFloat64Datum(10.5), "RightShift", NewUintDatum(0)},
	}

	for _, ca := range testCases {
		var (
			result Datum
			err    error
		)
		sc := new(variable.StatementContext)
		sc.IgnoreTruncate = true
		switch ca.bitop {
		case "And":
			result, err = ComputeBitAnd(sc, ca.a, ca.b)
		case "Or":
			result, err = ComputeBitOr(sc, ca.a, ca.b)
		case "Not":
			result, err = ComputeBitNeg(sc, ca.a)
		case "Xor":
			result, err = ComputeBitXor(sc, ca.a, ca.b)
		case "LeftShift":
			result, err = ComputeLeftShift(sc, ca.a, ca.b)
		case "RightShift":
			result, err = ComputeRightShift(sc, ca.a, ca.b)
		}
		c.Check(err, Equals, nil)
		c.Assert(result.GetUint64(), Equals, ca.result.GetUint64())
	}
}
开发者ID:pingcap,项目名称:tidb,代码行数:73,代码来源:datum_test.go



注:本文中的github.com/pingcap/tidb/sessionctx/variable.StatementContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang stmt.Statement类代码示例发布时间:2022-05-28
下一篇:
Golang variable.RegisterStatistics函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap