MobileBlur

Diff
Login

Differences From Artifact [5e9f1064e5]:

To Artifact [731d737012]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18

19
20
21
22
23
24
25
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17

18
19
20
21
22
23
24
25













-
+



-
+







import struct


try:
    Exception, Warning
except ImportError:
    try:
        from exceptions import Exception, Warning
    except ImportError:
        import sys
        e = sys.modules['exceptions']
        Exception = e.Exception
        Warning = e.Warning
    

from constants import ER

class MySQLError(Exception):
    

    """Exception related to operation with MySQL."""


class Warning(Warning, MySQLError):

    """Exception raised for important warnings like data truncations
    while inserting, etc."""
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
133
134
135
136


137
138
139
140
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140
141







-
+












-
+










-
+
+




           ER.NO_REFERENCED_ROW_2, ER.ROW_IS_REFERENCED, ER.ROW_IS_REFERENCED_2,
           ER.CANNOT_ADD_FOREIGN)
_map_error(NotSupportedError, ER.WARNING_NOT_COMPLETE_ROLLBACK,
           ER.NOT_SUPPORTED_YET, ER.FEATURE_DISABLED, ER.UNKNOWN_STORAGE_ENGINE)

del _map_error, ER

    

def _get_error_info(data):
    errno = struct.unpack('<h', data[1:3])[0]
    if data[3] == "#":
        # version 4.1
        sqlstate = data[4:9].decode("utf8")
        errorvalue = data[9:].decode("utf8")
        return (errno, sqlstate, errorvalue)
    else:
        # version 4.0
        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)

    # couldn't find the right error number
    raise InternalError, (errno, errorvalue)

def raise_mysql_exception(data):
    errinfo = _get_error_info(data)
    _check_mysql_exception(errinfo)