Only remove statement from map if deallocate succeeds

https://github.com/jackc/pgx/pull/1795
pull/1804/head
Jack Christensen 2023-11-11 09:48:17 -06:00 committed by Jack Christensen
parent 7d5a3969d0
commit 9782306287
1 changed files with 12 additions and 3 deletions

15
conn.go
View File

@ -341,14 +341,23 @@ func (c *Conn) Prepare(ctx context.Context, name, sql string) (sd *pgconn.Statem
// Deallocate releases a prepared statement.
func (c *Conn) Deallocate(ctx context.Context, name string) error {
var psName string
if sd, ok := c.preparedStatements[name]; ok {
delete(c.preparedStatements, name)
sd := c.preparedStatements[name]
if sd != nil {
psName = sd.Name
} else {
psName = name
}
err := c.pgConn.Deallocate(ctx, psName)
return err
if err != nil {
return err
}
if sd != nil {
delete(c.preparedStatements, name)
}
return nil
}
// DeallocateAll releases all previously prepared statements from the server and client, where it also resets the statement and description cache.