mirror of https://github.com/jackc/pgx.git
Fix stdlib error caused by idempotent Prepare
parent
984eace2b5
commit
41b96b5f77
4
conn.go
4
conn.go
|
@ -495,9 +495,11 @@ func configSSL(sslmode string, cc *ConnConfig) error {
|
||||||
// name and sql arguments. This allows a code path to Prepare and Query/Exec without
|
// name and sql arguments. This allows a code path to Prepare and Query/Exec 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 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
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if c.logLevel >= LogLevelError {
|
if c.logLevel >= LogLevelError {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -558,7 +560,7 @@ func (c *Conn) Prepare(name, sql string) (ps *PreparedStatement, err error) {
|
||||||
case readyForQuery:
|
case readyForQuery:
|
||||||
c.rxReadyForQuery(r)
|
c.rxReadyForQuery(r)
|
||||||
|
|
||||||
if softErr == nil && name != "" {
|
if softErr == nil {
|
||||||
c.preparedStatements[name] = ps
|
c.preparedStatements[name] = ps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue