[pywin32-checkins] pywin32/win32/src odbc.cpp,1.19,1.20
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2007-06-29 16:21:31
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6659/win32/src Modified Files: odbc.cpp Log Message: Prevent a crash when attempting to reestablish a dropped database connection Index: odbc.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/odbc.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** odbc.cpp 30 May 2007 06:08:04 -0000 1.19 --- odbc.cpp 29 Jun 2007 16:21:32 -0000 1.20 *************** *** 195,199 **** if (conn && errorType && (errorType->connected == 0)) { - // printf("Disconnected\n"); SQLDisconnect(conn->hdbc); conn->connected = 0; --- 195,198 ---- *************** *** 250,257 **** { /* ie the cursor was made on an old connection */ ! ! printf("Attempting reconnect\n"); ! SQLFreeStmt(cur->hstmt, SQL_DROP); ! if (cur->my_conx->connected == 0) { --- 249,258 ---- { /* ie the cursor was made on an old connection */ ! /* Do not need to free HSTMT here, since any statements attached to the connection ! are automatically invalidated when SQLDisconnect is called in odbcPrintError. ! (only place where connected is set to 0) ! SQLFreeStmt(cur->hstmt, SQL_DROP); ! */ ! cur->hstmt=NULL; if (cur->my_conx->connected == 0) { *************** *** 376,384 **** cur->my_conx = 0; cur->bGetDataIsNeeded = false; if (unsuccessful(SQLAllocStmt(conn->hdbc, &cur->hstmt))) { connectionError(cur->my_conx, "OPEN"); ! PyObject_Del(cur); ! return 0; } cur->my_conx = conn; --- 377,387 ---- cur->my_conx = 0; cur->bGetDataIsNeeded = false; + cur->hstmt=NULL; + if (unsuccessful(SQLAllocStmt(conn->hdbc, &cur->hstmt))) { connectionError(cur->my_conx, "OPEN"); ! Py_DECREF(cur); ! return NULL; } cur->my_conx = conn; *************** *** 463,470 **** { cursorObject *cur = cursor(self); ! if (SQLFreeStmt(cur->hstmt, SQL_DROP)) ! { ! cursorError(cur, "CLOSE"); ! } deleteBinding(cur); if (cur->my_conx) --- 466,473 ---- { cursorObject *cur = cursor(self); ! /* Only free HSTMT if database connection hasn't been disconnected */ ! if (cur->my_conx && cur->my_conx->connected && cur->hstmt) ! SQLFreeHandle(SQL_HANDLE_STMT, cur->hstmt); ! deleteBinding(cur); if (cur->my_conx) *************** *** 866,870 **** strcpy(ib->bind_area, val); ! int sqlType = SQL_VARCHAR; // SQL_CHAR can cause padding in some drivers.. if (len > 255) { --- 869,873 ---- strcpy(ib->bind_area, val); ! int sqlType = SQL_VARCHAR; /* SQL_CHAR can cause padding in some drivers.. */ if (len > 255) { *************** *** 910,914 **** wcscpy((WCHAR *)ib->bind_area, wval); ! // See above re SQL_VARCHAR int sqlType = SQL_WVARCHAR; if (nbytes > 255) --- 913,917 ---- wcscpy((WCHAR *)ib->bind_area, wval); ! /* See above re SQL_VARCHAR */ int sqlType = SQL_WVARCHAR; if (nbytes > 255) *************** *** 1771,1776 **** { connectionError(conn, "ALLOCATION"); ! PyObject_Del(conn); ! return 0; } --- 1774,1779 ---- { connectionError(conn, "ALLOCATION"); ! Py_DECREF(conn); ! return NULL; } *************** *** 1779,1784 **** if (doConnect(conn)) { ! PyObject_Del(conn); ! return 0; } --- 1782,1787 ---- if (doConnect(conn)) { ! Py_DECREF(conn); ! return NULL; } *************** *** 1787,1795 **** /* @pymethod (name, desc)/None|odbc|SQLDataSources|Enumerates ODBC data sources */ ! // @rdesc The result is None when SQL_NO_DATA is returned from ODBC. static PyObject *odbcSQLDataSources(PyObject *self, PyObject *args) { int direction; ! // @pyparm int|direction|| if (!PyArg_ParseTuple(args, "i:SQLDataSources", &direction)) return NULL; --- 1790,1798 ---- /* @pymethod (name, desc)/None|odbc|SQLDataSources|Enumerates ODBC data sources */ ! /* @rdesc The result is None when SQL_NO_DATA is returned from ODBC. */ static PyObject *odbcSQLDataSources(PyObject *self, PyObject *args) { int direction; ! /* @pyparm int|direction||One of SQL_FETCH_* flags indicating how to retrieve data sources */ if (!PyArg_ParseTuple(args, "i:SQLDataSources", &direction)) return NULL; |