Mercurial > p > mysql-python > mysqldb-2
annotate _mysql.c @ 35:e7bd07afbcb9 MySQLdb
Conflict-filled merge from 1.2br for 558:559 set and exception fixes
author | kylev |
---|---|
date | Thu, 12 Feb 2009 00:23:41 +0000 |
parents | d301c95d8fd7 |
children | 0da42144a012 |
rev | line source |
---|---|
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
1 #include "_mysql.h" |
0 | 2 |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
3 PyObject *_mysql_MySQLError; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
4 PyObject *_mysql_Warning; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
5 PyObject *_mysql_Error; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
6 PyObject *_mysql_DatabaseError; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
7 PyObject *_mysql_InterfaceError; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
8 PyObject *_mysql_DataError; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
9 PyObject *_mysql_OperationalError; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
10 PyObject *_mysql_IntegrityError; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
11 PyObject *_mysql_InternalError; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
12 PyObject *_mysql_ProgrammingError; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
13 PyObject *_mysql_NotSupportedError; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
14 PyObject *_mysql_error_map; |
0 | 15 |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
16 int _mysql_server_init_done = 0; |
0 | 17 |
18 PyObject * | |
19 _mysql_Exception(_mysql_ConnectionObject *c) | |
20 { | |
21 PyObject *t, *e; | |
22 int merr; | |
23 | |
24 if (!(t = PyTuple_New(2))) return NULL; | |
25 if (!_mysql_server_init_done) { | |
26 e = _mysql_InternalError; | |
27 PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L)); | |
28 PyTuple_SET_ITEM(t, 1, PyString_FromString("server not initialized")); | |
29 PyErr_SetObject(e, t); | |
30 Py_DECREF(t); | |
31 return NULL; | |
32 } | |
33 merr = mysql_errno(&(c->connection)); | |
34 if (!merr) | |
35 e = _mysql_InterfaceError; | |
36 else if (merr > CR_MAX_ERROR) { | |
37 PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L)); | |
38 PyTuple_SET_ITEM(t, 1, PyString_FromString("error totally whack")); | |
39 PyErr_SetObject(_mysql_InterfaceError, t); | |
40 Py_DECREF(t); | |
41 return NULL; | |
42 } | |
8
fa8974a41c76
New error handling code, plus some small fixes from 1.2
adustman
parents:
5
diff
changeset
|
43 else { |
fa8974a41c76
New error handling code, plus some small fixes from 1.2
adustman
parents:
5
diff
changeset
|
44 PyObject *py_merr = PyInt_FromLong(merr); |
fa8974a41c76
New error handling code, plus some small fixes from 1.2
adustman
parents:
5
diff
changeset
|
45 e = PyDict_GetItem(_mysql_error_map, py_merr); |
fa8974a41c76
New error handling code, plus some small fixes from 1.2
adustman
parents:
5
diff
changeset
|
46 Py_DECREF(py_merr); |
fa8974a41c76
New error handling code, plus some small fixes from 1.2
adustman
parents:
5
diff
changeset
|
47 if (!e) { |
fa8974a41c76
New error handling code, plus some small fixes from 1.2
adustman
parents:
5
diff
changeset
|
48 if (merr < 1000) e = _mysql_InternalError; |
fa8974a41c76
New error handling code, plus some small fixes from 1.2
adustman
parents:
5
diff
changeset
|
49 else e = _mysql_OperationalError; |
fa8974a41c76
New error handling code, plus some small fixes from 1.2
adustman
parents:
5
diff
changeset
|
50 } |
0 | 51 } |
52 PyTuple_SET_ITEM(t, 0, PyInt_FromLong((long)merr)); | |
53 PyTuple_SET_ITEM(t, 1, PyString_FromString(mysql_error(&(c->connection)))); | |
54 PyErr_SetObject(e, t); | |
55 Py_DECREF(t); | |
56 return NULL; | |
57 } | |
58 | |
59 static char _mysql_server_init__doc__[] = | |
60 "Initialize embedded server. If this client is not linked against\n\ | |
61 the embedded server library, this function does nothing.\n\ | |
62 \n\ | |
63 args -- sequence of command-line arguments\n\ | |
64 groups -- sequence of groups to use in defaults files\n\ | |
65 "; | |
66 | |
67 static PyObject *_mysql_server_init( | |
68 PyObject *self, | |
69 PyObject *args, | |
70 PyObject *kwargs) { | |
71 static char *kwlist[] = {"args", "groups", NULL}; | |
72 char **cmd_args_c=NULL, **groups_c=NULL, *s; | |
27
d301c95d8fd7
Apply missing Py_ssize_t conversion caught by spektrum.
kylev
parents:
18
diff
changeset
|
73 Py_ssize_t cmd_argc=0, i, groupc; |
0 | 74 PyObject *cmd_args=NULL, *groups=NULL, *ret=NULL, *item; |
75 | |
76 if (_mysql_server_init_done) { | |
77 PyErr_SetString(_mysql_ProgrammingError, | |
78 "already initialized"); | |
79 return NULL; | |
80 } | |
27
d301c95d8fd7
Apply missing Py_ssize_t conversion caught by spektrum.
kylev
parents:
18
diff
changeset
|
81 |
0 | 82 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", kwlist, |
83 &cmd_args, &groups)) | |
84 return NULL; | |
85 | |
86 #if MYSQL_VERSION_ID >= 40000 | |
87 if (cmd_args) { | |
88 if (!PySequence_Check(cmd_args)) { | |
89 PyErr_SetString(PyExc_TypeError, | |
90 "args must be a sequence"); | |
91 goto finish; | |
92 } | |
93 cmd_argc = PySequence_Size(cmd_args); | |
94 if (cmd_argc == -1) { | |
95 PyErr_SetString(PyExc_TypeError, | |
96 "args could not be sized"); | |
97 goto finish; | |
98 } | |
99 cmd_args_c = (char **) PyMem_Malloc(cmd_argc*sizeof(char *)); | |
100 for (i=0; i< cmd_argc; i++) { | |
101 item = PySequence_GetItem(cmd_args, i); | |
102 s = PyString_AsString(item); | |
103 Py_DECREF(item); | |
104 if (!s) { | |
105 PyErr_SetString(PyExc_TypeError, | |
106 "args must contain strings"); | |
107 goto finish; | |
108 } | |
109 cmd_args_c[i] = s; | |
110 } | |
111 } | |
112 if (groups) { | |
113 if (!PySequence_Check(groups)) { | |
114 PyErr_SetString(PyExc_TypeError, | |
115 "groups must be a sequence"); | |
116 goto finish; | |
117 } | |
118 groupc = PySequence_Size(groups); | |
119 if (groupc == -1) { | |
120 PyErr_SetString(PyExc_TypeError, | |
121 "groups could not be sized"); | |
122 goto finish; | |
123 } | |
124 groups_c = (char **) PyMem_Malloc((1+groupc)*sizeof(char *)); | |
125 for (i=0; i< groupc; i++) { | |
126 item = PySequence_GetItem(groups, i); | |
127 s = PyString_AsString(item); | |
128 Py_DECREF(item); | |
129 if (!s) { | |
130 PyErr_SetString(PyExc_TypeError, | |
131 "groups must contain strings"); | |
132 goto finish; | |
133 } | |
134 groups_c[i] = s; | |
135 } | |
136 groups_c[groupc] = (char *)NULL; | |
137 } | |
138 /* even though this may block, don't give up the interpreter lock | |
139 so that the server can't be initialized multiple times. */ | |
140 if (mysql_server_init(cmd_argc, cmd_args_c, groups_c)) { | |
141 _mysql_Exception(NULL); | |
142 goto finish; | |
143 } | |
144 #endif | |
145 ret = Py_None; | |
146 Py_INCREF(Py_None); | |
147 _mysql_server_init_done = 1; | |
148 finish: | |
149 PyMem_Free(groups_c); | |
150 PyMem_Free(cmd_args_c); | |
151 return ret; | |
152 } | |
153 | |
154 static char _mysql_server_end__doc__[] = | |
155 "Shut down embedded server. If not using an embedded server, this\n\ | |
156 does nothing."; | |
157 | |
158 static PyObject *_mysql_server_end( | |
159 PyObject *self, | |
160 PyObject *args) { | |
161 if (_mysql_server_init_done) { | |
162 #if MYSQL_VERSION_ID >= 40000 | |
163 mysql_server_end(); | |
164 #endif | |
165 _mysql_server_init_done = 0; | |
166 Py_INCREF(Py_None); | |
167 return Py_None; | |
168 } | |
169 return _mysql_Exception(NULL); | |
170 } | |
171 | |
172 #if MYSQL_VERSION_ID >= 32314 | |
173 static char _mysql_thread_safe__doc__[] = | |
174 "Indicates whether the client is compiled as thread-safe."; | |
175 | |
176 static PyObject *_mysql_thread_safe( | |
177 PyObject *self, | |
178 PyObject *args) { | |
179 PyObject *flag; | |
180 if (!PyArg_ParseTuple(args, "")) return NULL; | |
181 check_server_init(NULL); | |
182 if (!(flag=PyInt_FromLong((long)mysql_thread_safe()))) return NULL; | |
183 return flag; | |
184 } | |
185 #endif | |
186 | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
187 extern char _mysql_connect__doc__[]; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
188 PyObject * |
0 | 189 _mysql_connect( |
190 PyObject *self, | |
191 PyObject *args, | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
192 PyObject *kwargs); |
0 | 193 |
194 static char _mysql_debug__doc__[] = | |
195 "Does a DBUG_PUSH with the given string.\n\ | |
196 mysql_debug() uses the Fred Fish debug library.\n\ | |
197 To use this function, you must compile the client library to\n\ | |
198 support debugging.\n\ | |
199 "; | |
200 static PyObject * | |
201 _mysql_debug( | |
202 PyObject *self, | |
203 PyObject *args) | |
204 { | |
205 char *debug; | |
206 if (!PyArg_ParseTuple(args, "s", &debug)) return NULL; | |
207 mysql_debug(debug); | |
208 Py_INCREF(Py_None); | |
209 return Py_None; | |
210 } | |
211 | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
212 extern char _mysql_escape_string__doc__[]; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
213 PyObject * |
0 | 214 _mysql_escape_string( |
215 _mysql_ConnectionObject *self, | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
216 PyObject *args); |
0 | 217 |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
218 extern char _mysql_string_literal__doc__[]; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
219 PyObject * |
0 | 220 _mysql_string_literal( |
221 _mysql_ConnectionObject *self, | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
222 PyObject *args); |
0 | 223 |
224 static PyObject *_mysql_NULL; | |
225 | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
226 PyObject * |
0 | 227 _escape_item( |
228 PyObject *item, | |
229 PyObject *d) | |
230 { | |
231 PyObject *quoted=NULL, *itemtype, *itemconv; | |
232 if (!(itemtype = PyObject_Type(item))) | |
233 goto error; | |
234 itemconv = PyObject_GetItem(d, itemtype); | |
235 Py_DECREF(itemtype); | |
236 if (!itemconv) { | |
237 PyErr_Clear(); | |
238 itemconv = PyObject_GetItem(d, | |
239 (PyObject *) &PyString_Type); | |
240 } | |
241 if (!itemconv) { | |
242 PyErr_SetString(PyExc_TypeError, | |
243 "no default type converter defined"); | |
244 goto error; | |
245 } | |
246 quoted = PyObject_CallFunction(itemconv, "OO", item, d); | |
247 Py_DECREF(itemconv); | |
248 error: | |
249 return quoted; | |
250 } | |
251 | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
252 extern char _mysql_escape__doc__[]; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
253 PyObject * |
0 | 254 _mysql_escape( |
255 PyObject *self, | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
256 PyObject *args); |
0 | 257 |
258 static char _mysql_escape_sequence__doc__[] = | |
259 "escape_sequence(seq, dict) -- escape any special characters in sequence\n\ | |
260 seq using mapping dict to provide quoting functions for each type.\n\ | |
261 Returns a tuple of escaped items."; | |
262 static PyObject * | |
263 _mysql_escape_sequence( | |
264 PyObject *self, | |
265 PyObject *args) | |
266 { | |
267 PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted; | |
268 int i, n; | |
269 if (!PyArg_ParseTuple(args, "OO:escape_sequence", &o, &d)) | |
270 goto error; | |
271 if (!PyMapping_Check(d)) { | |
272 PyErr_SetString(PyExc_TypeError, | |
273 "argument 2 must be a mapping"); | |
274 return NULL; | |
275 } | |
276 if ((n = PyObject_Length(o)) == -1) goto error; | |
277 if (!(r = PyTuple_New(n))) goto error; | |
278 for (i=0; i<n; i++) { | |
279 item = PySequence_GetItem(o, i); | |
280 if (!item) goto error; | |
281 quoted = _escape_item(item, d); | |
282 Py_DECREF(item); | |
283 if (!quoted) goto error; | |
284 PyTuple_SET_ITEM(r, i, quoted); | |
285 } | |
286 return r; | |
287 error: | |
288 Py_XDECREF(r); | |
289 return NULL; | |
290 } | |
291 | |
292 static char _mysql_escape_dict__doc__[] = | |
293 "escape_sequence(d, dict) -- escape any special characters in\n\ | |
294 dictionary d using mapping dict to provide quoting functions for each type.\n\ | |
295 Returns a dictionary of escaped items."; | |
296 static PyObject * | |
297 _mysql_escape_dict( | |
298 PyObject *self, | |
299 PyObject *args) | |
300 { | |
301 PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted, *pkey; | |
5 | 302 Py_ssize_t ppos = 0; |
0 | 303 if (!PyArg_ParseTuple(args, "O!O:escape_dict", &PyDict_Type, &o, &d)) |
304 goto error; | |
305 if (!PyMapping_Check(d)) { | |
306 PyErr_SetString(PyExc_TypeError, | |
307 "argument 2 must be a mapping"); | |
308 return NULL; | |
309 } | |
310 if (!(r = PyDict_New())) goto error; | |
311 while (PyDict_Next(o, &ppos, &pkey, &item)) { | |
312 quoted = _escape_item(item, d); | |
313 if (!quoted) goto error; | |
314 if (PyDict_SetItem(r, pkey, quoted)==-1) goto error; | |
315 Py_DECREF(quoted); | |
316 } | |
317 return r; | |
318 error: | |
319 Py_XDECREF(r); | |
320 return NULL; | |
321 } | |
322 | |
323 static char _mysql_get_client_info__doc__[] = | |
324 "get_client_info() -- Returns a string that represents\n\ | |
325 the client library version."; | |
326 static PyObject * | |
327 _mysql_get_client_info( | |
328 PyObject *self, | |
329 PyObject *args) | |
330 { | |
331 if (!PyArg_ParseTuple(args, "")) return NULL; | |
332 check_server_init(NULL); | |
333 return PyString_FromString(mysql_get_client_info()); | |
334 } | |
335 | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
336 extern PyTypeObject _mysql_ConnectionObject_Type; |
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
337 extern PyTypeObject _mysql_ResultObject_Type; |
0 | 338 |
339 static PyMethodDef | |
340 _mysql_methods[] = { | |
341 { | |
342 "connect", | |
343 (PyCFunction)_mysql_connect, | |
344 METH_VARARGS | METH_KEYWORDS, | |
345 _mysql_connect__doc__ | |
346 }, | |
347 { | |
348 "debug", | |
349 (PyCFunction)_mysql_debug, | |
350 METH_VARARGS, | |
351 _mysql_debug__doc__ | |
352 }, | |
353 { | |
354 "escape", | |
355 (PyCFunction)_mysql_escape, | |
356 METH_VARARGS, | |
357 _mysql_escape__doc__ | |
358 }, | |
359 { | |
360 "escape_sequence", | |
361 (PyCFunction)_mysql_escape_sequence, | |
362 METH_VARARGS, | |
363 _mysql_escape_sequence__doc__ | |
364 }, | |
365 { | |
366 "escape_dict", | |
367 (PyCFunction)_mysql_escape_dict, | |
368 METH_VARARGS, | |
369 _mysql_escape_dict__doc__ | |
370 }, | |
371 { | |
372 "escape_string", | |
373 (PyCFunction)_mysql_escape_string, | |
374 METH_VARARGS, | |
375 _mysql_escape_string__doc__ | |
376 }, | |
377 { | |
378 "string_literal", | |
379 (PyCFunction)_mysql_string_literal, | |
380 METH_VARARGS, | |
381 _mysql_string_literal__doc__ | |
382 }, | |
383 { | |
384 "get_client_info", | |
385 (PyCFunction)_mysql_get_client_info, | |
386 METH_VARARGS, | |
387 _mysql_get_client_info__doc__ | |
388 }, | |
389 #if MYSQL_VERSION_ID >= 32314 | |
390 { | |
391 "thread_safe", | |
392 (PyCFunction)_mysql_thread_safe, | |
393 METH_VARARGS, | |
394 _mysql_thread_safe__doc__ | |
395 }, | |
396 #endif | |
397 { | |
398 "server_init", | |
399 (PyCFunction)_mysql_server_init, | |
400 METH_VARARGS | METH_KEYWORDS, | |
401 _mysql_server_init__doc__ | |
402 }, | |
403 { | |
404 "server_end", | |
405 (PyCFunction)_mysql_server_end, | |
406 METH_VARARGS, | |
407 _mysql_server_end__doc__ | |
408 }, | |
409 {NULL, NULL} /* sentinel */ | |
410 }; | |
411 | |
412 static PyObject * | |
413 _mysql_NewException( | |
414 PyObject *dict, | |
415 PyObject *edict, | |
416 char *name) | |
417 { | |
418 PyObject *e; | |
419 | |
420 if (!(e = PyDict_GetItemString(edict, name))) | |
421 return NULL; | |
422 if (PyDict_SetItemString(dict, name, e)) return NULL; | |
423 return e; | |
424 } | |
425 | |
4 | 426 #define QUOTE(X) _QUOTE(X) |
427 #define _QUOTE(X) #X | |
428 | |
0 | 429 static char _mysql___doc__[] = |
430 "an adaptation of the MySQL C API (mostly)\n\ | |
431 \n\ | |
432 You probably are better off using MySQLdb instead of using this\n\ | |
433 module directly.\n\ | |
434 \n\ | |
435 In general, renaming goes from mysql_* to _mysql.*. _mysql.connect()\n\ | |
436 returns a connection object (MYSQL). Functions which expect MYSQL * as\n\ | |
437 an argument are now methods of the connection object. A number of things\n\ | |
438 return result objects (MYSQL_RES). Functions which expect MYSQL_RES * as\n\ | |
439 an argument are now methods of the result object. Deprecated functions\n\ | |
440 (as of 3.23) are NOT implemented.\n\ | |
441 "; | |
442 | |
443 DL_EXPORT(void) | |
444 init_mysql(void) | |
445 { | |
446 PyObject *dict, *module, *emod, *edict; | |
447 module = Py_InitModule4("_mysql", _mysql_methods, _mysql___doc__, | |
448 (PyObject *)NULL, PYTHON_API_VERSION); | |
449 if (!module) return; /* this really should never happen */ | |
450 _mysql_ConnectionObject_Type.ob_type = &PyType_Type; | |
451 _mysql_ResultObject_Type.ob_type = &PyType_Type; | |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
452 _mysql_FieldObject_Type.ob_type = &PyType_Type; |
0 | 453 #if PY_VERSION_HEX >= 0x02020000 |
454 _mysql_ConnectionObject_Type.tp_alloc = PyType_GenericAlloc; | |
455 _mysql_ConnectionObject_Type.tp_new = PyType_GenericNew; | |
456 _mysql_ConnectionObject_Type.tp_free = _PyObject_GC_Del; | |
457 _mysql_ResultObject_Type.tp_alloc = PyType_GenericAlloc; | |
458 _mysql_ResultObject_Type.tp_new = PyType_GenericNew; | |
459 _mysql_ResultObject_Type.tp_free = _PyObject_GC_Del; | |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
460 _mysql_FieldObject_Type.tp_alloc = PyType_GenericAlloc; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
461 _mysql_FieldObject_Type.tp_new = PyType_GenericNew; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
462 _mysql_FieldObject_Type.tp_free = _PyObject_GC_Del; |
0 | 463 #endif |
464 | |
465 if (!(dict = PyModule_GetDict(module))) goto error; | |
466 if (PyDict_SetItemString(dict, "version_info", | |
4 | 467 PyRun_String(QUOTE(version_info), Py_eval_input, |
0 | 468 dict, dict))) |
469 goto error; | |
470 if (PyDict_SetItemString(dict, "__version__", | |
4 | 471 PyString_FromString(QUOTE(__version__)))) |
0 | 472 goto error; |
473 if (PyDict_SetItemString(dict, "connection", | |
474 (PyObject *)&_mysql_ConnectionObject_Type)) | |
475 goto error; | |
476 Py_INCREF(&_mysql_ConnectionObject_Type); | |
477 if (PyDict_SetItemString(dict, "result", | |
478 (PyObject *)&_mysql_ResultObject_Type)) | |
479 goto error; | |
480 Py_INCREF(&_mysql_ResultObject_Type); | |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
481 if (PyDict_SetItemString(dict, "field", |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
482 (PyObject *)&_mysql_FieldObject_Type)) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
483 goto error; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
484 Py_INCREF(&_mysql_FieldObject_Type); |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
8
diff
changeset
|
485 if (!(emod = PyImport_ImportModule("MySQLdb.exceptions"))) |
0 | 486 goto error; |
487 if (!(edict = PyModule_GetDict(emod))) goto error; | |
488 if (!(_mysql_MySQLError = | |
489 _mysql_NewException(dict, edict, "MySQLError"))) | |
490 goto error; | |
491 if (!(_mysql_Warning = | |
492 _mysql_NewException(dict, edict, "Warning"))) | |
493 goto error; | |
494 if (!(_mysql_Error = | |
495 _mysql_NewException(dict, edict, "Error"))) | |
496 goto error; | |
497 if (!(_mysql_InterfaceError = | |
498 _mysql_NewException(dict, edict, "InterfaceError"))) | |
499 goto error; | |
500 if (!(_mysql_DatabaseError = | |
501 _mysql_NewException(dict, edict, "DatabaseError"))) | |
502 goto error; | |
503 if (!(_mysql_DataError = | |
504 _mysql_NewException(dict, edict, "DataError"))) | |
505 goto error; | |
506 if (!(_mysql_OperationalError = | |
507 _mysql_NewException(dict, edict, "OperationalError"))) | |
508 goto error; | |
509 if (!(_mysql_IntegrityError = | |
510 _mysql_NewException(dict, edict, "IntegrityError"))) | |
511 goto error; | |
512 if (!(_mysql_InternalError = | |
513 _mysql_NewException(dict, edict, "InternalError"))) | |
514 goto error; | |
515 if (!(_mysql_ProgrammingError = | |
516 _mysql_NewException(dict, edict, "ProgrammingError"))) | |
517 goto error; | |
518 if (!(_mysql_NotSupportedError = | |
519 _mysql_NewException(dict, edict, "NotSupportedError"))) | |
520 goto error; | |
8
fa8974a41c76
New error handling code, plus some small fixes from 1.2
adustman
parents:
5
diff
changeset
|
521 if (!(_mysql_error_map = PyDict_GetItemString(edict, "error_map"))) |
fa8974a41c76
New error handling code, plus some small fixes from 1.2
adustman
parents:
5
diff
changeset
|
522 goto error; |
0 | 523 Py_DECREF(emod); |
524 if (!(_mysql_NULL = PyString_FromString("NULL"))) | |
525 goto error; | |
526 if (PyDict_SetItemString(dict, "NULL", _mysql_NULL)) goto error; | |
527 error: | |
528 if (PyErr_Occurred()) | |
529 PyErr_SetString(PyExc_ImportError, | |
530 "_mysql: init failed"); | |
531 return; | |
532 } | |
533 | |
534 |