示例#1
0
文件: tidb.go 项目: pingcap/tidb
// 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
}
示例#2
0
文件: eval.go 项目: pingcap/tidb
// 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
}