session: add parser failed error to sessionVars.StmtCtx (#34311)
close pingcap/tidb#34276
This commit is contained in:
@ -141,6 +141,11 @@ func TestShowErrors(t *testing.T) {
|
||||
_, _ = tk.Exec(testSQL)
|
||||
|
||||
tk.MustQuery("show errors").Check(testkit.RowsWithSep("|", "Error|1050|Table 'test.show_errors' already exists"))
|
||||
|
||||
// eliminate previous errors
|
||||
tk.MustExec("select 1")
|
||||
_, _ = tk.Exec("create invalid")
|
||||
tk.MustQuery("show errors").Check(testkit.RowsWithSep("|", "Error|1064|You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 14 near \"invalid\" "))
|
||||
}
|
||||
|
||||
func TestShowWarningsForExprPushdown(t *testing.T) {
|
||||
|
||||
@ -2057,9 +2057,10 @@ func (cli *testServerClient) runTestInfoschemaClientErrors(t *testing.T) {
|
||||
errCode: 1068, // multiple pkeys
|
||||
},
|
||||
{
|
||||
stmt: "gibberish",
|
||||
incrementErrors: true,
|
||||
errCode: 1064, // parse error
|
||||
stmt: "gibberish",
|
||||
incrementWarnings: true,
|
||||
incrementErrors: true,
|
||||
errCode: 1064, // parse error
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -1503,6 +1503,7 @@ func (s *session) Parse(ctx context.Context, sql string) ([]ast.StmtNode, error)
|
||||
stmts, warns, err := s.ParseSQL(ctx, sql, s.sessionVars.GetParseParams()...)
|
||||
if err != nil {
|
||||
s.rollbackOnError(ctx)
|
||||
err = util.SyntaxError(err)
|
||||
|
||||
// Only print log message when this SQL is from the user.
|
||||
// Mute the warning for internal SQLs.
|
||||
@ -1512,8 +1513,9 @@ func (s *session) Parse(ctx context.Context, sql string) ([]ast.StmtNode, error)
|
||||
} else {
|
||||
logutil.Logger(ctx).Warn("parse SQL failed", zap.Error(err), zap.String("SQL", sql))
|
||||
}
|
||||
s.sessionVars.StmtCtx.AppendError(err)
|
||||
}
|
||||
return nil, util.SyntaxError(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
durParse := time.Since(parseStartTime)
|
||||
|
||||
Reference in New Issue
Block a user