From 5b06f03d0ae933992ef84871058196def89cc763 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 31 Aug 2020 15:03:21 +0800 Subject: [PATCH] Fix SimpleProtocol with prepared statement --- conn.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/conn.go b/conn.go index 6b9a2b20..e38523ac 100644 --- a/conn.go +++ b/conn.go @@ -473,14 +473,14 @@ optionLoop: } } - if simpleProtocol { - return c.execSimpleProtocol(ctx, sql, arguments) - } - if sd, ok := c.preparedStatements[sql]; ok { return c.execPrepared(ctx, sd, arguments) } + if simpleProtocol { + return c.execSimpleProtocol(ctx, sql, arguments) + } + if len(arguments) == 0 { return c.execSimpleProtocol(ctx, sql, arguments) } @@ -624,7 +624,9 @@ optionLoop: rows := c.getRows(ctx, sql, args) var err error - if simpleProtocol { + sd, ok := c.preparedStatements[sql] + + if simpleProtocol && !ok { sql, err = c.sanitizeForSimpleQuery(sql, args...) if err != nil { rows.fatal(err) @@ -646,7 +648,6 @@ optionLoop: c.eqb.Reset() - sd, ok := c.preparedStatements[sql] if !ok { if c.stmtcache != nil { sd, err = c.stmtcache.Get(ctx, sql)