[pywin32-checkins] pywin32/win32/src dbi.cpp, 1.10.2.1, 1.10.2.2 odbc.cpp, 1.20.2.1, 1.20.2.2
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2008-09-06 22:33:11
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24296 Modified Files: Tag: py3k dbi.cpp odbc.cpp Log Message: Call PyType_Ready for types defined in module Add constants with unicode names Change string exceptions to real exceptions Index: odbc.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/odbc.cpp,v retrieving revision 1.20.2.1 retrieving revision 1.20.2.2 diff -C2 -d -r1.20.2.1 -r1.20.2.2 *** odbc.cpp 29 Aug 2008 04:59:26 -0000 1.20.2.1 --- odbc.cpp 6 Sep 2008 22:33:20 -0000 1.20.2.2 *************** *** 755,761 **** static int ibindLong(cursorObject*cur,int column, PyObject *item) { ! int len = sizeof(double); ! double val = PyLong_AsDouble(item); ! InputBinding *ib = initInputBinding(cur, len); if (!ib) --- 755,762 ---- static int ibindLong(cursorObject*cur,int column, PyObject *item) { ! int len = sizeof(long long); ! long long val = PyLong_AsLongLong(item); ! if (val == -1 && PyErr_Occurred()) ! return 0; InputBinding *ib = initInputBinding(cur, len); if (!ib) *************** *** 768,773 **** column, SQL_PARAM_INPUT, ! SQL_C_DOUBLE, ! SQL_FLOAT, len, 0, --- 769,774 ---- column, SQL_PARAM_INPUT, ! SQL_C_SBIGINT, ! SQL_BIGINT, len, 0, *************** *** 1073,1078 **** { PyObject *sitem = PyObject_Str(item); ! rv = ibindString(cur, iCol, sitem); ! Py_DECREF(sitem); } Py_DECREF(item); --- 1074,1088 ---- { PyObject *sitem = PyObject_Str(item); ! if (sitem==NULL) ! rv = 0; ! else if PyString_Check(sitem) ! rv = ibindString(cur, iCol, sitem); ! else if PyUnicode_Check(sitem) ! rv = ibindUnicode(cur, iCol, sitem); ! else{ // Just in case some object doesn't follow the rules ! PyErr_Format(PyExc_SystemError, "??? Repr for type '%s' returned type '%s' ???", item->ob_type, sitem->ob_type); ! rv=0; ! } ! Py_XDECREF(sitem); } Py_DECREF(item); *************** *** 1875,1880 **** } else ret = Py_BuildValue("NN", ! PyString_FromStringAndSize((char *)svr, svr_size), ! PyString_FromStringAndSize((char *)desc, desc_size)); return ret; } --- 1885,1890 ---- } else ret = Py_BuildValue("NN", ! PyWinObject_FromTCHAR((TCHAR *)svr, svr_size), ! PyWinObject_FromTCHAR((TCHAR *)desc, desc_size)); return ret; } *************** *** 1887,1906 **** }; - int AddConstant(PyObject *dict, char *key, long value) - { - PyObject *okey = PyString_FromString(key); - PyObject *oval = PyInt_FromLong(value); - if (!okey || !oval) { - Py_XDECREF(okey); - Py_XDECREF(oval); - return 1; - } - int rc = PyDict_SetItem(dict,okey, oval); - Py_XDECREF(okey); - Py_XDECREF(oval); - return rc; - } - #define ADD_CONSTANT(tok) AddConstant(dict,#tok, tok) extern "C" __declspec(dllexport) --- 1897,1902 ---- }; + #define ADD_CONSTANT(tok) if (PyModule_AddIntConstant(module, #tok, tok) == -1) RETURN_ERROR; extern "C" __declspec(dllexport) *************** *** 1915,1928 **** #if (PY_VERSION_HEX < 0x03000000) module = Py_InitModule("odbc", globalMethods); - if (!module) - return; - dict = PyModule_GetDict(module); - if (!dict) - return; - if (!PyImport_ImportModule("dbi")) - return; #else static PyModuleDef odbc_def = { PyModuleDef_HEAD_INIT, --- 1911,1919 ---- #if (PY_VERSION_HEX < 0x03000000) + #define RETURN_ERROR return; module = Py_InitModule("odbc", globalMethods); #else + #define RETURN_ERROR return NULL; static PyModuleDef odbc_def = { PyModuleDef_HEAD_INIT, *************** *** 1933,1952 **** }; module = PyModule_Create(&odbc_def); if (!module) ! return NULL; dict = PyModule_GetDict(module); if (!dict) ! return NULL; if (!PyImport_ImportModule("dbi")) ! return NULL; ! #endif if (unsuccessful(SQLAllocEnv(&Env))) { odbcPrintError(SQL_NULL_HENV, 0, SQL_NULL_HSTMT, _T("INIT")); } ! odbcError = PyString_FromString("OdbcError"); ! PyDict_SetItemString(dict, "error", odbcError); /* The indices go to indices in the ODBC error table */ --- 1924,1946 ---- }; module = PyModule_Create(&odbc_def); + #endif + if (!module) ! RETURN_ERROR; dict = PyModule_GetDict(module); if (!dict) ! RETURN_ERROR; if (!PyImport_ImportModule("dbi")) ! RETURN_ERROR; if (unsuccessful(SQLAllocEnv(&Env))) { odbcPrintError(SQL_NULL_HENV, 0, SQL_NULL_HSTMT, _T("INIT")); + RETURN_ERROR; } ! odbcError = PyErr_NewException("odbc.odbcError", NULL, NULL); ! if (odbcError == NULL || PyDict_SetItemString(dict, "error", odbcError) == -1) ! RETURN_ERROR; /* The indices go to indices in the ODBC error table */ Index: dbi.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/dbi.cpp,v retrieving revision 1.10.2.1 retrieving revision 1.10.2.2 diff -C2 -d -r1.10.2.1 -r1.10.2.2 *** dbi.cpp 29 Aug 2008 04:59:26 -0000 1.10.2.1 --- dbi.cpp 6 Sep 2008 22:33:20 -0000 1.10.2.2 *************** *** 361,371 **** #if (PY_VERSION_HEX < 0x03000000) module = Py_InitModule("dbi", globalMethods); ! if (!module) ! return; ! dict = PyModule_GetDict(module); ! if (!dict) ! return; #else static PyModuleDef dbi_def = { PyModuleDef_HEAD_INIT, --- 361,369 ---- #if (PY_VERSION_HEX < 0x03000000) + #define RETURN_ERROR return; module = Py_InitModule("dbi", globalMethods); ! #else + #define RETURN_ERROR return NULL; static PyModuleDef dbi_def = { PyModuleDef_HEAD_INIT, *************** *** 376,424 **** }; module = PyModule_Create(&dbi_def); if (!module) ! return NULL; dict = PyModule_GetDict(module); if (!dict) ! return NULL; ! #endif ! PyDict_SetItemString(dict, "STRING", ! DbiString = PyString_FromString("STRING")); ! PyDict_SetItemString(dict, "RAW", ! DbiRaw = PyString_FromString("RAW")); ! PyDict_SetItemString(dict, "NUMBER", ! DbiNumber = PyString_FromString("NUMBER")); ! PyDict_SetItemString(dict, "DATE", ! DbiDate = PyString_FromString("DATE")); ! PyDict_SetItemString(dict, "ROWID", ! DbiRowId = PyString_FromString("ROWID")); ! PyDict_SetItemString( ! dict, "TYPES", ! Py_BuildValue("(OOOOO)", ! DbiString, ! DbiRaw, ! DbiNumber, ! DbiDate, ! DbiRowId)); ! /* Establish errors */ ! PyDict_SetItemString( ! dict, "noError", ! DbiNoError = PyString_FromString("dbi.no-error")); ! PyDict_SetItemString( ! dict, "opError", ! DbiOpError = PyString_FromString("dbi.operation-error")); ! PyDict_SetItemString( ! dict, "progError", ! DbiProgError = PyString_FromString("dbi.program-error")); ! PyDict_SetItemString( ! dict, "integrityError", ! DbiIntegrityError = PyString_FromString("dbi.integrity-error")); ! PyDict_SetItemString( ! dict, "dataError", ! DbiDataError = PyString_FromString("dbi.data-error")); ! PyDict_SetItemString( ! dict, "internalError", ! DbiInternalError = PyString_FromString("dbi.internal-error")); #if (PY_VERSION_HEX >= 0x03000000) --- 374,451 ---- }; module = PyModule_Create(&dbi_def); + #endif + if (!module) ! RETURN_ERROR; dict = PyModule_GetDict(module); if (!dict) ! RETURN_ERROR; ! if (PyType_Ready(&DbiDate_Type) == -1 ! ||PyType_Ready(&DbiRaw_Type) == -1 ! ||PyType_Ready(&DbiRowId_Type) == -1) ! RETURN_ERROR; ! /* These need to be unicode strings in Py3k and char strings in 2.x regardless if UNICODE ! is defined. Py_BuildValue with 's' format is a convenient way to do so. ! ??? Why expose them in multiple ways ??? ! */ ! char *szDbiString = "STRING"; ! char *szDbiRaw = "RAW"; ! char *szDbiNumber = "NUMBER"; ! char *szDbiDate = "DATE"; ! char *szDbiRowId = "ROWID"; ! PyObject *obtypes=Py_BuildValue("(sssss)", ! szDbiString, ! szDbiRaw, ! szDbiNumber, ! szDbiDate, ! szDbiRowId); ! // Steals a ref to obtypes, so it doesn't need to be DECREF'ed. ! if (obtypes==NULL || PyModule_AddObject(module, "TYPES", obtypes) == -1) ! RETURN_ERROR; ! // These are exported and used in odbc.cpp, so keep our own ref ! DbiString = PyTuple_GET_ITEM(obtypes, 0); ! Py_INCREF(DbiString); ! DbiRaw = PyTuple_GET_ITEM(obtypes, 1); ! Py_INCREF(DbiRaw); ! DbiNumber = PyTuple_GET_ITEM(obtypes, 2); ! Py_INCREF(DbiNumber); ! DbiDate = PyTuple_GET_ITEM(obtypes, 3); ! Py_INCREF(DbiDate); ! DbiRowId = PyTuple_GET_ITEM(obtypes, 4); ! Py_INCREF(DbiRowId); ! /* ??? These are also added to the module with attribute name same as value, ! not sure what the point of this is ??? ! */ ! if (PyDict_SetItem(dict, DbiString, DbiString) == -1 ! ||PyDict_SetItem(dict, DbiRaw, DbiRaw) == -1 ! ||PyDict_SetItem(dict, DbiNumber, DbiNumber) == -1 ! ||PyDict_SetItem(dict, DbiDate, DbiDate) == -1 ! ||PyDict_SetItem(dict, DbiRowId, DbiRowId) == -1) ! RETURN_ERROR; ! ! /* Establish errors ! The class names have been changed to agree with the name with which they are added to the module. ! Formerly they were actually invalid identifiers. ! */ ! DbiNoError = PyErr_NewException("dbi.noError", NULL, NULL); ! if (DbiNoError == NULL || PyDict_SetItemString(dict, "noError", DbiNoError) == -1) ! RETURN_ERROR; ! DbiOpError = PyErr_NewException("dbi.opError", NULL, NULL); ! if (DbiOpError == NULL || PyDict_SetItemString(dict, "opError", DbiOpError) == -1) ! RETURN_ERROR; ! DbiProgError = PyErr_NewException("dbi.progError", NULL, NULL); ! if (DbiProgError == NULL || PyDict_SetItemString(dict, "progError", DbiProgError) == -1) ! RETURN_ERROR; ! DbiIntegrityError = PyErr_NewException("dbi.integrityError", NULL, NULL); ! if (DbiIntegrityError == NULL || PyDict_SetItemString(dict, "integrityError", DbiIntegrityError) == -1) ! RETURN_ERROR; ! DbiDataError = PyErr_NewException("dbi.dataError", NULL, NULL); ! if (DbiDataError == NULL || PyDict_SetItemString(dict, "dataError", DbiDataError) == -1) ! RETURN_ERROR; ! DbiInternalError = PyErr_NewException("dbi.internalError", NULL, NULL); ! if (DbiInternalError == NULL || PyDict_SetItemString(dict, "internalError", DbiInternalError) == -1) ! RETURN_ERROR; #if (PY_VERSION_HEX >= 0x03000000) |