Skip to content

Commit

Permalink
sql: fix recently introduced minor bug around PREPARE
Browse files Browse the repository at this point in the history
In just merged 4a3e787, we had a minor
bug that in case `addPreparedStmt` call fails, we don't restore the
original placeholders, which can then lead to panics.

Release note: None
  • Loading branch information
yuzefovich committed Aug 9, 2023
1 parent 01a6aab commit 2042afe
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/sql/conn_executor_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,16 +903,18 @@ func (ex *connExecutor) execStmtInOpenState(
// PREPARE statement itself.
oldPlaceholders := p.extendedEvalCtx.Placeholders
p.extendedEvalCtx.Placeholders = nil
defer func() {
// The call to addPreparedStmt changed the planner stmt to the
// statement being prepared. Set it back to the PREPARE statement,
// so that it's logged correctly.
p.stmt = stmt
p.extendedEvalCtx.Placeholders = oldPlaceholders
}()
if _, err := ex.addPreparedStmt(
ctx, name, prepStmt, typeHints, rawTypeHints, PreparedStatementOriginSQL,
); err != nil {
return makeErrEvent(err)
}
// The call to addPreparedStmt changed the planner stmt to the statement
// being prepared. Set it back to the PREPARE statement, so that it's
// logged correctly.
p.stmt = stmt
p.extendedEvalCtx.Placeholders = oldPlaceholders
return nil, nil, nil
}

Expand Down

0 comments on commit 2042afe

Please sign in to comment.