--- e:\prg\py\third-parties\mysql\mysql-connector-python-0.3.0-devel\python3\mysql\connector\cursor.py 2010-12-10 11:39:18.000000000 +0100 +++ e:\prg\py\third-parties\mysql\mysql-connector-python-0.3.0-patched\python3\mysql\connector\cursor.py 2010-12-18 12:08:35.484375000 +0100 @@ -37,6 +37,26 @@ RE_SQL_INSERT_VALUES = re.compile(r'\sVALUES\s*(\(.*\))', re.I) RE_SQL_INSERT_STMT = re.compile(r'INSERT\s+INTO', re.I) +RE_SQL_TUPLE_ARG = re.compile(b"(%s)") + +class _TupleArgsSubber(object): + def __init__( self, args ): + self.args = args + self.index = 0 + + def __call__( self, matchobj ): + index = self.index + self.index += 1 + return self.args[index] + +def _subst_tuple_args( stmt, args ): + subber = _TupleArgsSubber( args ) + subst_stmt = RE_SQL_TUPLE_ARG.sub( subber, stmt ) + remaining = len(args) - subber.index + if remaining: + raise ValueError('%d arguments where not used in substitution of query %r' % (remaining, stmt)) + return subst_stmt + class CursorBase(object): """ Base for defining MySQLCursor. This class is a skeleton and defines @@ -305,9 +325,7 @@ for k,v in self._process_params_dict(params).items(): stmt = stmt.replace(k,v,1) elif isinstance(params, (list,tuple)): - for p in self._process_params(params): - stmt = stmt.replace(b'%s',p,1) - + stmt = _subst_tuple_args( stmt, self._process_params(params) ) res = self.db().protocol.cmd_query(stmt) self._handle_result(res) except (UnicodeDecodeError,UnicodeEncodeError) as e: