Skip to content

Commit

Permalink
session: add parser failed error to sessionVars.StmtCtx (pingcap#34311)
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 authored Apr 29, 2022
1 parent 090feab commit d42cf6a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}

Expand Down
4 changes: 3 additions & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit d42cf6a

Please sign in to comment.