-
Notifications
You must be signed in to change notification settings - Fork 19
/
exception_generator.py
207 lines (201 loc) · 5.66 KB
/
exception_generator.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env python
import time
import sys
file_template = """
/* generated on %(when)s */
enum _oursqlx_exception_type _oursqlx_exc_from_errno(int err) {
switch (err) {
%(code)s
default:
if (err >= ER_ERROR_FIRST && err <= ER_ERROR_LAST)
return _oursqlx_ProgrammingError;
else if (err > CR_MIN_ERROR && err < CR_MAX_ERROR)
return _oursqlx_InterfaceError;
}
return _oursqlx_UnknownError;
}
"""
case_template = """
#ifdef %(const)s
case %(const)s:
#endif
"""
return_template = """
return %(exc)s;
"""
data = dict(
_oursqlx_DataError="""
CR_DATA_TRUNCATED
ER_DIVISION_BY_ZERO
ER_DUPLICATED_VALUE_IN_TYPE
ER_TRUNCATED_WRONG_VALUE
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
ER_WARN_DATA_OUT_OF_RANGE
ER_WARN_NULL_TO_NOTNULL
ER_WRONG_VALUE
""",
_oursqlx_IntegrityError="""
ER_DROP_INDEX_FK
ER_DUP_ENTRY
ER_DUP_ENTRY_AUTOINCREMENT_CASE
ER_DUP_UNIQUE
ER_FOREIGN_DUPLICATE_KEY
ER_NO_REFERENCED_ROW
ER_NO_REFERENCED_ROW_2
ER_ROW_IS_REFERENCED
ER_ROW_IS_REFERENCED_2
""",
_oursqlx_InternalError="""
ER_DUP_KEY
ER_FILSORT_ABORT
ER_KEY_NOT_FOUND
""",
_oursqlx_NotSupportedError="""
CR_NOT_IMPLEMENTED
ER_CHECK_NOT_IMPLEMENTED
ER_DELAYED_NOT_SUPPORTED
ER_DUMP_NOT_IMPLEMENTED
ER_FOREIGN_KEY_ON_PARTITIONED
ER_ILLEGAL_HA
ER_ILLEGAL_HA_CREATE_OPTION
ER_ILLEGAL_REFERENCE
ER_NDB_CANT_SWITCH_BINLOG_FORMAT
ER_NOT_SUPPORTED_AUTH_MODE
ER_NOT_SUPPORTED_YET
ER_NO_RAID_COMPILED
ER_NULL_COLUMN_IN_INDEX
ER_PARTITION_FUNCTION_FAILURE
ER_SLAVE_IGNORED_SSL_PARAMS
ER_SP_NO_AGGREGATE
ER_SP_SUBSELECT_NYI
ER_TABLESPACE_AUTO_EXTEND_ERROR
ER_TABLE_CANT_HANDLE_AUTO_INCREMENT
ER_TABLE_CANT_HANDLE_BLOB
ER_TABLE_CANT_HANDLE_FT
ER_TABLE_CANT_HANDLE_SPKEYS
ER_UNSUPPORTED_EXTENSION
ER_UNSUPPORTED_PS
ER_WARN_ENGINE_TRANSACTION_ROLLBACK
""",
_oursqlx_OperationalError="""
CR_SERVER_GONE_ERROR
CR_SERVER_LOST
ER_ABORTING_CONNECTION
ER_ALTER_FILEGROUP_FAILED
ER_AUTOINC_READ_FAILED
ER_BINLOG_PURGE_FATAL_ERR
ER_BINLOG_ROW_LOGGING_FAILED
ER_CANNOT_USER
ER_CANT_CREATE_DB
ER_CANT_CREATE_FILE
ER_CANT_CREATE_HANDLER_FILE
ER_CANT_CREATE_TABLE
ER_CANT_CREATE_THREAD
ER_CANT_DELETE_FILE
ER_CANT_FIND_SYSTEM_REC
ER_CANT_GET_STAT
ER_CANT_GET_WD
ER_CANT_LOCK
ER_CANT_OPEN_FILE
ER_CANT_OPEN_LIBRARY
ER_CANT_READ_DIR
ER_CANT_SET_WD
ER_CHECKREAD
ER_CONFLICT_FN_PARSE_ERROR
ER_CONNECT_TO_MASTER
ER_CRASHED_ON_REPAIR
ER_CRASHED_ON_USAGE
ER_CREATE_FILEGROUP_FAILED
ER_DB_DROP_DELETE
ER_DB_DROP_RMDIR
ER_DDL_LOG_ERROR
ER_DISK_FULL
ER_DROP_FILEGROUP_FAILED
ER_ERROR_DURING_CHECKPOINT
ER_ERROR_DURING_COMMIT
ER_ERROR_DURING_FLUSH_LOGS
ER_ERROR_DURING_ROLLBACK
ER_ERROR_ON_CLOSE
ER_ERROR_ON_READ
ER_ERROR_ON_RENAME
ER_ERROR_ON_WRITE
ER_ERROR_WHEN_EXECUTING_COMMAND
ER_EVENT_CANNOT_DELETE
ER_EVENT_CANT_ALTER
ER_EVENT_COMPILE_ERROR
ER_EVENT_DROP_FAILED
ER_EVENT_MODIFY_QUEUE_ERROR
ER_EVENT_OPEN_TABLE_FAILED
ER_EVENT_SET_VAR_ERROR
ER_EVENT_STORE_FAILED
ER_EXCEPTIONS_WRITE_ERROR
ER_FAILED_ROUTINE_BREAK_BINLOG
ER_FILE_NOT_FOUND
ER_FILE_USED
ER_FSEEK_FAIL
ER_GET_ERRMSG
ER_GET_ERRNO
ER_GET_TEMPORARY_ERRMSG
ER_INDEX_REBUILD
ER_IO_ERR_LOG_INDEX_READ
ER_LOG_PURGE_UNKNOWN_ERR
ER_MASTER
ER_MASTER_FATAL_ERROR_READING_BINLOG
ER_MASTER_INFO
ER_MASTER_NET_READ
ER_MASTER_NET_WRITE
ER_NET_ERROR_ON_WRITE
ER_NET_FCNTL_ERROR
ER_NET_PACKETS_OUT_OF_ORDER
ER_NET_READ_ERROR
ER_NET_READ_ERROR_FROM_PIPE
ER_NET_READ_INTERRUPTED
ER_NET_UNCOMPRESS_ERROR
ER_NET_WRITE_INTERRUPTED
ER_NO_FILE_MAPPING
ER_PROC_AUTO_GRANT_FAIL
ER_PROC_AUTO_REVOKE_FAIL
ER_QUERY_ON_MASTER
ER_REGEXP_ERROR
ER_RELAY_LOG_FAIL
ER_RELAY_LOG_INIT
ER_SLAVE_THREAD
ER_SP_CANT_ALTER
ER_SP_DROP_FAILED
ER_SP_PROC_TABLE_CORRUPT
ER_SP_STORE_FAILED
ER_UNEXPECTED_EOF
ER_VIEW_CHECKSUM
ER_WARNING_NOT_COMPLETE_ROLLBACK
ER_WSAS_FAILED
ER_XAER_RMERR
""",
_oursqlx_PermissionsError="""
ER_ACCESS_DENIED_ERROR
ER_BINLOG_CREATE_ROUTINE_NEED_SUPER
ER_CANT_CREATE_USER_WITH_GRANT
ER_COLUMNACCESS_DENIED_ERROR
ER_DBACCESS_DENIED_ERROR
ER_HOST_NOT_PRIVILEGED
ER_KILL_DENIED_ERROR
ER_NO_PERMISSION_TO_CREATE_USER
ER_PASSWORD_NOT_ALLOWED
ER_PROCACCESS_DENIED_ERROR
ER_SPECIFIC_ACCESS_DENIED_ERROR
ER_TABLEACCESS_DENIED_ERROR
ER_VIEW_NO_EXPLAIN
ER_VIEW_OTHER_USER
""",
)
def main(outfile):
output = []
for exc, consts in sorted(data.iteritems()):
for const in consts.split():
output.append(case_template % dict(const=const))
output.append(return_template % dict(exc=exc))
outfile.write(file_template % dict(
when=time.asctime(),
code=''.join(output),
))
if __name__ == '__main__':
main(open(sys.argv[1], 'wb'))