upgraded to pymysql 0.2
This commit is contained in:
@@ -2,20 +2,21 @@ import struct
|
||||
|
||||
|
||||
try:
|
||||
Exception, Warning
|
||||
StandardError, Warning
|
||||
except ImportError:
|
||||
try:
|
||||
from exceptions import Exception, Warning
|
||||
from exceptions import StandardError, Warning
|
||||
except ImportError:
|
||||
import sys
|
||||
e = sys.modules['exceptions']
|
||||
Exception = e.Exception
|
||||
StandardError = e.StandardError
|
||||
Warning = e.Warning
|
||||
|
||||
|
||||
from constants import ER
|
||||
import sys
|
||||
|
||||
class MySQLError(Exception):
|
||||
|
||||
class MySQLError(StandardError):
|
||||
|
||||
"""Exception related to operation with MySQL."""
|
||||
|
||||
|
||||
@@ -106,13 +107,19 @@ _map_error(IntegrityError, ER.DUP_ENTRY, ER.NO_REFERENCED_ROW,
|
||||
ER.CANNOT_ADD_FOREIGN)
|
||||
_map_error(NotSupportedError, ER.WARNING_NOT_COMPLETE_ROLLBACK,
|
||||
ER.NOT_SUPPORTED_YET, ER.FEATURE_DISABLED, ER.UNKNOWN_STORAGE_ENGINE)
|
||||
_map_error(OperationalError, ER.DBACCESS_DENIED_ERROR, ER.ACCESS_DENIED_ERROR,
|
||||
ER.TABLEACCESS_DENIED_ERROR, ER.COLUMNACCESS_DENIED_ERROR)
|
||||
|
||||
del _map_error, ER
|
||||
|
||||
|
||||
|
||||
def _get_error_info(data):
|
||||
errno = struct.unpack('<h', data[1:3])[0]
|
||||
if data[3] == "#":
|
||||
if sys.version_info[0] == 3:
|
||||
is_41 = data[3] == ord("#")
|
||||
else:
|
||||
is_41 = data[3] == "#"
|
||||
if is_41:
|
||||
# version 4.1
|
||||
sqlstate = data[4:9].decode("utf8")
|
||||
errorvalue = data[9:].decode("utf8")
|
||||
@@ -122,7 +129,7 @@ def _get_error_info(data):
|
||||
return (errno, None, data[3:].decode("utf8"))
|
||||
|
||||
def _check_mysql_exception(errinfo):
|
||||
errno, sqlstate, errorvalue = errinfo
|
||||
errno, sqlstate, errorvalue = errinfo
|
||||
errorclass = error_map.get(errno, None)
|
||||
if errorclass:
|
||||
raise errorclass, (errno,errorvalue)
|
||||
@@ -133,8 +140,7 @@ def _check_mysql_exception(errinfo):
|
||||
def raise_mysql_exception(data):
|
||||
errinfo = _get_error_info(data)
|
||||
_check_mysql_exception(errinfo)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user