Skip to content

Commit 40cca24

Browse files
authored
Merge pull request #2583 from dolthub/zachmu/deallocate
DEALLOCATE ALL
2 parents 5c5c758 + 25ec26d commit 40cca24

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

server/connection_handler.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ func (h *ConnectionHandler) handleQueryOutsideEngine(query ConvertedQuery) (hand
498498
case *sqlparser.Commit:
499499
h.inTransaction = false
500500
case *sqlparser.Deallocate:
501-
// TODO: handle ALL keyword
502501
return true, true, h.deallocatePreparedStatement(stmt.Name, h.preparedStatements, query, h.Conn())
503502
case sqlparser.InjectedStatement:
504503
switch injectedStmt := stmt.Statement.(type) {
@@ -968,12 +967,21 @@ func startTransactionIfNecessary(ctx *sql.Context) error {
968967
return nil
969968
}
970969

970+
// deallocatePreparedStatement handles a DEALLOCATE statement by deleting the corresponding prepared statement from the
971+
// handler's prepared statement map, and sending a CommandComplete message back to the client. Pass an empty |name|
972+
// for `ALL`. This matches the behavior in the parser, which doesn't include a separate field for ALL.
971973
func (h *ConnectionHandler) deallocatePreparedStatement(name string, preparedStatements map[string]PreparedStatementData, query ConvertedQuery, conn net.Conn) error {
972-
_, ok := preparedStatements[name]
973-
if !ok {
974-
return errors.Errorf("prepared statement %s does not exist", name)
974+
if name == "" {
975+
for name := range preparedStatements {
976+
delete(preparedStatements, name)
977+
}
978+
} else {
979+
_, ok := preparedStatements[name]
980+
if !ok {
981+
return errors.Errorf("prepared statement %s does not exist", name)
982+
}
983+
delete(preparedStatements, name)
975984
}
976-
delete(preparedStatements, name)
977985

978986
return h.send(&pgproto3.CommandComplete{
979987
CommandTag: []byte(query.StatementTag),

0 commit comments

Comments
 (0)