mirror of https://github.com/jackc/pgx.git
parent
d1fd222ca5
commit
8a7165dd98
10
conn.go
10
conn.go
|
@ -710,7 +710,7 @@ func configSSL(sslmode string, cc *ConnConfig) error {
|
|||
// name and sql arguments. This allows a code path to Prepare and Query/Exec without
|
||||
// concern for if the statement has already been prepared.
|
||||
func (c *Conn) Prepare(name, sql string) (ps *PreparedStatement, err error) {
|
||||
return c.PrepareEx(name, sql, nil)
|
||||
return c.PrepareEx(context.Background(), name, sql, nil)
|
||||
}
|
||||
|
||||
// PrepareEx creates a prepared statement with name and sql. sql can contain placeholders
|
||||
|
@ -720,11 +720,7 @@ func (c *Conn) Prepare(name, sql string) (ps *PreparedStatement, err error) {
|
|||
// PrepareEx is idempotent; i.e. it is safe to call PrepareEx multiple times with the same
|
||||
// name and sql arguments. This allows a code path to PrepareEx and Query/Exec without
|
||||
// concern for if the statement has already been prepared.
|
||||
func (c *Conn) PrepareEx(name, sql string, opts *PrepareExOptions) (ps *PreparedStatement, err error) {
|
||||
return c.PrepareExContext(context.Background(), name, sql, opts)
|
||||
}
|
||||
|
||||
func (c *Conn) PrepareExContext(ctx context.Context, name, sql string, opts *PrepareExOptions) (ps *PreparedStatement, err error) {
|
||||
func (c *Conn) PrepareEx(ctx context.Context, name, sql string, opts *PrepareExOptions) (ps *PreparedStatement, err error) {
|
||||
err = c.waitForPreviousCancelQuery(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1455,7 +1451,7 @@ func (c *Conn) ExecEx(ctx context.Context, sql string, options *QueryExOptions,
|
|||
ps, ok := c.preparedStatements[sql]
|
||||
if !ok {
|
||||
var err error
|
||||
ps, err = c.PrepareExContext(ctx, "", sql, nil)
|
||||
ps, err = c.PrepareEx(ctx, "", sql, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -425,7 +425,7 @@ func (p *ConnPool) Begin() (*Tx, error) {
|
|||
// the same name and sql arguments. This allows a code path to Prepare and
|
||||
// Query/Exec/PrepareEx without concern for if the statement has already been prepared.
|
||||
func (p *ConnPool) Prepare(name, sql string) (*PreparedStatement, error) {
|
||||
return p.PrepareEx(name, sql, nil)
|
||||
return p.PrepareEx(context.Background(), name, sql, nil)
|
||||
}
|
||||
|
||||
// PrepareEx creates a prepared statement on a connection in the pool to test the
|
||||
|
@ -439,7 +439,7 @@ func (p *ConnPool) Prepare(name, sql string) (*PreparedStatement, error) {
|
|||
// PrepareEx is idempotent; i.e. it is safe to call PrepareEx multiple times with the same
|
||||
// name and sql arguments. This allows a code path to PrepareEx and Query/Exec/Prepare without
|
||||
// concern for if the statement has already been prepared.
|
||||
func (p *ConnPool) PrepareEx(name, sql string, opts *PrepareExOptions) (*PreparedStatement, error) {
|
||||
func (p *ConnPool) PrepareEx(ctx context.Context, name, sql string, opts *PrepareExOptions) (*PreparedStatement, error) {
|
||||
p.cond.L.Lock()
|
||||
defer p.cond.L.Unlock()
|
||||
|
||||
|
@ -461,13 +461,13 @@ func (p *ConnPool) PrepareEx(name, sql string, opts *PrepareExOptions) (*Prepare
|
|||
return ps, nil
|
||||
}
|
||||
|
||||
ps, err := c.PrepareEx(name, sql, opts)
|
||||
ps, err := c.PrepareEx(ctx, name, sql, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, c := range p.availableConnections {
|
||||
_, err := c.PrepareEx(name, sql, opts)
|
||||
_, err := c.PrepareEx(ctx, name, sql, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -1326,7 +1326,7 @@ func TestPrepareEx(t *testing.T) {
|
|||
conn := mustConnect(t, *defaultConnConfig)
|
||||
defer closeConn(t, conn)
|
||||
|
||||
_, err := conn.PrepareEx("test", "select $1", &pgx.PrepareExOptions{ParameterOids: []pgtype.Oid{pgtype.TextOid}})
|
||||
_, err := conn.PrepareEx(context.Background(), "test", "select $1", &pgx.PrepareExOptions{ParameterOids: []pgtype.Oid{pgtype.TextOid}})
|
||||
if err != nil {
|
||||
t.Errorf("Unable to prepare statement: %v", err)
|
||||
return
|
||||
|
|
2
query.go
2
query.go
|
@ -386,7 +386,7 @@ func (c *Conn) QueryEx(ctx context.Context, sql string, options *QueryExOptions,
|
|||
ps, ok := c.preparedStatements[sql]
|
||||
if !ok {
|
||||
var err error
|
||||
ps, err = c.PrepareExContext(ctx, "", sql, nil)
|
||||
ps, err = c.PrepareEx(ctx, "", sql, nil)
|
||||
if err != nil {
|
||||
rows.fatal(err)
|
||||
return rows, rows.err
|
||||
|
|
|
@ -220,7 +220,7 @@ func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, e
|
|||
name := fmt.Sprintf("pgx_%d", c.psCount)
|
||||
c.psCount++
|
||||
|
||||
ps, err := c.conn.PrepareExContext(ctx, name, query, nil)
|
||||
ps, err := c.conn.PrepareEx(ctx, name, query, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ func (c *Conn) QueryContext(ctx context.Context, query string, argsV []driver.Na
|
|||
return nil, driver.ErrBadConn
|
||||
}
|
||||
|
||||
ps, err := c.conn.PrepareExContext(ctx, "", query, nil)
|
||||
ps, err := c.conn.PrepareEx(ctx, "", query, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
6
tx.go
6
tx.go
|
@ -174,16 +174,16 @@ func (tx *Tx) Exec(sql string, arguments ...interface{}) (commandTag CommandTag,
|
|||
|
||||
// Prepare delegates to the underlying *Conn
|
||||
func (tx *Tx) Prepare(name, sql string) (*PreparedStatement, error) {
|
||||
return tx.PrepareEx(name, sql, nil)
|
||||
return tx.PrepareEx(context.Background(), name, sql, nil)
|
||||
}
|
||||
|
||||
// PrepareEx delegates to the underlying *Conn
|
||||
func (tx *Tx) PrepareEx(name, sql string, opts *PrepareExOptions) (*PreparedStatement, error) {
|
||||
func (tx *Tx) PrepareEx(ctx context.Context, name, sql string, opts *PrepareExOptions) (*PreparedStatement, error) {
|
||||
if tx.status != TxStatusInProgress {
|
||||
return nil, ErrTxClosed
|
||||
}
|
||||
|
||||
return tx.conn.PrepareEx(name, sql, opts)
|
||||
return tx.conn.PrepareEx(ctx, name, sql, opts)
|
||||
}
|
||||
|
||||
// Query delegates to the underlying *Conn
|
||||
|
|
Loading…
Reference in New Issue