comparison _mysql.c @ 39:78e810705b3d MySQLdb

Update some of the constants and declarations to post python-2.0 convenience functions, increase related test coverage.
author kylev
date Sun, 15 Feb 2009 07:26:36 +0000
parents 0da42144a012
children e80676c3505f
comparison
equal deleted inserted replaced
38:0da42144a012 39:78e810705b3d
440 return result objects (MYSQL_RES). Functions which expect MYSQL_RES * as\n\ 440 return result objects (MYSQL_RES). Functions which expect MYSQL_RES * as\n\
441 an argument are now methods of the result object. Deprecated functions\n\ 441 an argument are now methods of the result object. Deprecated functions\n\
442 (as of 3.23) are NOT implemented.\n\ 442 (as of 3.23) are NOT implemented.\n\
443 "; 443 ";
444 444
445 DL_EXPORT(void) 445 PyMODINIT_FUNC
446 init_mysql(void) 446 init_mysql(void)
447 { 447 {
448 PyObject *dict, *module, *emod, *edict; 448 PyObject *dict, *module, *emod, *edict, *version_tuple;
449 449
450 module = Py_InitModule3("_mysql", _mysql_methods, _mysql___doc__); 450 module = Py_InitModule3("_mysql", _mysql_methods, _mysql___doc__);
451 if (!module) 451 if (!module)
452 return; /* this really should never happen */ 452 return; /* this really should never happen */
453 453
454 /* Populate final object settings */
454 _mysql_ConnectionObject_Type.ob_type = &PyType_Type; 455 _mysql_ConnectionObject_Type.ob_type = &PyType_Type;
455 _mysql_ResultObject_Type.ob_type = &PyType_Type; 456 _mysql_ResultObject_Type.ob_type = &PyType_Type;
456 _mysql_FieldObject_Type.ob_type = &PyType_Type; 457 _mysql_FieldObject_Type.ob_type = &PyType_Type;
457 _mysql_ConnectionObject_Type.tp_alloc = PyType_GenericAlloc; 458 _mysql_ConnectionObject_Type.tp_alloc = PyType_GenericAlloc;
458 _mysql_ConnectionObject_Type.tp_new = PyType_GenericNew; 459 _mysql_ConnectionObject_Type.tp_new = PyType_GenericNew;
462 _mysql_ResultObject_Type.tp_free = _PyObject_GC_Del; 463 _mysql_ResultObject_Type.tp_free = _PyObject_GC_Del;
463 _mysql_FieldObject_Type.tp_alloc = PyType_GenericAlloc; 464 _mysql_FieldObject_Type.tp_alloc = PyType_GenericAlloc;
464 _mysql_FieldObject_Type.tp_new = PyType_GenericNew; 465 _mysql_FieldObject_Type.tp_new = PyType_GenericNew;
465 _mysql_FieldObject_Type.tp_free = _PyObject_GC_Del; 466 _mysql_FieldObject_Type.tp_free = _PyObject_GC_Del;
466 467
467 if (!(dict = PyModule_GetDict(module))) goto error; 468 if (!(dict = PyModule_GetDict(module)))
468 if (PyDict_SetItemString(dict, "version_info", 469 goto error;
469 PyRun_String(QUOTE(version_info), Py_eval_input, 470
470 dict, dict))) 471 /* Module constants */
471 goto error; 472 version_tuple = PyRun_String(QUOTE(version_info), Py_eval_input,
472 if (PyDict_SetItemString(dict, "__version__", 473 dict, dict);
473 PyString_FromString(QUOTE(__version__)))) 474 if (PyModule_AddObject(module, "version_info", version_tuple) < 0)
474 goto error; 475 goto error;
476 if (PyModule_AddStringConstant(module, "__version__",
477 QUOTE(__version__)) < 0)
478 goto error;
479 if (PyModule_AddStringConstant(module, "NULL", "NULL") < 0)
480 goto error;
481
482
483 /* Register types */
475 if (PyDict_SetItemString(dict, "connection", 484 if (PyDict_SetItemString(dict, "connection",
476 (PyObject *)&_mysql_ConnectionObject_Type)) 485 (PyObject *)&_mysql_ConnectionObject_Type))
477 goto error; 486 goto error;
478 Py_INCREF(&_mysql_ConnectionObject_Type); 487 Py_INCREF(&_mysql_ConnectionObject_Type);
479 if (PyDict_SetItemString(dict, "result", 488 if (PyDict_SetItemString(dict, "result",
482 Py_INCREF(&_mysql_ResultObject_Type); 491 Py_INCREF(&_mysql_ResultObject_Type);
483 if (PyDict_SetItemString(dict, "field", 492 if (PyDict_SetItemString(dict, "field",
484 (PyObject *)&_mysql_FieldObject_Type)) 493 (PyObject *)&_mysql_FieldObject_Type))
485 goto error; 494 goto error;
486 Py_INCREF(&_mysql_FieldObject_Type); 495 Py_INCREF(&_mysql_FieldObject_Type);
496
497 /* Reach into the exceptions module. */
487 if (!(emod = PyImport_ImportModule("MySQLdb.exceptions"))) 498 if (!(emod = PyImport_ImportModule("MySQLdb.exceptions")))
488 goto error; 499 goto error;
489 if (!(edict = PyModule_GetDict(emod))) goto error; 500 if (!(edict = PyModule_GetDict(emod))) goto error;
490 if (!(_mysql_MySQLError = 501 if (!(_mysql_MySQLError =
491 _mysql_NewException(dict, edict, "MySQLError"))) 502 _mysql_NewException(dict, edict, "MySQLError")))
521 _mysql_NewException(dict, edict, "NotSupportedError"))) 532 _mysql_NewException(dict, edict, "NotSupportedError")))
522 goto error; 533 goto error;
523 if (!(_mysql_error_map = PyDict_GetItemString(edict, "error_map"))) 534 if (!(_mysql_error_map = PyDict_GetItemString(edict, "error_map")))
524 goto error; 535 goto error;
525 Py_DECREF(emod); 536 Py_DECREF(emod);
526 if (!(_mysql_NULL = PyString_FromString("NULL"))) 537
527 goto error;
528 if (PyDict_SetItemString(dict, "NULL", _mysql_NULL)) goto error;
529 error: 538 error:
530 if (PyErr_Occurred()) 539 if (PyErr_Occurred())
531 PyErr_SetString(PyExc_ImportError, 540 PyErr_SetString(PyExc_ImportError,
532 "_mysql: init failed"); 541 "_mysql: init failed");
533 return; 542 return;