aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/python/pgmodule.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2002-08-28 20:18:58 +0000
committerBruce Momjian <bruce@momjian.us>2002-08-28 20:18:58 +0000
commitf5fea0808f385677dccffa0b4dc0ffe512cb4199 (patch)
treea534278fdba813b36bc7bbe6f24527fa2ef8a5a8 /src/interfaces/python/pgmodule.c
parentb60acaf568bec8afd72a37dc0a486e17d4c21ba3 (diff)
downloadpostgresql-f5fea0808f385677dccffa0b4dc0ffe512cb4199.tar.gz
postgresql-f5fea0808f385677dccffa0b4dc0ffe512cb4199.zip
This is a quick patch to fix a crash in pgquery_dictresult() introduced
recently. I just ran into it while running a set of python test scripts, and I'm not sure who the normal maintainer is for interfaces/python. John Nield
Diffstat (limited to 'src/interfaces/python/pgmodule.c')
-rw-r--r--src/interfaces/python/pgmodule.c78
1 files changed, 7 insertions, 71 deletions
diff --git a/src/interfaces/python/pgmodule.c b/src/interfaces/python/pgmodule.c
index 355c3e4725d..fcda897deb8 100644
--- a/src/interfaces/python/pgmodule.c
+++ b/src/interfaces/python/pgmodule.c
@@ -1788,41 +1788,7 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
n = PQnfields(self->last_result);
reslist = PyList_New(m);
- if ((typ = malloc(sizeof(int) * n)) == NULL)
- {
- PyErr_SetString(PyExc_SyntaxError, "memory error in getresult().");
- return NULL;
- }
-
- for (j = 0; j < n; j++)
- {
- switch (PQftype(self->last_result, j))
- {
- case INT2OID:
- case INT4OID:
- case OIDOID:
- typ[j] = 1;
- break;
-
- case INT8OID:
- typ[j] = 2;
- break;
-
- case FLOAT4OID:
- case FLOAT8OID:
- case NUMERICOID:
- typ[j] = 3;
- break;
-
- case CASHOID:
- typ[j] = 4;
- break;
-
- default:
- typ[j] = 5;
- break;
- }
- }
+ typ = get_type_array(self->last_result, n);
for (i = 0; i < m; i++)
{
@@ -1944,41 +1910,7 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
n = PQnfields(self->last_result);
reslist = PyList_New(m);
- if ((typ = malloc(sizeof(int) * n)) == NULL)
- {
- PyErr_SetString(PyExc_SyntaxError, "memory error in dictresult().");
- return NULL;
- }
-
- for (j = 0; j < n; j++)
- {
- switch (PQftype(self->last_result, j))
- {
- case INT2OID:
- case INT4OID:
- case OIDOID:
- typ[j] = 1;
- break;
-
- case INT8OID:
- typ[j] = 2;
- break;
-
- case FLOAT4OID:
- case FLOAT8OID:
- case NUMERICOID:
- typ[j] = 2;
- break;
-
- case CASHOID:
- typ[j] = 3;
- break;
-
- default:
- typ[j] = 4;
- break;
- }
- }
+ typ = get_type_array(self->last_result, n);
for (i = 0; i < m; i++)
{
@@ -2034,9 +1966,13 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
* one */
s++;
- for (k = 0; *s; s++)
+ for (k = 0;
+ *s && k < sizeof(cashbuf)/sizeof(cashbuf[0])-1;
+ s++)
+ {
if (*s != ',')
cashbuf[k++] = *s;
+ }
cashbuf[k] = 0;
val = PyFloat_FromDouble(strtod(cashbuf, NULL) * mult);