comparison _mysql.c @ 38:0da42144a012 MySQLdb

Use Py_InitModule3 since we were were doing the same as the #define for the extra arguments; remove trailing whitespaces; ditch another pre-python-2.3 #ifdef .
author kylev
date Fri, 13 Feb 2009 08:10:00 +0000
parents d301c95d8fd7
children 78e810705b3d
comparison
equal deleted inserted replaced
37:df4d804244ec 38:0da42144a012
1 /* -*- mode: C; indent-tabs-mode: t; c-basic-offset: 8; -*- */
2
1 #include "_mysql.h" 3 #include "_mysql.h"
2 4
3 PyObject *_mysql_MySQLError; 5 PyObject *_mysql_MySQLError;
4 PyObject *_mysql_Warning; 6 PyObject *_mysql_Warning;
5 PyObject *_mysql_Error; 7 PyObject *_mysql_Error;
6 PyObject *_mysql_DatabaseError; 8 PyObject *_mysql_DatabaseError;
7 PyObject *_mysql_InterfaceError; 9 PyObject *_mysql_InterfaceError;
8 PyObject *_mysql_DataError; 10 PyObject *_mysql_DataError;
9 PyObject *_mysql_OperationalError; 11 PyObject *_mysql_OperationalError;
10 PyObject *_mysql_IntegrityError; 12 PyObject *_mysql_IntegrityError;
11 PyObject *_mysql_InternalError; 13 PyObject *_mysql_InternalError;
12 PyObject *_mysql_ProgrammingError; 14 PyObject *_mysql_ProgrammingError;
13 PyObject *_mysql_NotSupportedError; 15 PyObject *_mysql_NotSupportedError;
14 PyObject *_mysql_error_map; 16 PyObject *_mysql_error_map;
15 17
16 int _mysql_server_init_done = 0; 18 int _mysql_server_init_done = 0;
53 PyTuple_SET_ITEM(t, 1, PyString_FromString(mysql_error(&(c->connection)))); 55 PyTuple_SET_ITEM(t, 1, PyString_FromString(mysql_error(&(c->connection))));
54 PyErr_SetObject(e, t); 56 PyErr_SetObject(e, t);
55 Py_DECREF(t); 57 Py_DECREF(t);
56 return NULL; 58 return NULL;
57 } 59 }
58 60
59 static char _mysql_server_init__doc__[] = 61 static char _mysql_server_init__doc__[] =
60 "Initialize embedded server. If this client is not linked against\n\ 62 "Initialize embedded server. If this client is not linked against\n\
61 the embedded server library, this function does nothing.\n\ 63 the embedded server library, this function does nothing.\n\
62 \n\ 64 \n\
63 args -- sequence of command-line arguments\n\ 65 args -- sequence of command-line arguments\n\
166 Py_INCREF(Py_None); 168 Py_INCREF(Py_None);
167 return Py_None; 169 return Py_None;
168 } 170 }
169 return _mysql_Exception(NULL); 171 return _mysql_Exception(NULL);
170 } 172 }
171 173
172 #if MYSQL_VERSION_ID >= 32314 174 #if MYSQL_VERSION_ID >= 32314
173 static char _mysql_thread_safe__doc__[] = 175 static char _mysql_thread_safe__doc__[] =
174 "Indicates whether the client is compiled as thread-safe."; 176 "Indicates whether the client is compiled as thread-safe.";
175 177
176 static PyObject *_mysql_thread_safe( 178 static PyObject *_mysql_thread_safe(
262 static PyObject * 264 static PyObject *
263 _mysql_escape_sequence( 265 _mysql_escape_sequence(
264 PyObject *self, 266 PyObject *self,
265 PyObject *args) 267 PyObject *args)
266 { 268 {
267 PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted; 269 PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted;
268 int i, n; 270 int i, n;
269 if (!PyArg_ParseTuple(args, "OO:escape_sequence", &o, &d)) 271 if (!PyArg_ParseTuple(args, "OO:escape_sequence", &o, &d))
270 goto error; 272 goto error;
271 if (!PyMapping_Check(d)) { 273 if (!PyMapping_Check(d)) {
272 PyErr_SetString(PyExc_TypeError, 274 PyErr_SetString(PyExc_TypeError,
296 static PyObject * 298 static PyObject *
297 _mysql_escape_dict( 299 _mysql_escape_dict(
298 PyObject *self, 300 PyObject *self,
299 PyObject *args) 301 PyObject *args)
300 { 302 {
301 PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted, *pkey; 303 PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted, *pkey;
302 Py_ssize_t ppos = 0; 304 Py_ssize_t ppos = 0;
303 if (!PyArg_ParseTuple(args, "O!O:escape_dict", &PyDict_Type, &o, &d)) 305 if (!PyArg_ParseTuple(args, "O!O:escape_dict", &PyDict_Type, &o, &d))
304 goto error; 306 goto error;
305 if (!PyMapping_Check(d)) { 307 if (!PyMapping_Check(d)) {
306 PyErr_SetString(PyExc_TypeError, 308 PyErr_SetString(PyExc_TypeError,
336 extern PyTypeObject _mysql_ConnectionObject_Type; 338 extern PyTypeObject _mysql_ConnectionObject_Type;
337 extern PyTypeObject _mysql_ResultObject_Type; 339 extern PyTypeObject _mysql_ResultObject_Type;
338 340
339 static PyMethodDef 341 static PyMethodDef
340 _mysql_methods[] = { 342 _mysql_methods[] = {
341 { 343 {
342 "connect", 344 "connect",
343 (PyCFunction)_mysql_connect, 345 (PyCFunction)_mysql_connect,
344 METH_VARARGS | METH_KEYWORDS, 346 METH_VARARGS | METH_KEYWORDS,
345 _mysql_connect__doc__ 347 _mysql_connect__doc__
346 }, 348 },
347 { 349 {
348 "debug", 350 "debug",
349 (PyCFunction)_mysql_debug, 351 (PyCFunction)_mysql_debug,
350 METH_VARARGS, 352 METH_VARARGS,
351 _mysql_debug__doc__ 353 _mysql_debug__doc__
352 }, 354 },
353 { 355 {
354 "escape", 356 "escape",
355 (PyCFunction)_mysql_escape, 357 (PyCFunction)_mysql_escape,
356 METH_VARARGS, 358 METH_VARARGS,
357 _mysql_escape__doc__ 359 _mysql_escape__doc__
358 }, 360 },
359 { 361 {
360 "escape_sequence", 362 "escape_sequence",
366 "escape_dict", 368 "escape_dict",
367 (PyCFunction)_mysql_escape_dict, 369 (PyCFunction)_mysql_escape_dict,
368 METH_VARARGS, 370 METH_VARARGS,
369 _mysql_escape_dict__doc__ 371 _mysql_escape_dict__doc__
370 }, 372 },
371 { 373 {
372 "escape_string", 374 "escape_string",
373 (PyCFunction)_mysql_escape_string, 375 (PyCFunction)_mysql_escape_string,
374 METH_VARARGS, 376 METH_VARARGS,
375 _mysql_escape_string__doc__ 377 _mysql_escape_string__doc__
376 }, 378 },
377 { 379 {
378 "string_literal", 380 "string_literal",
379 (PyCFunction)_mysql_string_literal, 381 (PyCFunction)_mysql_string_literal,
380 METH_VARARGS, 382 METH_VARARGS,
381 _mysql_string_literal__doc__ 383 _mysql_string_literal__doc__
382 }, 384 },
442 444
443 DL_EXPORT(void) 445 DL_EXPORT(void)
444 init_mysql(void) 446 init_mysql(void)
445 { 447 {
446 PyObject *dict, *module, *emod, *edict; 448 PyObject *dict, *module, *emod, *edict;
447 module = Py_InitModule4("_mysql", _mysql_methods, _mysql___doc__, 449
448 (PyObject *)NULL, PYTHON_API_VERSION); 450 module = Py_InitModule3("_mysql", _mysql_methods, _mysql___doc__);
449 if (!module) return; /* this really should never happen */ 451 if (!module)
452 return; /* this really should never happen */
453
450 _mysql_ConnectionObject_Type.ob_type = &PyType_Type; 454 _mysql_ConnectionObject_Type.ob_type = &PyType_Type;
451 _mysql_ResultObject_Type.ob_type = &PyType_Type; 455 _mysql_ResultObject_Type.ob_type = &PyType_Type;
452 _mysql_FieldObject_Type.ob_type = &PyType_Type; 456 _mysql_FieldObject_Type.ob_type = &PyType_Type;
453 #if PY_VERSION_HEX >= 0x02020000
454 _mysql_ConnectionObject_Type.tp_alloc = PyType_GenericAlloc; 457 _mysql_ConnectionObject_Type.tp_alloc = PyType_GenericAlloc;
455 _mysql_ConnectionObject_Type.tp_new = PyType_GenericNew; 458 _mysql_ConnectionObject_Type.tp_new = PyType_GenericNew;
456 _mysql_ConnectionObject_Type.tp_free = _PyObject_GC_Del; 459 _mysql_ConnectionObject_Type.tp_free = _PyObject_GC_Del;
457 _mysql_ResultObject_Type.tp_alloc = PyType_GenericAlloc; 460 _mysql_ResultObject_Type.tp_alloc = PyType_GenericAlloc;
458 _mysql_ResultObject_Type.tp_new = PyType_GenericNew; 461 _mysql_ResultObject_Type.tp_new = PyType_GenericNew;
459 _mysql_ResultObject_Type.tp_free = _PyObject_GC_Del; 462 _mysql_ResultObject_Type.tp_free = _PyObject_GC_Del;
460 _mysql_FieldObject_Type.tp_alloc = PyType_GenericAlloc; 463 _mysql_FieldObject_Type.tp_alloc = PyType_GenericAlloc;
461 _mysql_FieldObject_Type.tp_new = PyType_GenericNew; 464 _mysql_FieldObject_Type.tp_new = PyType_GenericNew;
462 _mysql_FieldObject_Type.tp_free = _PyObject_GC_Del; 465 _mysql_FieldObject_Type.tp_free = _PyObject_GC_Del;
463 #endif
464 466
465 if (!(dict = PyModule_GetDict(module))) goto error; 467 if (!(dict = PyModule_GetDict(module))) goto error;
466 if (PyDict_SetItemString(dict, "version_info", 468 if (PyDict_SetItemString(dict, "version_info",
467 PyRun_String(QUOTE(version_info), Py_eval_input, 469 PyRun_String(QUOTE(version_info), Py_eval_input,
468 dict, dict))) 470 dict, dict)))
474 (PyObject *)&_mysql_ConnectionObject_Type)) 476 (PyObject *)&_mysql_ConnectionObject_Type))
475 goto error; 477 goto error;
476 Py_INCREF(&_mysql_ConnectionObject_Type); 478 Py_INCREF(&_mysql_ConnectionObject_Type);
477 if (PyDict_SetItemString(dict, "result", 479 if (PyDict_SetItemString(dict, "result",
478 (PyObject *)&_mysql_ResultObject_Type)) 480 (PyObject *)&_mysql_ResultObject_Type))
479 goto error; 481 goto error;
480 Py_INCREF(&_mysql_ResultObject_Type); 482 Py_INCREF(&_mysql_ResultObject_Type);
481 if (PyDict_SetItemString(dict, "field", 483 if (PyDict_SetItemString(dict, "field",
482 (PyObject *)&_mysql_FieldObject_Type)) 484 (PyObject *)&_mysql_FieldObject_Type))
483 goto error; 485 goto error;
484 Py_INCREF(&_mysql_FieldObject_Type); 486 Py_INCREF(&_mysql_FieldObject_Type);
485 if (!(emod = PyImport_ImportModule("MySQLdb.exceptions"))) 487 if (!(emod = PyImport_ImportModule("MySQLdb.exceptions")))
486 goto error; 488 goto error;
487 if (!(edict = PyModule_GetDict(emod))) goto error; 489 if (!(edict = PyModule_GetDict(emod))) goto error;
488 if (!(_mysql_MySQLError = 490 if (!(_mysql_MySQLError =