Skip to content

Commit 9c1b0d8

Browse files
authored
Reduce callproc roundtrip time (PyMySQL#636)
Make only one single call to SET variables used as procedure parameters
2 parents 9f29c16 + 3dda4a5 commit 9c1b0d8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pymysql/cursors.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ def callproc(self, procname, args=()):
262262
disconnected.
263263
"""
264264
conn = self._get_db()
265-
for index, arg in enumerate(args):
266-
q = "SET @_%s_%d=%s" % (procname, index, conn.escape(arg))
267-
self._query(q)
265+
if args:
266+
fmt = '@_{0}_%d=%s'.format(procname)
267+
self._query('SET %s' % ','.join(fmt % (index, conn.escape(arg))
268+
for index, arg in enumerate(args)))
268269
self.nextset()
269270

270271
q = "CALL %s(%s)" % (procname,

0 commit comments

Comments
 (0)