Skip to content

Commit 2042afe

Browse files
committed
sql: fix recently introduced minor bug around PREPARE
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
1 parent 01a6aab commit 2042afe

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pkg/sql/conn_executor_exec.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -903,16 +903,18 @@ func (ex *connExecutor) execStmtInOpenState(
903903
// PREPARE statement itself.
904904
oldPlaceholders := p.extendedEvalCtx.Placeholders
905905
p.extendedEvalCtx.Placeholders = nil
906+
defer func() {
907+
// The call to addPreparedStmt changed the planner stmt to the
908+
// statement being prepared. Set it back to the PREPARE statement,
909+
// so that it's logged correctly.
910+
p.stmt = stmt
911+
p.extendedEvalCtx.Placeholders = oldPlaceholders
912+
}()
906913
if _, err := ex.addPreparedStmt(
907914
ctx, name, prepStmt, typeHints, rawTypeHints, PreparedStatementOriginSQL,
908915
); err != nil {
909916
return makeErrEvent(err)
910917
}
911-
// The call to addPreparedStmt changed the planner stmt to the statement
912-
// being prepared. Set it back to the PREPARE statement, so that it's
913-
// logged correctly.
914-
p.stmt = stmt
915-
p.extendedEvalCtx.Placeholders = oldPlaceholders
916918
return nil, nil, nil
917919
}
918920

0 commit comments

Comments
 (0)