From: Billy G. A. <bal...@us...> - 2001-09-23 03:58:52
|
Update of /cvsroot/pypgsql/pypgsql In directory usw-pr-cvs1:/tmp/cvs-serv17400 Modified Files: pgconnection.c Log Message: 22SEP2001 bga Fixed bugs uncovered during development of the regression test cases for pgconnection.c. --- Improved the error checking on the mode parameter in lo_creat(). --- Removed lo_get(). It doesn't provide any useful functionality since you never get a Large Object OID from PgResult.getvalue(). You always get a PgLargeObject. Index: pgconnection.c =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/pgconnection.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** pgconnection.c 2001/09/21 03:46:31 1.7 --- pgconnection.c 2001/09/23 03:58:47 1.8 *************** *** 29,32 **** --- 29,39 ---- | Date Ini Description | | --------- --- ------------------------------------------------------- | + | 22SEP2001 bga Fixed bugs uncovered during testing with the new test | + | cases for regression testing. | + | --- Improved the error checking on the mode parameter in | + | lo_creat(). | + | --- Removed lo_get(). It doesn't provide any useful func- | + | tionality since you never get a Large Object's OID from | + | PgResult.getvalue(). You always get a PgLargeObject. | | 20SEP2001 bga [Bug #455514] Modified pgFixEsc to that if will also | | handle octal escape sequences. If the escape sequence | *************** *** 306,315 **** int rtype; - if (!PyArg_ParseTuple(args,"s:query", &query)) - return NULL; - if (!PgConnection_check((PyObject *)self)) return NULL; (void)pgFixEsc(query); --- 313,322 ---- int rtype; if (!PgConnection_check((PyObject *)self)) return NULL; + if (!PyArg_ParseTuple(args,"s:query", &query)) + return NULL; + (void)pgFixEsc(query); *************** *** 362,371 **** int onOff; - if (!PyArg_ParseTuple(args, "i:setnonblocking", &onOff)) - return NULL; - if (!PgConnection_check((PyObject *)self)) return NULL; onOff = ((onOff != 0) ? 1 : 0); --- 369,378 ---- int onOff; if (!PgConnection_check((PyObject *)self)) return NULL; + if (!PyArg_ParseTuple(args, "i:setnonblocking", &onOff)) + return NULL; + onOff = ((onOff != 0) ? 1 : 0); *************** *** 391,400 **** char *query; - if (!PyArg_ParseTuple(args,"s:sendQuery", &query)) - return NULL; - if (!PgConnection_check((PyObject *)self)) return NULL; if (!PQsendQuery(PgConnection_Get(self), query)) { --- 398,407 ---- char *query; if (!PgConnection_check((PyObject *)self)) return NULL; + if (!PyArg_ParseTuple(args,"s:sendQuery", &query)) + return NULL; + if (!PQsendQuery(PgConnection_Get(self), query)) { *************** *** 420,423 **** --- 427,433 ---- int rtype; + if (!PgConnection_check((PyObject *)self)) + return (PyObject *)NULL; + if (!PyArg_ParseTuple(args,"")) { *************** *** 427,433 **** } - if (!PgConnection_check((PyObject *)self)) - return (PyObject *)NULL; - res = PQgetResult(PgConnection_Get(self)); --- 437,440 ---- *************** *** 464,467 **** --- 471,477 ---- static PyObject *libPQconsumeInput(PgConnection *self, PyObject *args) { + if (!PgConnection_check((PyObject *)self)) + return NULL; + if (!PyArg_ParseTuple(args, "")) { *************** *** 471,477 **** } - if (!PgConnection_check((PyObject *)self)) - return NULL; - if (!PQconsumeInput(PgConnection_Get(self))) { --- 481,484 ---- *************** *** 492,495 **** --- 499,505 ---- static PyObject *libPQflush(PgConnection *self, PyObject *args) { + if (!PgConnection_check((PyObject *)self)) + return NULL; + if (!PyArg_ParseTuple(args, "")) { *************** *** 499,505 **** } - if (!PgConnection_check((PyObject *)self)) - return NULL; - if (!PQflush(PgConnection_Get(self))) { --- 509,512 ---- *************** *** 521,534 **** static PyObject *libPQconnectPoll(PgConnection *self, PyObject *args) { if (!PyArg_ParseTuple(args,"")) { PyErr_SetString(PqErr_InterfaceError, ! "getResult() takes no parameters"); return NULL; } - if (!PgConnection_check((PyObject *)self)) - return NULL; - return Py_BuildValue("i", PQconnectPoll(PgConnection_Get(self))); } --- 528,541 ---- static PyObject *libPQconnectPoll(PgConnection *self, PyObject *args) { + if (!PgConnection_check((PyObject *)self)) + return NULL; + if (!PyArg_ParseTuple(args,"")) { PyErr_SetString(PqErr_InterfaceError, ! "connectPoll() takes no parameters"); return NULL; } return Py_BuildValue("i", PQconnectPoll(PgConnection_Get(self))); } *************** *** 544,547 **** --- 551,557 ---- static PyObject *libPQrequestCancel(PgConnection *self, PyObject *args) { + if (!PgConnection_check((PyObject *)self)) + return NULL; + if (!PyArg_ParseTuple(args, "")) { *************** *** 551,557 **** } - if (!PgConnection_check((PyObject *)self)) - return NULL; - if (!PQrequestCancel(PgConnection_Get(self))) { --- 561,564 ---- *************** *** 574,577 **** --- 581,587 ---- static PyObject * libPQfinish(PgConnection *self, PyObject *args) { + if (!PgConnection_check((PyObject *)self)) + return NULL; + if (!PyArg_ParseTuple(args,"")) { *************** *** 581,587 **** } - if (!PgConnection_check((PyObject *)self)) - return NULL; - PQfinish(PgConnection_Get(self)); --- 591,594 ---- *************** *** 602,605 **** --- 609,615 ---- static PyObject *libPQreset(PgConnection *self, PyObject *args) { + if (!PgConnection_check((PyObject *)self)) + return NULL; + if (!PyArg_ParseTuple(args,"")) { *************** *** 609,615 **** } - if (!PgConnection_check((PyObject *)self)) - return NULL; - Py_BEGIN_ALLOW_THREADS PQreset(PgConnection_Get(self)); --- 619,622 ---- *************** *** 637,640 **** --- 644,650 ---- static PyObject *libPQnotifies(PgConnection *self, PyObject *args) { + if (!PgConnection_check((PyObject *)self)) + return (PyObject *)NULL; + if (!PyArg_ParseTuple(args,"")) { *************** *** 644,650 **** } - if (!PgConnection_check((PyObject *)self)) - return (PyObject *)NULL; - return PgNotify_New(PQnotifies(PgConnection_Get(self))); } --- 654,657 ---- *************** *** 662,666 **** PyObject *result; ! PGconn *cnx = PgConnection_Get(self); if (!PyArg_ParseTuple(args,"")) --- 669,674 ---- PyObject *result; ! if (!PgConnection_check((PyObject *)self)) ! return NULL; if (!PyArg_ParseTuple(args,"")) *************** *** 671,676 **** } ! if (!PgConnection_check((PyObject *)self)) ! return NULL; for (size = idx = 0, res = 1; res > 0; idx = (size - 1)) --- 679,683 ---- } ! PGconn *cnx = PgConnection_Get(self); for (size = idx = 0, res = 1; res > 0; idx = (size - 1)) *************** *** 716,720 **** PyObject *result = (PyObject *)NULL; ! PGconn *cnx = PgConnection_Get(self); if (!PyArg_ParseTuple(args,"")) --- 723,728 ---- PyObject *result = (PyObject *)NULL; ! if (!PgConnection_check((PyObject *)self)) ! return NULL; if (!PyArg_ParseTuple(args,"")) *************** *** 725,730 **** } ! if (!PgConnection_check((PyObject *)self)) ! return NULL; for (size = idx = leave = 0; leave; idx = size) --- 733,737 ---- } ! PGconn *cnx = PgConnection_Get(self); for (size = idx = leave = 0; leave; idx = size) *************** *** 785,794 **** int res; - if (!PyArg_ParseTuple(args,"s:putline", &line)) - return NULL; - if (!PgConnection_check((PyObject *)self)) return NULL; Pg_BEGIN_ALLOW_THREADS(PgConnection_Get(self)) res = PQputline(PgConnection_Get(self), line); --- 792,801 ---- int res; if (!PgConnection_check((PyObject *)self)) return NULL; + if (!PyArg_ParseTuple(args,"s:putline", &line)) + return NULL; + Pg_BEGIN_ALLOW_THREADS(PgConnection_Get(self)) res = PQputline(PgConnection_Get(self), line); *************** *** 815,818 **** --- 822,828 ---- int res; + if (!PgConnection_check((PyObject *)self)) + return NULL; + if (!PyArg_ParseTuple(args,"")) { *************** *** 822,828 **** } - if (!PgConnection_check((PyObject *)self)) - return NULL; - Pg_BEGIN_ALLOW_THREADS(PgConnection_Get(self)) res = PQendcopy(PgConnection_Get(self)); --- 832,835 ---- *************** *** 850,858 **** PyObject *out; - if (!PyArg_ParseTuple(args,"O!:trace", &PyFile_Type, &out)) - return NULL; - if (!PgConnection_check((PyObject *)self)) return NULL; PQtrace(PgConnection_Get(self), PyFile_AsFile(out)); --- 857,865 ---- PyObject *out; if (!PgConnection_check((PyObject *)self)) return NULL; + + if (!PyArg_ParseTuple(args,"O!:trace", &PyFile_Type, &out)) + return NULL; PQtrace(PgConnection_Get(self), PyFile_AsFile(out)); *************** *** 869,872 **** --- 876,882 ---- static PyObject *libPQuntrace(PgConnection *self, PyObject *args) { + if (!PgConnection_check((PyObject *)self)) + return NULL; + if (!PyArg_ParseTuple(args,"")) { *************** *** 876,882 **** } - if (!PgConnection_check((PyObject *)self)) - return NULL; - PQuntrace(PgConnection_Get(self)); --- 886,889 ---- *************** *** 887,890 **** --- 894,907 ---- /*--------------------------------------------------------------------------*/ + /* The following define is only used internally, to track if the 'b' + * flag in the mode is seen. + */ + #define INV_BIN 0x00010000 + + extern struct { + char *name; + int mode; + } validmodes[]; + static char PgLo_creat_Doc[] = "lo_creat(mode) -- Creates a PgLargeObject with the attribues given in " *************** *** 894,929 **** { Oid oid; ! int mode; /* mode */ ! ! if (!PyArg_ParseTuple(args,"i:lo_creat", &mode)) ! return (PyObject *)NULL; if (!PgConnection_check((PyObject *)self)) return (PyObject *)NULL; ! if (!(oid = lo_creat(PgConnection_Get(self), mode))) { ! PyErr_SetString(PqErr_OperationalError, "Can't create large object."); ! return (PyObject *)NULL; } - - return PgLargeObject_New((PyObject *)self, oid); - } ! /*--------------------------------------------------------------------------*/ ! static char PgLo_get_Doc[] = ! "lo_get(oid, mode) -- Creates a PgLargeObject instance for oid and mode."; ! static PyObject *PgLo_get(PgConnection *self, PyObject *args) ! { ! Oid oid; /* Large Object OID */ ! if (!PyArg_ParseTuple(args,"i:lo_get", &oid)) ! return (PyObject *)NULL; ! if (!PgConnection_check((PyObject *)self)) return (PyObject *)NULL; ! return PgLargeObject_New((PyObject *)self, oid); } --- 911,965 ---- { Oid oid; ! int i; ! int mode; /* mode */ ! char *mname; /* mode (as string) */ if (!PgConnection_check((PyObject *)self)) return (PyObject *)NULL; ! mname = (char *)NULL; ! mode = 0; ! ! if (!PyArg_ParseTuple(args,"s:lo_creat", &mname)) { ! PyErr_Clear(); ! if (!PyArg_ParseTuple(args, "i:lo_creat", &mode)) ! return (PyObject *)NULL; } ! if (mname != (char *)NULL) ! for (i = 0; validmodes[i].name != (char *)NULL; i++) ! if (strcmp(mname, validmodes[i].name) == 0) ! { ! mode = validmodes[i].mode; ! break; ! } ! /* This loop will look up the text version of mode, if passed in as an ! * integer, or normalize the text version of mode if passed in as a ! * string. ! */ ! for (i = 0; validmodes[i].name != (char *)NULL; i++) ! if (mode == validmodes[i].mode) ! { ! mname = validmodes[i].name; ! break; ! } ! if (validmodes[i].name == (char *)NULL) ! { ! PyErr_SetString(PyExc_ValueError, "invalid mode for lo_creat()"); ! return (PyObject *)NULL; ! } ! // Make sure that INV_BIN is not set. ! mode &= (INV_READ | INV_WRITE); ! if (!(oid = lo_creat(PgConnection_Get(self), mode))) ! { ! PyErr_SetString(PqErr_OperationalError, "Can't create large object."); return (PyObject *)NULL; ! } ! return PgLargeObject_New((PyObject *)self, oid); } *************** *** 936,947 **** static PyObject *PgLo_import(PgConnection *self, PyObject *args) { Oid oid; ! char *filename; if (!PyArg_ParseTuple(args,"s:lo_import", &filename)) return (PyObject *)NULL; - if (PgConnection_check((PyObject *)self)) - return (PyObject *)NULL; - if (!(oid = lo_import(PgConnection_Get(self), filename))) { --- 972,983 ---- static PyObject *PgLo_import(PgConnection *self, PyObject *args) { Oid oid; ! char *filename = (char *)NULL; ! ! if (!PgConnection_check((PyObject *)self)) ! return (PyObject *)NULL; if (!PyArg_ParseTuple(args,"s:lo_import", &filename)) return (PyObject *)NULL; if (!(oid = lo_import(PgConnection_Get(self), filename))) { *************** *** 962,971 **** Oid oid; if (!PyArg_ParseTuple(args,"i:lo_unlink", &oid)) return (PyObject *)NULL; - if (PgConnection_check((PyObject *)self)) - return (PyObject *)NULL; - if (lo_unlink(PgConnection_Get(self), oid)) { --- 998,1007 ---- Oid oid; + if (!PgConnection_check((PyObject *)self)) + return (PyObject *)NULL; + if (!PyArg_ParseTuple(args,"i:lo_unlink", &oid)) return (PyObject *)NULL; if (lo_unlink(PgConnection_Get(self), oid)) { *************** *** 988,992 **** {"getlineAsync", (PyCFunction)libPQgetlineAsync, 1, libPQgetlineAsync_Doc}, {"lo_creat", (PyCFunction)PgLo_creat, 1, PgLo_creat_Doc}, - {"lo_get", (PyCFunction)PgLo_get, 1, PgLo_get_Doc}, {"lo_import", (PyCFunction)PgLo_import, 1, PgLo_import_Doc}, {"lo_unlink", (PyCFunction)PgLo_unlink, 1, PgLo_unlink_Doc}, --- 1024,1027 ---- |