"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "mysql/connector/cursor.py" between
mysql-utilities-1.6.4.tar.gz and mysql-utilities-1.6.5.tar.gz

About: MySQL Utilities is a package of utilities that are used for maintenance and administration of MySQL servers (written in Python).

cursor.py  (mysql-utilities-1.6.4):cursor.py  (mysql-utilities-1.6.5)
# MySQL Connector/Python - MySQL driver written in Python. # MySQL Connector/Python - MySQL driver written in Python.
# Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
# MySQL Connector/Python is licensed under the terms of the GPLv2 # MySQL Connector/Python is licensed under the terms of the GPLv2
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most # <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
# MySQL Connectors. There are special exceptions to the terms and # MySQL Connectors. There are special exceptions to the terms and
# conditions of the GPLv2 as it is applied to this software, see the # conditions of the GPLv2 as it is applied to this software, see the
# FOSS License Exception # FOSS License Exception
# <http://www.mysql.com/about/legal/licensing/foss-exception.html>. # <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
skipping to change at line 43 skipping to change at line 43
from .catch23 import PY2 from .catch23 import PY2
SQL_COMMENT = r"\/\*.*?\*\/" SQL_COMMENT = r"\/\*.*?\*\/"
RE_SQL_COMMENT = re.compile( RE_SQL_COMMENT = re.compile(
r'''({0})|(["'`][^"'`]*?({0})[^"'`]*?["'`])'''.format(SQL_COMMENT), r'''({0})|(["'`][^"'`]*?({0})[^"'`]*?["'`])'''.format(SQL_COMMENT),
re.I | re.M | re.S) re.I | re.M | re.S)
RE_SQL_ON_DUPLICATE = re.compile( RE_SQL_ON_DUPLICATE = re.compile(
r'''\s*ON\s+DUPLICATE\s+KEY(?:[^"'`]*["'`][^"'`]*["'`])*[^"'`]*$''', r'''\s*ON\s+DUPLICATE\s+KEY(?:[^"'`]*["'`][^"'`]*["'`])*[^"'`]*$''',
re.I | re.M | re.S) re.I | re.M | re.S)
RE_SQL_INSERT_STMT = re.compile( RE_SQL_INSERT_STMT = re.compile(
r"({0}|\s)*INSERT({0}|\s)*INTO.+VALUES.*".format(SQL_COMMENT), r"({0}|\s)*INSERT({0}|\s)*INTO\s+[`'\"]?.+[`'\"]?(?:\.[`'\"]?.+[`'\"]?)"
"{{0,2}}\s+VALUES\s*\(.+(?:\s*,.+)*\)".format(SQL_COMMENT),
re.I | re.M | re.S) re.I | re.M | re.S)
RE_SQL_INSERT_VALUES = re.compile(r'.*VALUES\s*(\(.*\)).*', re.I | re.M | re.S) RE_SQL_INSERT_VALUES = re.compile(r'.*VALUES\s*(\(.*\)).*', re.I | re.M | re.S)
RE_PY_PARAM = re.compile(b'(%s)') RE_PY_PARAM = re.compile(b'(%s)')
RE_PY_MAPPING_PARAM = re.compile(
br'''
%
\((?P<mapping_key>[^)]+)\)
(?P<conversion_type>[diouxXeEfFgGcrs%])
''',
re.X
)
RE_SQL_SPLIT_STMTS = re.compile( RE_SQL_SPLIT_STMTS = re.compile(
b''';(?=(?:[^"'`]*["'`][^"'`]*["'`])*[^"'`]*$)''') b''';(?=(?:[^"'`]*["'`][^"'`]*["'`])*[^"'`]*$)''')
RE_SQL_FIND_PARAM = re.compile( RE_SQL_FIND_PARAM = re.compile(
b'''%s(?=(?:[^"'`]*["'`][^"'`]*["'`])*[^"'`]*$)''') b'''%s(?=(?:[^"'`]*["'`][^"'`]*["'`])*[^"'`]*$)''')
ERR_NO_RESULT_TO_FETCH = "No result set to fetch from" ERR_NO_RESULT_TO_FETCH = "No result set to fetch from"
class _ParamSubstitutor(object): class _ParamSubstitutor(object):
""" """
Substitutes parameters into SQL statement. Substitutes parameters into SQL statement.
skipping to change at line 76 skipping to change at line 85
return bytes(self.params[index]) return bytes(self.params[index])
except IndexError: except IndexError:
raise errors.ProgrammingError( raise errors.ProgrammingError(
"Not enough parameters for the SQL statement") "Not enough parameters for the SQL statement")
@property @property
def remaining(self): def remaining(self):
"""Returns number of parameters remaining to be substituted""" """Returns number of parameters remaining to be substituted"""
return len(self.params) - self.index return len(self.params) - self.index
def _bytestr_format_dict(bytestr, value_dict):
"""
>>> _bytestr_format_dict(b'%(a)s', {b'a': b'foobar'})
b'foobar
>>> _bytestr_format_dict(b'%%(a)s', {b'a': b'foobar'})
b'%%(a)s'
>>> _bytestr_format_dict(b'%%%(a)s', {b'a': b'foobar'})
b'%%foobar'
>>> _bytestr_format_dict(b'%(x)s %(y)s',
... {b'x': b'x=%(y)s', b'y': b'y=%(x)s'})
b'x=%(y)s y=%(x)s'
"""
def replace(matchobj):
value = None
groups = matchobj.groupdict()
if groups["conversion_type"] == b"%":
value = b"%"
if groups["conversion_type"] == b"s":
key = groups["mapping_key"].encode("utf-8") \
if PY2 else groups["mapping_key"]
value = value_dict[key]
if value is None:
raise ValueError("Unsupported conversion_type: {0}"
"".format(groups["conversion_type"]))
return value.decode("utf-8") if PY2 else value
return RE_PY_MAPPING_PARAM.sub(replace, bytestr.decode("utf-8")
if PY2 else bytestr)
class CursorBase(MySQLCursorAbstract): class CursorBase(MySQLCursorAbstract):
""" """
Base for defining MySQLCursor. This class is a skeleton and defines Base for defining MySQLCursor. This class is a skeleton and defines
methods and members as required for the Python Database API methods and members as required for the Python Database API
Specification v2.0. Specification v2.0.
It's better to inherite from MySQLCursor. It's better to inherite from MySQLCursor.
""" """
_raw = False _raw = False
skipping to change at line 360 skipping to change at line 397
to_mysql = self._connection.converter.to_mysql to_mysql = self._connection.converter.to_mysql
escape = self._connection.converter.escape escape = self._connection.converter.escape
quote = self._connection.converter.quote quote = self._connection.converter.quote
res = {} res = {}
for key, value in list(params.items()): for key, value in list(params.items()):
conv = value conv = value
conv = to_mysql(conv) conv = to_mysql(conv)
conv = escape(conv) conv = escape(conv)
conv = quote(conv) conv = quote(conv)
if PY2: if PY2:
res["%({0})s".format(key)] = conv res[key] = conv
else: else:
res["%({0})s".format(key).encode()] = conv res[key.encode()] = conv
except Exception as err: except Exception as err:
raise errors.ProgrammingError( raise errors.ProgrammingError(
"Failed processing pyformat-parameters; %s" % err) "Failed processing pyformat-parameters; %s" % err)
else: else:
return res return res
def _process_params(self, params): def _process_params(self, params):
"""Process query parameters.""" """Process query parameters."""
try: try:
res = params res = params
skipping to change at line 497 skipping to change at line 534
try: try:
if not isinstance(operation, (bytes, bytearray)): if not isinstance(operation, (bytes, bytearray)):
stmt = operation.encode(self._connection.python_charset) stmt = operation.encode(self._connection.python_charset)
else: else:
stmt = operation stmt = operation
except (UnicodeDecodeError, UnicodeEncodeError) as err: except (UnicodeDecodeError, UnicodeEncodeError) as err:
raise errors.ProgrammingError(str(err)) raise errors.ProgrammingError(str(err))
if params is not None: if params is not None:
if isinstance(params, dict): if isinstance(params, dict):
for key, value in self._process_params_dict(params).items(): stmt = _bytestr_format_dict(
stmt = stmt.replace(key, value) stmt, self._process_params_dict(params))
elif isinstance(params, (list, tuple)): elif isinstance(params, (list, tuple)):
psub = _ParamSubstitutor(self._process_params(params)) psub = _ParamSubstitutor(self._process_params(params))
stmt = RE_PY_PARAM.sub(psub, stmt) stmt = RE_PY_PARAM.sub(psub, stmt)
if psub.remaining != 0: if psub.remaining != 0:
raise errors.ProgrammingError( raise errors.ProgrammingError(
"Not all parameters were used in the SQL statement") "Not all parameters were used in the SQL statement")
self._executed = stmt self._executed = stmt
if multi: if multi:
self._executed_list = [] self._executed_list = []
skipping to change at line 551 skipping to change at line 588
"Check SQL syntax." "Check SQL syntax."
) )
fmt = matches.group(1).encode(self._connection.charset) fmt = matches.group(1).encode(self._connection.charset)
values = [] values = []
try: try:
stmt = operation.encode(self._connection.charset) stmt = operation.encode(self._connection.charset)
for params in seq_params: for params in seq_params:
tmp = fmt tmp = fmt
if isinstance(params, dict): if isinstance(params, dict):
for key, value in self._process_params_dict(params).items(): tmp = _bytestr_format_dict(
tmp = tmp.replace(key, value) tmp, self._process_params_dict(params))
else: else:
psub = _ParamSubstitutor(self._process_params(params)) psub = _ParamSubstitutor(self._process_params(params))
tmp = RE_PY_PARAM.sub(psub, tmp) tmp = RE_PY_PARAM.sub(psub, tmp)
if psub.remaining != 0: if psub.remaining != 0:
raise errors.ProgrammingError( raise errors.ProgrammingError(
"Not all parameters were used in the SQL statement") "Not all parameters were used in the SQL statement")
#for p in self._process_params(params): #for p in self._process_params(params):
# tmp = tmp.replace(b'%s',p,1) # tmp = tmp.replace(b'%s',p,1)
values.append(tmp) values.append(tmp)
if fmt in stmt: if fmt in stmt:
 End of changes. 8 change blocks. 
8 lines changed or deleted 45 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS