Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f51c7ca

Browse files
committed
Make plpython's spi_execute interface handle NULLs properly.
From Andrew Bosma.
1 parent 6f49703 commit f51c7ca

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

src/pl/plpython/plpython.c

+34-15
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
3030
*
3131
* IDENTIFICATION
32-
* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.28 2003/01/31 22:25:13 tgl Exp $
32+
* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.29 2003/01/31 22:35:24 tgl Exp $
3333
*
3434
*********************************************************************
3535
*/
@@ -2181,6 +2181,7 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, int limit)
21812181
int i,
21822182
rv;
21832183
PLyPlanObject *plan;
2184+
char *nulls;
21842185

21852186
enter();
21862187

@@ -2242,30 +2243,48 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, int limit)
22422243

22432244
if (nargs)
22442245
{
2246+
nulls = palloc((nargs + 1) * sizeof(char));
2247+
22452248
for (i = 0; i < nargs; i++)
22462249
{
22472250
PyObject *elem,
22482251
*so;
22492252
char *sv;
22502253

22512254
elem = PySequence_GetItem(list, i);
2252-
so = PyObject_Str(elem);
2253-
sv = PyString_AsString(so);
2254-
2255-
/*
2256-
* FIXME -- if this can elog, we have leak
2257-
*/
2258-
plan->values[i] = FunctionCall3(&(plan->args[i].out.d.typfunc),
2259-
CStringGetDatum(sv),
2260-
ObjectIdGetDatum(plan->args[i].out.d.typelem),
2261-
Int32GetDatum(-1));
2262-
2263-
Py_DECREF(so);
2264-
Py_DECREF(elem);
2255+
if (elem != Py_None)
2256+
{
2257+
so = PyObject_Str(elem);
2258+
sv = PyString_AsString(so);
2259+
2260+
/*
2261+
* FIXME -- if this can elog, we have leak
2262+
*/
2263+
plan->values[i] = FunctionCall3(&(plan->args[i].out.d.typfunc),
2264+
CStringGetDatum(sv),
2265+
ObjectIdGetDatum(plan->args[i].out.d.typelem),
2266+
Int32GetDatum(-1));
2267+
2268+
Py_DECREF(so);
2269+
Py_DECREF(elem);
2270+
2271+
nulls[i] = ' ';
2272+
}
2273+
else
2274+
{
2275+
Py_DECREF(elem);
2276+
plan->values[i] = (Datum) 0;
2277+
nulls[i] = 'n';
2278+
}
22652279
}
2280+
nulls[i] = '\0';
2281+
}
2282+
else
2283+
{
2284+
nulls = NULL;
22662285
}
22672286

2268-
rv = SPI_execp(plan->plan, plan->values, NULL, limit);
2287+
rv = SPI_execp(plan->plan, plan->values, nulls, limit);
22692288
RESTORE_EXC();
22702289

22712290
for (i = 0; i < nargs; i++)

0 commit comments

Comments
 (0)