From 41b96b5f77eec98737106c51b291bc7af6a586fa Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Fri, 16 Oct 2015 14:56:30 -0500 Subject: [PATCH] Fix stdlib error caused by idempotent Prepare --- conn.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/conn.go b/conn.go index 4038ba6e..e84db518 100644 --- a/conn.go +++ b/conn.go @@ -495,8 +495,10 @@ 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) { - if ps, ok := c.preparedStatements[name]; ok && ps.SQL == sql { - return ps, nil + if name != "" { + if ps, ok := c.preparedStatements[name]; ok && ps.SQL == sql { + return ps, nil + } } if c.logLevel >= LogLevelError { @@ -558,7 +560,7 @@ func (c *Conn) Prepare(name, sql string) (ps *PreparedStatement, err error) { case readyForQuery: c.rxReadyForQuery(r) - if softErr == nil && name != "" { + if softErr == nil { c.preparedStatements[name] = ps }