Skip to content

Commit

Permalink
session: cleanup some duplicated code (pingcap#19980)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackysp authored Sep 15, 2020
1 parent 3c04ec4 commit fa6baa9
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,32 +1077,18 @@ func (s *session) Execute(ctx context.Context, sql string) (recordSets []sqlexec
logutil.Eventf(ctx, "execute: %s", sql)
}

charsetInfo, collation := s.sessionVars.GetCharsetInfo()
parseStartTime := time.Now()
stmtNodes, warns, err := s.ParseSQL(ctx, sql, charsetInfo, collation)
stmtNodes, err := s.Parse(ctx, sql)
if err != nil {
s.rollbackOnError(ctx)

// Only print log message when this SQL is from the user.
// Mute the warning for internal SQLs.
if !s.sessionVars.InRestrictedSQL {
logutil.Logger(ctx).Warn("parse SQL failed", zap.Error(err), zap.String("SQL", sql))
}
return nil, util.SyntaxError(err)
return nil, err
}
if len(stmtNodes) != 1 {
return nil, errors.New("Execute() API doesn't support multiple statements any more")
}
durParse := time.Since(parseStartTime)
s.GetSessionVars().DurationParse = durParse

rs, err := s.ExecuteStmt(ctx, stmtNodes[0])
if err != nil {
s.sessionVars.StmtCtx.AppendError(err)
}
for _, warn := range warns {
s.sessionVars.StmtCtx.AppendWarning(util.SyntaxWarn(warn))
}
if rs == nil {
return nil, err
}
Expand Down

0 comments on commit fa6baa9

Please sign in to comment.