From 1f8bd5361e068bc81a522ae405bb632d74d86be4 Mon Sep 17 00:00:00 2001 From: Vilnis Termanis Date: Sat, 20 Jan 2018 17:40:38 +0000 Subject: [PATCH 1/2] Reduce callproc roundtrip time - Make only one single call to SET variables used as procedure parameters --- MySQLdb/cursors.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py index 3769ab5e..b3632933 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -349,9 +349,10 @@ def callproc(self, procname, args=()): """ db = self._get_db() - for index, arg in enumerate(args): - q = "SET @_%s_%d=%s" % (procname, index, - db.literal(arg)) + if args: + argFmt = '@_{0}_%d=%s'.format(procname) + q = 'SET %s' % ','.join(argFmt % (index, db.literal(arg)) + for index, arg in enumerate(args)) if isinstance(q, unicode): q = q.encode(db.encoding, 'surrogateescape') self._query(q) From f2f94dcddeddbcd0b458873f6166b5d1dea23ba0 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Thu, 15 Mar 2018 18:44:22 +0900 Subject: [PATCH 2/2] Update cursors.py --- MySQLdb/cursors.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py index b3632933..bc1334b7 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -350,9 +350,9 @@ def callproc(self, procname, args=()): db = self._get_db() if args: - argFmt = '@_{0}_%d=%s'.format(procname) - q = 'SET %s' % ','.join(argFmt % (index, db.literal(arg)) - for index, arg in enumerate(args)) + fmt = '@_{0}_%d=%s'.format(procname) + q = 'SET %s' % ','.join(fmt % (index, db.literal(arg)) + for index, arg in enumerate(args)) if isinstance(q, unicode): q = q.encode(db.encoding, 'surrogateescape') self._query(q)