From: Billy G. A. <bal...@us...> - 2001-09-26 05:41:37
|
Update of /cvsroot/pypgsql/pypgsql In directory usw-pr-cvs1:/tmp/cvs-serv27934 Modified Files: libpqmodule.c Log Message: 26SEP2001 bga Change the quoting/escaping helper routines so that they also escape the double quote character. This was done so that the escaped, quoted string can be used to create PostgreSQL arrays by simply removine the outer single quotes. --- Added a PgLargeObject constructor. Index: libpqmodule.c =================================================================== RCS file: /cvsroot/pypgsql/pypgsql/libpqmodule.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** libpqmodule.c 2001/09/24 07:10:56 1.15 --- libpqmodule.c 2001/09/26 05:41:34 1.16 *************** *** 32,35 **** --- 32,38 ---- | Date Ini Description | | --------- --- ------------------------------------------------------- | + | 26SEP2001 bga Change the quoting/escaping helper routines so that | + | they also escape the double quote character. | + | --- Added a PgLargeObject constructor. | | 24SEP2001 bga Added support routines to: | | 1. quote strings (PgQuoteString). | *************** *** 157,161 **** | NL \n | | CR \r | ! | other \OOO where OOO is the octal value of the control char. | | | | 2. The backslash is quoted as \\. | --- 160,165 ---- | NL \n | | CR \r | ! | other \OOO where OOO is the octal representation of the con- | ! | trol character's ordinal number. | | | | 2. The backslash is quoted as \\. | *************** *** 163,167 **** | 3. The single quote is quoted as \'. | | | ! | 4. All other characters are unchanged. | \***********************************************************************/ --- 167,178 ---- | 3. The single quote is quoted as \'. | | | ! | 4. The double quote is quoted as \". | ! | | ! | 5. All other characters are unchanged. | ! | | ! | Note: The double quote (") is escaped in case the quoted string is | ! | part of a PostgreSQL array, which uses double quotes around | ! | string values instead of single quotes. It saves having to do | ! | a global search and replace of double quotes in Python. | \***********************************************************************/ *************** *** 187,190 **** --- 198,202 ---- switch (sin[i]) { + case '"': case '\'': case '\\': *************** *** 254,259 **** | able for use in PostgreSQL. The quoting rules are: | | | ! | 1. Control characters are quoted as \OOO where OOO is the octal | ! | value of the control character. | | | | 2. The backslash is quoted as \\\\. | --- 266,271 ---- | able for use in PostgreSQL. The quoting rules are: | | | ! | 1. Non-printable characters are quoted as \OOO where OOO is the | ! | octal representation of the characters ordinal number. | | | | 2. The backslash is quoted as \\\\. | *************** *** 261,265 **** | 3. The single quote is quoted as \'. | | | ! | 4. All other characters are unchanged. | \***********************************************************************/ --- 273,284 ---- | 3. The single quote is quoted as \'. | | | ! | 4. The double quote is quoted as \". | ! | | ! | 5. All other characters are unchanged. | ! | | ! | Note: The double quote (") is escaped in case the quoted string is | ! | part of a PostgreSQL array, which uses double quotes around | ! | string values instead of single quotes. It saves having to do | ! | a global search and replace of double quotes in Python. | \***********************************************************************/ *************** *** 284,287 **** --- 303,307 ---- switch (sin[i]) { + case '"': case '\'': sout[j++] = '\\'; *************** *** 677,682 **** } #if defined(HAVE_LONG_LONG) ! static PgInt8Object *libPQint8_FromObject(PyObject *self, PyObject *args) { PyObject *obj; --- 697,704 ---- } + /*--------------------------------------------------------------------------*/ + #if defined(HAVE_LONG_LONG) ! static PyObject *libPQint8_FromObject(PyObject *self, PyObject *args) { PyObject *obj; *************** *** 684,696 **** if (!PyArg_ParseTuple(args,"O:PgInt8", &obj)) ! return NULL; if (PgInt2_Check(obj)) { ! return (PgInt8Object *)PgInt8_FromLong((long)PgInt2_AS_INT2(obj)); } else if (PyInt_Check(obj)) { ! return (PgInt8Object *)PgInt8_FromLong(PyInt_AS_LONG(obj)); } else if (PyLong_Check(obj)) --- 706,718 ---- if (!PyArg_ParseTuple(args,"O:PgInt8", &obj)) ! return (PyObject *)NULL; if (PgInt2_Check(obj)) { ! return PgInt8_FromLong((long)PgInt2_AS_INT2(obj)); } else if (PyInt_Check(obj)) { ! return PgInt8_FromLong(PyInt_AS_LONG(obj)); } else if (PyLong_Check(obj)) *************** *** 699,705 **** if (a == -1 && PyErr_Occurred()) ! return (PgInt8Object *)NULL; ! return (PgInt8Object *)PgInt8_FromLongLong(a); } else if (PyFloat_Check(obj)) --- 721,727 ---- if (a == -1 && PyErr_Occurred()) ! return (PyObject *)NULL; ! return PgInt8_FromLongLong(a); } else if (PyFloat_Check(obj)) *************** *** 717,723 **** if (a == -1 && PyErr_Occurred()) ! return (PgInt8Object *)NULL; ! return (PgInt8Object *)PgInt8_FromLongLong(a); } else if (PyString_Check(obj)) --- 739,745 ---- if (a == -1 && PyErr_Occurred()) ! return (PyObject *)NULL; ! return PgInt8_FromLongLong(a); } else if (PyString_Check(obj)) *************** *** 726,730 **** if (s == (char *)NULL) ! return (PgInt8Object *)PyErr_NoMemory(); return PgInt8_FromString(s, (char **)NULL, 10); --- 748,752 ---- if (s == (char *)NULL) ! return (PyObject *)PyErr_NoMemory(); return PgInt8_FromString(s, (char **)NULL, 10); *************** *** 732,749 **** PyErr_SetString(PyExc_TypeError, "a string or numeric is requireed"); ! return (PgInt8Object *)NULL; } #endif ! static PgInt2Object *libPQint2_FromObject(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,"O:PgInt2", &obj)) ! return NULL; if (PyInt_Check(obj)) { ! return (PgInt2Object *)PgInt2_FromLong(PyInt_AS_LONG(obj)); } #if defined(HAVE_LONG_LONG) --- 754,773 ---- PyErr_SetString(PyExc_TypeError, "a string or numeric is requireed"); ! return (PyObject *)NULL; } #endif ! /*--------------------------------------------------------------------------*/ ! ! static PyObject *libPQint2_FromObject(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,"O:PgInt2", &obj)) ! return (PyObject *)NULL; if (PyInt_Check(obj)) { ! return PgInt2_FromLong(PyInt_AS_LONG(obj)); } #if defined(HAVE_LONG_LONG) *************** *** 753,759 **** if (a == -1 && PyErr_Occurred()) ! return (PgInt2Object *)NULL; ! return (PgInt2Object *)PgInt2_FromLong(a); } #endif --- 777,783 ---- if (a == -1 && PyErr_Occurred()) ! return (PyObject *)NULL; ! return PgInt2_FromLong(a); } #endif *************** *** 763,769 **** if (a == -1 && PyErr_Occurred()) ! return (PgInt2Object *)NULL; ! return (PgInt2Object *)PgInt2_FromLong(a); } else if (PyFloat_Check(obj)) --- 787,793 ---- if (a == -1 && PyErr_Occurred()) ! return (PyObject *)NULL; ! return PgInt2_FromLong(a); } else if (PyFloat_Check(obj)) *************** *** 778,785 **** PyErr_SetString(PyExc_OverflowError, "number to large to convert to PgInt2"); ! return (PgInt2Object *)NULL; } ! return (PgInt2Object *)PgInt2_FromLong(a); } else if (PyString_Check(obj)) --- 802,809 ---- PyErr_SetString(PyExc_OverflowError, "number to large to convert to PgInt2"); ! return (PyObject *)NULL; } ! return PgInt2_FromLong(a); } else if (PyString_Check(obj)) *************** *** 788,792 **** if (s == (char *)NULL) ! return (PgInt2Object *)PyErr_NoMemory(); return PgInt2_FromString(s, (char **)NULL, 10); --- 812,816 ---- if (s == (char *)NULL) ! return PyErr_NoMemory(); return PgInt2_FromString(s, (char **)NULL, 10); *************** *** 794,801 **** PyErr_SetString(PyExc_TypeError, "a string or numeric is requireed"); ! return (PgInt2Object *)NULL; } ! static PgBooleanObject *libPQbool_FromString(PyObject *self, PyObject *args) { char *s; --- 818,827 ---- PyErr_SetString(PyExc_TypeError, "a string or numeric is requireed"); ! return (PyObject *)NULL; } ! /*--------------------------------------------------------------------------*/ ! ! static PyObject *libPQbool_FromString(PyObject *self, PyObject *args) { char *s; *************** *** 804,821 **** return NULL; ! return (PgBooleanObject *)PgBoolean_FromString(s); } ! static PgBooleanObject *libPQbool_FromInt(PyObject *self, PyObject *args) { long l; ! if (!PyArg_ParseTuple(args,"i:BooleanFromInteger", &l)) return NULL; ! return (PgBooleanObject *)PgBoolean_FromLong(l); } ! static PgBooleanObject *libPQbool_FromObject(PyObject *self, PyObject *args) { PyObject *obj; --- 830,851 ---- return NULL; ! return PgBoolean_FromString(s); } ! /*--------------------------------------------------------------------------*/ ! ! static PyObject *libPQbool_FromInt(PyObject *self, PyObject *args) { long l; ! if (!PyArg_ParseTuple(args, "i:BooleanFromInteger", &l)) return NULL; ! return PgBoolean_FromLong(l); } ! /*--------------------------------------------------------------------------*/ ! ! static PyObject *libPQbool_FromObject(PyObject *self, PyObject *args) { PyObject *obj; *************** *** 826,830 **** if (PyInt_Check(obj)) { ! return (PgBooleanObject *)PgBoolean_FromLong(PyInt_AS_LONG(obj)); } else if (PyLong_Check(obj) || PyFloat_Check(obj)) --- 856,860 ---- if (PyInt_Check(obj)) { ! return PgBoolean_FromLong(PyInt_AS_LONG(obj)); } else if (PyLong_Check(obj) || PyFloat_Check(obj)) *************** *** 832,836 **** long i = (*(obj->ob_type->tp_as_number)->nb_nonzero)(obj); ! return (PgBooleanObject *)PgBoolean_FromLong(i); } else if (PyString_Check(obj)) --- 862,866 ---- long i = (*(obj->ob_type->tp_as_number)->nb_nonzero)(obj); ! return PgBoolean_FromLong(i); } else if (PyString_Check(obj)) *************** *** 840,846 **** PyErr_SetString(PyExc_TypeError, "a string or numeric is requireed"); ! return (PgBooleanObject *)NULL; } /***********************************************************************\ | Define the libpq methods and attributes. | --- 870,890 ---- PyErr_SetString(PyExc_TypeError, "a string or numeric is requireed"); ! return (PyObject *)NULL; } + /*--------------------------------------------------------------------------*/ + + static PyObject *libPQlargeObject_New(PyObject *self, PyObject *args) + { + PyObject *conn; + long int loOid; + + if (!PyArg_ParseTuple(args, "O!l:PgLargeObject", + &PgConnection_Type, &conn, &loOid)) + return NULL; + + return PgLargeObject_New(conn, loOid); + } + /***********************************************************************\ | Define the libpq methods and attributes. | *************** *** 863,873 **** libPQconnectStart_Doc }, #endif ! { "PgBooleanFromString", (PyCFunction)libPQbool_FromString, 1}, ! { "PgBooleanFromInteger", (PyCFunction)libPQbool_FromInt, 1}, ! { "PgBoolean", (PyCFunction)libPQbool_FromObject, 1}, #if defined(HAVE_LONG_LONG) ! { "PgInt8", (PyCFunction)libPQint8_FromObject, 1}, #endif ! { "PgInt2", (PyCFunction)libPQint2_FromObject, 1}, { NULL, NULL } }; --- 907,918 ---- libPQconnectStart_Doc }, #endif ! { "PgBooleanFromString", (PyCFunction)libPQbool_FromString, 1 }, ! { "PgBooleanFromInteger", (PyCFunction)libPQbool_FromInt, 1 }, ! { "PgBoolean", (PyCFunction)libPQbool_FromObject, 1 }, #if defined(HAVE_LONG_LONG) ! { "PgInt8", (PyCFunction)libPQint8_FromObject, 1 }, #endif ! { "PgInt2", (PyCFunction)libPQint2_FromObject, 1 }, ! { "PgLargeObject", (PyCFunction)libPQlargeObject_New, 1 }, { NULL, NULL } }; |