Deallocate takes context

pull/483/head
Jack Christensen 2019-04-20 11:34:52 -05:00
parent 1f010f412d
commit 95756b1d7f
3 changed files with 6 additions and 11 deletions

View File

@ -282,14 +282,9 @@ func (c *Conn) PrepareEx(ctx context.Context, name, sql string, opts *PrepareExO
} }
// Deallocate released a prepared statement // Deallocate released a prepared statement
func (c *Conn) Deallocate(name string) error { func (c *Conn) Deallocate(ctx context.Context, name string) error {
return c.deallocateContext(context.Background(), name)
}
// TODO - consider making this public
func (c *Conn) deallocateContext(ctx context.Context, name string) (err error) {
delete(c.preparedStatements, name) delete(c.preparedStatements, name)
_, err = c.pgConn.Exec(ctx, "deallocate "+quoteIdentifier(name)).ReadAll() _, err := c.pgConn.Exec(ctx, "deallocate "+quoteIdentifier(name)).ReadAll()
return err return err
} }

View File

@ -297,7 +297,7 @@ func TestPrepare(t *testing.T) {
t.Errorf("Prepared statement did not return expected value: %v", s) t.Errorf("Prepared statement did not return expected value: %v", s)
} }
err = conn.Deallocate("test") err = conn.Deallocate(context.Background(), "test")
if err != nil { if err != nil {
t.Errorf("conn.Deallocate failed: %v", err) t.Errorf("conn.Deallocate failed: %v", err)
} }
@ -321,7 +321,7 @@ func TestPrepare(t *testing.T) {
t.Errorf("Prepared statement did not return expected value: %v", s) t.Errorf("Prepared statement did not return expected value: %v", s)
} }
err = conn.Deallocate("test") err = conn.Deallocate(context.Background(), "test")
if err != nil { if err != nil {
t.Errorf("conn.Deallocate failed: %v", err) t.Errorf("conn.Deallocate failed: %v", err)
} }
@ -392,7 +392,7 @@ func TestPrepareEx(t *testing.T) {
t.Errorf("Prepared statement did not return expected value: %v", s) t.Errorf("Prepared statement did not return expected value: %v", s)
} }
err = conn.Deallocate("test") err = conn.Deallocate(context.Background(), "test")
if err != nil { if err != nil {
t.Errorf("conn.Deallocate failed: %v", err) t.Errorf("conn.Deallocate failed: %v", err)
} }

View File

@ -315,7 +315,7 @@ type Stmt struct {
} }
func (s *Stmt) Close() error { func (s *Stmt) Close() error {
return s.conn.conn.Deallocate(s.ps.Name) return s.conn.conn.Deallocate(context.Background(), s.ps.Name)
} }
func (s *Stmt) NumInput() int { func (s *Stmt) NumInput() int {