Skip to content

Commit d2e028b

Browse files
committed
Fix brain damage in deciding which python input converter to use.
1 parent b952d61 commit d2e028b

File tree

1 file changed

+31
-66
lines changed

1 file changed

+31
-66
lines changed

src/pl/plpython/plpython.c

Lines changed: 31 additions & 66 deletions
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.32 2003/05/27 17:49:47 momjian Exp $
32+
* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.33 2003/06/11 18:33:39 tgl Exp $
3333
*
3434
*********************************************************************
3535
*/
@@ -244,8 +244,8 @@ static void PLy_typeinfo_init(PLyTypeInfo *);
244244
static void PLy_typeinfo_dealloc(PLyTypeInfo *);
245245
static void PLy_output_datum_func(PLyTypeInfo *, Form_pg_type);
246246
static void PLy_output_datum_func2(PLyObToDatum *, Form_pg_type);
247-
static void PLy_input_datum_func(PLyTypeInfo *, Form_pg_type);
248-
static void PLy_input_datum_func2(PLyDatumToOb *, Form_pg_type);
247+
static void PLy_input_datum_func(PLyTypeInfo *, Oid, Form_pg_type);
248+
static void PLy_input_datum_func2(PLyDatumToOb *, Oid, Form_pg_type);
249249
static void PLy_output_tuple_funcs(PLyTypeInfo *, TupleDesc);
250250
static void PLy_input_tuple_funcs(PLyTypeInfo *, TupleDesc);
251251

@@ -1152,7 +1152,9 @@ PLy_procedure_create(FunctionCallInfo fcinfo, bool is_trigger,
11521152
argTypeStruct = (Form_pg_type) GETSTRUCT(argTypeTup);
11531153

11541154
if (argTypeStruct->typrelid == InvalidOid)
1155-
PLy_input_datum_func(&(proc->args[i]), argTypeStruct);
1155+
PLy_input_datum_func(&(proc->args[i]),
1156+
procStruct->proargtypes[i],
1157+
argTypeStruct);
11561158
else
11571159
{
11581160
TupleTableSlot *slot = (TupleTableSlot *) fcinfo->arg[i];
@@ -1373,7 +1375,9 @@ PLy_input_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc)
13731375

13741376
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
13751377

1376-
PLy_input_datum_func2(&(arg->in.r.atts[i]), typeStruct);
1378+
PLy_input_datum_func2(&(arg->in.r.atts[i]),
1379+
desc->attrs[i]->atttypid,
1380+
typeStruct);
13771381

13781382
ReleaseSysCache(typeTup);
13791383
}
@@ -1439,85 +1443,46 @@ PLy_output_datum_func2(PLyObToDatum * arg, Form_pg_type typeStruct)
14391443
}
14401444

14411445
void
1442-
PLy_input_datum_func(PLyTypeInfo * arg, Form_pg_type typeStruct)
1446+
PLy_input_datum_func(PLyTypeInfo * arg, Oid typeOid, Form_pg_type typeStruct)
14431447
{
14441448
enter();
14451449

14461450
if (arg->is_rel == 1)
14471451
elog(FATAL, "plpython: PLyTypeInfo struct is initialized for Tuple");
14481452
arg->is_rel = 0;
1449-
PLy_input_datum_func2(&(arg->in.d), typeStruct);
1453+
PLy_input_datum_func2(&(arg->in.d), typeOid, typeStruct);
14501454
}
14511455

14521456
void
1453-
PLy_input_datum_func2(PLyDatumToOb * arg, Form_pg_type typeStruct)
1457+
PLy_input_datum_func2(PLyDatumToOb * arg, Oid typeOid, Form_pg_type typeStruct)
14541458
{
1455-
char *type;
1456-
1459+
/* Get the type's conversion information */
14571460
perm_fmgr_info(typeStruct->typoutput, &arg->typfunc);
14581461
arg->typelem = typeStruct->typelem;
14591462
arg->typbyval = typeStruct->typbyval;
14601463

1461-
/*
1462-
* hmmm, wierd. means this arg will always be converted to a python
1463-
* None
1464-
*/
1465-
if (!OidIsValid(typeStruct->typoutput))
1466-
{
1467-
elog(ERROR, "plpython: (FIXME) typeStruct->typoutput is invalid");
1468-
1469-
arg->func = NULL;
1470-
return;
1471-
}
1472-
1473-
type = NameStr(typeStruct->typname);
1474-
switch (type[0])
1464+
/* Determine which kind of Python object we will convert to */
1465+
switch (typeOid)
14751466
{
1476-
case 'b':
1477-
{
1478-
if (strcasecmp("bool", type))
1479-
{
1480-
arg->func = PLyBool_FromString;
1481-
return;
1482-
}
1483-
break;
1484-
}
1485-
case 'f':
1486-
{
1487-
if ((strncasecmp("float", type, 5) == 0) &&
1488-
((type[5] == '8') || (type[5] == '4')))
1489-
{
1490-
arg->func = PLyFloat_FromString;
1491-
return;
1492-
}
1493-
break;
1494-
}
1495-
case 'i':
1496-
{
1497-
if ((strncasecmp("int", type, 3) == 0) &&
1498-
((type[3] == '4') || (type[3] == '2')) &&
1499-
(type[4] == '\0'))
1500-
{
1501-
arg->func = PLyInt_FromString;
1502-
return;
1503-
}
1504-
else if (strcasecmp("int8", type) == 0)
1505-
arg->func = PLyLong_FromString;
1506-
break;
1507-
}
1508-
case 'n':
1509-
{
1510-
if (strcasecmp("numeric", type) == 0)
1511-
{
1512-
arg->func = PLyFloat_FromString;
1513-
return;
1514-
}
1515-
break;
1516-
}
1467+
case BOOLOID:
1468+
arg->func = PLyBool_FromString;
1469+
break;
1470+
case FLOAT4OID:
1471+
case FLOAT8OID:
1472+
case NUMERICOID:
1473+
arg->func = PLyFloat_FromString;
1474+
break;
1475+
case INT2OID:
1476+
case INT4OID:
1477+
arg->func = PLyInt_FromString;
1478+
break;
1479+
case INT8OID:
1480+
arg->func = PLyLong_FromString;
1481+
break;
15171482
default:
1483+
arg->func = PLyString_FromString;
15181484
break;
15191485
}
1520-
arg->func = PLyString_FromString;
15211486
}
15221487

15231488
void

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy