summaryrefslogtreecommitdiff
path: root/src/pl/plpython/plpy_resultobject.c
diff options
context:
space:
mode:
authorPeter Eisentraut2012-04-15 17:23:08 +0000
committerPeter Eisentraut2012-04-15 17:23:08 +0000
commitc03523ed3fc65e219068aff536330ce451f63ca7 (patch)
treee940022faeb9fb921216028b3130fc37958f3bb2 /src/pl/plpython/plpy_resultobject.c
parent4efbb7d04f3481da1aaf75630c1203203f400b66 (diff)
PL/Python: Fix crash when colnames() etc. called without result set
The result object methods colnames() etc. would crash when called after a command that did not produce a result set. Now they throw an exception. discovery and initial patch by Jean-Baptiste Quenot
Diffstat (limited to 'src/pl/plpython/plpy_resultobject.c')
-rw-r--r--src/pl/plpython/plpy_resultobject.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/pl/plpython/plpy_resultobject.c b/src/pl/plpython/plpy_resultobject.c
index b25e8083b9e..fcf8074228d 100644
--- a/src/pl/plpython/plpy_resultobject.c
+++ b/src/pl/plpython/plpy_resultobject.c
@@ -9,6 +9,7 @@
#include "plpython.h"
#include "plpy_resultobject.h"
+#include "plpy_elog.h"
static void PLy_result_dealloc(PyObject *arg);
@@ -131,6 +132,12 @@ PLy_result_colnames(PyObject *self, PyObject *unused)
PyObject *list;
int i;
+ if (!ob->tupdesc)
+ {
+ PLy_exception_set(PLy_exc_error, "command did not produce a result set");
+ return NULL;
+ }
+
list = PyList_New(ob->tupdesc->natts);
for (i = 0; i < ob->tupdesc->natts; i++)
PyList_SET_ITEM(list, i, PyString_FromString(NameStr(ob->tupdesc->attrs[i]->attname)));
@@ -145,6 +152,12 @@ PLy_result_coltypes(PyObject *self, PyObject *unused)
PyObject *list;
int i;
+ if (!ob->tupdesc)
+ {
+ PLy_exception_set(PLy_exc_error, "command did not produce a result set");
+ return NULL;
+ }
+
list = PyList_New(ob->tupdesc->natts);
for (i = 0; i < ob->tupdesc->natts; i++)
PyList_SET_ITEM(list, i, PyInt_FromLong(ob->tupdesc->attrs[i]->atttypid));
@@ -159,6 +172,12 @@ PLy_result_coltypmods(PyObject *self, PyObject *unused)
PyObject *list;
int i;
+ if (!ob->tupdesc)
+ {
+ PLy_exception_set(PLy_exc_error, "command did not produce a result set");
+ return NULL;
+ }
+
list = PyList_New(ob->tupdesc->natts);
for (i = 0; i < ob->tupdesc->natts; i++)
PyList_SET_ITEM(list, i, PyInt_FromLong(ob->tupdesc->attrs[i]->atttypmod));