Rename Preparex to PrepareEx

pull/149/head
Jack Christensen 2016-05-20 08:14:56 -05:00
parent a0d005a993
commit b06560aa03
3 changed files with 19 additions and 19 deletions

16
conn.go
View File

@ -78,8 +78,8 @@ type PreparedStatement struct {
ParameterOids []Oid ParameterOids []Oid
} }
// PreparexOptions is an option struct that can be passed to Preparex // PrepareExOptions is an option struct that can be passed to PrepareEx
type PreparexOptions struct { type PrepareExOptions struct {
ParameterOids []Oid ParameterOids []Oid
} }
@ -585,7 +585,7 @@ func configSSL(sslmode string, cc *ConnConfig) error {
// for bound parameters. These placeholders are referenced positional as $1, $2, etc. // for bound parameters. These placeholders are referenced positional as $1, $2, etc.
// //
// Prepare is idempotent; i.e. it is safe to call Prepare multiple times with the same // Prepare is idempotent; i.e. it is safe to call Prepare multiple times with the same
// name and sql arguments. This allows a code path to Prepare and Query/Exec/Preparex without // 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. // concern for if the statement has already been prepared.
func (c *Conn) Prepare(name, sql string) (ps *PreparedStatement, err error) { func (c *Conn) Prepare(name, sql string) (ps *PreparedStatement, err error) {
if name != "" { if name != "" {
@ -666,14 +666,14 @@ func (c *Conn) Prepare(name, sql string) (ps *PreparedStatement, err error) {
} }
} }
// Preparex creates a prepared statement with name and sql. sql can contain placeholders // PrepareEx creates a prepared statement with name and sql. sql can contain placeholders
// for bound parameters. These placeholders are referenced positional as $1, $2, etc. // for bound parameters. These placeholders are referenced positional as $1, $2, etc.
// It defers from Prepare as it allows additional options (such as parameter OIDs) to be passed via struct // It defers from Prepare as it allows additional options (such as parameter OIDs) to be passed via struct
// //
// Preparex is idempotent; i.e. it is safe to call Preparex multiple times with the same // 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 Preparex and Query/Exec/Prepare without // 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. // concern for if the statement has already been prepared.
func (c *Conn) Preparex(name, sql string, opts PreparexOptions) (ps *PreparedStatement, err error) { func (c *Conn) PrepareEx(name, sql string, opts PrepareExOptions) (ps *PreparedStatement, err error) {
if name != "" { if name != "" {
if ps, ok := c.preparedStatements[name]; ok && ps.SQL == sql { if ps, ok := c.preparedStatements[name]; ok && ps.SQL == sql {
return ps, nil return ps, nil
@ -694,7 +694,7 @@ func (c *Conn) Preparex(name, sql string, opts PreparexOptions) (ps *PreparedSta
wbuf.WriteCString(sql) wbuf.WriteCString(sql)
if len(opts.ParameterOids) > 65535 { if len(opts.ParameterOids) > 65535 {
return nil, errors.New(fmt.Sprintf("Number of PreparexOptions ParameterOids must be between 0 and 65535, received %d", len(opts.ParameterOids))) return nil, errors.New(fmt.Sprintf("Number of PrepareExOptions ParameterOids must be between 0 and 65535, received %d", len(opts.ParameterOids)))
} }
if len(opts.ParameterOids) > 0 { if len(opts.ParameterOids) > 0 {

View File

@ -329,7 +329,7 @@ func (p *ConnPool) Begin() (*Tx, error) {
// //
// Prepare is idempotent; i.e. it is safe to call Prepare multiple times with // Prepare is idempotent; i.e. it is safe to call Prepare multiple times with
// the same name and sql arguments. This allows a code path to Prepare and // the same name and sql arguments. This allows a code path to Prepare and
// Query/Exec/Preparex without concern for if the statement has already been prepared. // Query/Exec/PrepareEx without concern for if the statement has already been prepared.
func (p *ConnPool) Prepare(name, sql string) (*PreparedStatement, error) { func (p *ConnPool) Prepare(name, sql string) (*PreparedStatement, error) {
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
@ -361,18 +361,18 @@ func (p *ConnPool) Prepare(name, sql string) (*PreparedStatement, error) {
return ps, err return ps, err
} }
// Preparex creates a prepared statement on a connection in the pool to test the // PrepareEx creates a prepared statement on a connection in the pool to test the
// statement is valid. If it succeeds all connections accessed through the pool // statement is valid. If it succeeds all connections accessed through the pool
// will have the statement available. // will have the statement available.
// //
// Preparex creates a prepared statement with name and sql. sql can contain placeholders // PrepareEx creates a prepared statement with name and sql. sql can contain placeholders
// for bound parameters. These placeholders are referenced positional as $1, $2, etc. // for bound parameters. These placeholders are referenced positional as $1, $2, etc.
// It defers from Prepare as it allows additional options (such as parameter OIDs) to be passed via struct // It defers from Prepare as it allows additional options (such as parameter OIDs) to be passed via struct
// //
// Preparex is idempotent; i.e. it is safe to call Preparex multiple times with the same // 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 Preparex and Query/Exec/Prepare without // 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. // concern for if the statement has already been prepared.
func (p *ConnPool) Preparex(name, sql string, opts PreparexOptions) (*PreparedStatement, error) { func (p *ConnPool) PrepareEx(name, sql string, opts PrepareExOptions) (*PreparedStatement, error) {
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
@ -385,7 +385,7 @@ func (p *ConnPool) Preparex(name, sql string, opts PreparexOptions) (*PreparedSt
return nil, err return nil, err
} }
ps, err := c.Preparex(name, sql, opts) ps, err := c.PrepareEx(name, sql, opts)
p.availableConnections = append(p.availableConnections, c) p.availableConnections = append(p.availableConnections, c)
if err != nil { if err != nil {
@ -393,7 +393,7 @@ func (p *ConnPool) Preparex(name, sql string, opts PreparexOptions) (*PreparedSt
} }
for _, c := range p.availableConnections { for _, c := range p.availableConnections {
_, err := c.Preparex(name, sql, opts) _, err := c.PrepareEx(name, sql, opts)
if err != nil { if err != nil {
return nil, err return nil, err
} }

6
tx.go
View File

@ -136,13 +136,13 @@ func (tx *Tx) Prepare(name, sql string) (*PreparedStatement, error) {
return tx.conn.Prepare(name, sql) return tx.conn.Prepare(name, sql)
} }
// Preparex delegates to the underlying *Conn // PrepareEx delegates to the underlying *Conn
func (tx *Tx) Preparex(name, sql string, opts PreparexOptions) (*PreparedStatement, error) { func (tx *Tx) PrepareEx(name, sql string, opts PrepareExOptions) (*PreparedStatement, error) {
if tx.status != TxStatusInProgress { if tx.status != TxStatusInProgress {
return nil, ErrTxClosed return nil, ErrTxClosed
} }
return tx.conn.Preparex(name, sql, opts) return tx.conn.PrepareEx(name, sql, opts)
} }
// Query delegates to the underlying *Conn // Query delegates to the underlying *Conn