mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-16 12:27:03 +08:00
Fix client_flag fubar and add support for more detailed warning
information available from MySQL-4.1 and newer server.
This commit is contained in:
@ -132,16 +132,17 @@ class Connection(_mysql.connection):
|
|||||||
del kwargs2['use_unicode']
|
del kwargs2['use_unicode']
|
||||||
|
|
||||||
client_flag = kwargs.get('client_flag', 0)
|
client_flag = kwargs.get('client_flag', 0)
|
||||||
client_version = [ int(n) for n in _mysql.get_client_info().split('.')[:2] ]
|
client_version = tuple([ int(n) for n in _mysql.get_client_info().split('.')[:2] ])
|
||||||
if client_version >= (4, 1):
|
if client_version >= (4, 1):
|
||||||
client_version |= CLIENT.MULTI_STATEMENTS
|
client_flag |= CLIENT.MULTI_STATEMENTS
|
||||||
if client_version >= (5, 0):
|
if client_version >= (5, 0):
|
||||||
client_version |= CLIENT.MULTI_RESULTS
|
client_flag |= CLIENT.MULTI_RESULTS
|
||||||
|
|
||||||
kwargs2['client_flag'] = client_flag
|
kwargs2['client_flag'] = client_flag
|
||||||
|
|
||||||
super(Connection, self).__init__(*args, **kwargs2)
|
super(Connection, self).__init__(*args, **kwargs2)
|
||||||
|
|
||||||
|
self._server_version = tuple([ int(n) for n in self.get_server_info().split('.')[:2] ])
|
||||||
self.charset = self.character_set_name().split('_')[0]
|
self.charset = self.character_set_name().split('_')[0]
|
||||||
|
|
||||||
if use_unicode:
|
if use_unicode:
|
||||||
@ -209,7 +210,19 @@ class Connection(_mysql.connection):
|
|||||||
return atoi(info.split()[-1])
|
return atoi(info.split()[-1])
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def show_warnings(self):
|
||||||
|
"""Return detailed information about warnings as a
|
||||||
|
sequence of tuples of (Level, Code, Message). This
|
||||||
|
is only supported in MySQL-4.1 and up. If your server
|
||||||
|
is an earlier version, an empty sequence is returned."""
|
||||||
|
if self._server_version < (4,1): return ()
|
||||||
|
self.query("SHOW WARNINGS")
|
||||||
|
r = self.store_result()
|
||||||
|
warnings = r.fetch_row(0)
|
||||||
|
return [ (level.tostring(), int(code), message.tostring())
|
||||||
|
for level, code, message in warnings ]
|
||||||
|
|
||||||
Warning = Warning
|
Warning = Warning
|
||||||
Error = Error
|
Error = Error
|
||||||
InterfaceError = InterfaceError
|
InterfaceError = InterfaceError
|
||||||
|
@ -56,9 +56,18 @@ class BaseCursor(object):
|
|||||||
|
|
||||||
def _warning_check(self):
|
def _warning_check(self):
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
if self._warnings and self._info:
|
if self._warnings:
|
||||||
self.messages.append((self.Warning, self._info))
|
warnings = self.connection.show_warnings()
|
||||||
warn(self._info, self.Warning, 3)
|
if warnings:
|
||||||
|
# This is done in two loops in case
|
||||||
|
# Warnings are set to raise exceptions.
|
||||||
|
for w in warnings:
|
||||||
|
self.messages.append((self.Warning, w))
|
||||||
|
for w in warnings:
|
||||||
|
warn(w[-1], self.Warning, 3)
|
||||||
|
elif self._info:
|
||||||
|
self.messages.append((self.Warning, self._info))
|
||||||
|
warn(self._info, self.Warning, 3)
|
||||||
|
|
||||||
def nextset(self):
|
def nextset(self):
|
||||||
"""Advance to the next result set.
|
"""Advance to the next result set.
|
||||||
|
Reference in New Issue
Block a user