mirror of https://github.com/jackc/pgx.git
Only remove statement from map if deallocate succeeds
https://github.com/jackc/pgx/pull/1795pull/1804/head
parent
7d5a3969d0
commit
9782306287
15
conn.go
15
conn.go
|
@ -341,14 +341,23 @@ func (c *Conn) Prepare(ctx context.Context, name, sql string) (sd *pgconn.Statem
|
||||||
// Deallocate releases a prepared statement.
|
// Deallocate releases a prepared statement.
|
||||||
func (c *Conn) Deallocate(ctx context.Context, name string) error {
|
func (c *Conn) Deallocate(ctx context.Context, name string) error {
|
||||||
var psName string
|
var psName string
|
||||||
if sd, ok := c.preparedStatements[name]; ok {
|
sd := c.preparedStatements[name]
|
||||||
delete(c.preparedStatements, name)
|
if sd != nil {
|
||||||
psName = sd.Name
|
psName = sd.Name
|
||||||
} else {
|
} else {
|
||||||
psName = name
|
psName = name
|
||||||
}
|
}
|
||||||
|
|
||||||
err := c.pgConn.Deallocate(ctx, psName)
|
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.
|
// DeallocateAll releases all previously prepared statements from the server and client, where it also resets the statement and description cache.
|
||||||
|
|
Loading…
Reference in New Issue