Example #1
0
File: tidb.go Project: 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
}