mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Allow pltcl args to spi_prepare and plpython args to plpy.prepare to be standard type aliases as well as those known in pg_type. Similar to recent change in plperl.
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/pltcl.sgml,v 2.45 2007/02/01 00:28:17 momjian Exp $ -->
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/pltcl.sgml,v 2.46 2007/02/21 03:27:31 adunstan Exp $ -->
|
||||||
|
|
||||||
<chapter id="pltcl">
|
<chapter id="pltcl">
|
||||||
<title>PL/Tcl - Tcl Procedural Language</title>
|
<title>PL/Tcl - Tcl Procedural Language</title>
|
||||||
@ -331,9 +331,6 @@ spi_exec -array C "SELECT * FROM pg_class" {
|
|||||||
If the query uses parameters, the names of the parameter types
|
If the query uses parameters, the names of the parameter types
|
||||||
must be given as a Tcl list. (Write an empty list for
|
must be given as a Tcl list. (Write an empty list for
|
||||||
<replaceable>typelist</replaceable> if no parameters are used.)
|
<replaceable>typelist</replaceable> if no parameters are used.)
|
||||||
Presently, the parameter types must be identified by the internal
|
|
||||||
type names shown in the system table <literal>pg_type</>; for example <literal>int4</> not
|
|
||||||
<literal>integer</>.
|
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
The return value from <function>spi_prepare</function> is a query ID
|
The return value from <function>spi_prepare</function> is a query ID
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* plpython.c - python as a procedural language for PostgreSQL
|
* plpython.c - python as a procedural language for PostgreSQL
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.95 2007/02/09 03:35:35 tgl Exp $
|
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.96 2007/02/21 03:27:32 adunstan Exp $
|
||||||
*
|
*
|
||||||
*********************************************************************
|
*********************************************************************
|
||||||
*/
|
*/
|
||||||
@ -2309,8 +2309,9 @@ PLy_spi_prepare(PyObject * self, PyObject * args)
|
|||||||
for (i = 0; i < nargs; i++)
|
for (i = 0; i < nargs; i++)
|
||||||
{
|
{
|
||||||
char *sptr;
|
char *sptr;
|
||||||
List *names;
|
|
||||||
HeapTuple typeTup;
|
HeapTuple typeTup;
|
||||||
|
Oid typeId;
|
||||||
|
int32 typmod;
|
||||||
Form_pg_type typeStruct;
|
Form_pg_type typeStruct;
|
||||||
|
|
||||||
optr = PySequence_GetItem(list, i);
|
optr = PySequence_GetItem(list, i);
|
||||||
@ -2318,18 +2319,24 @@ PLy_spi_prepare(PyObject * self, PyObject * args)
|
|||||||
elog(ERROR, "Type names must be strings.");
|
elog(ERROR, "Type names must be strings.");
|
||||||
sptr = PyString_AsString(optr);
|
sptr = PyString_AsString(optr);
|
||||||
|
|
||||||
/*
|
/********************************************************
|
||||||
* Parse possibly-qualified type name and look it up in
|
* Resolve argument type names and then look them up by
|
||||||
* pg_type
|
* oid in the system cache, and remember the required
|
||||||
*/
|
*information for input conversion.
|
||||||
names = stringToQualifiedNameList(sptr,
|
********************************************************/
|
||||||
"PLy_spi_prepare");
|
|
||||||
typeTup = typenameType(NULL,
|
parseTypeString(sptr, &typeId, &typmod);
|
||||||
makeTypeNameFromNameList(names));
|
|
||||||
|
typeTup = SearchSysCache(TYPEOID,
|
||||||
|
ObjectIdGetDatum(typeId),
|
||||||
|
0,0,0);
|
||||||
|
if (!HeapTupleIsValid(typeTup))
|
||||||
|
elog(ERROR, "cache lookup failed for type %u", typeId);
|
||||||
|
|
||||||
Py_DECREF(optr);
|
Py_DECREF(optr);
|
||||||
optr = NULL; /* this is important */
|
optr = NULL; /* this is important */
|
||||||
|
|
||||||
plan->types[i] = HeapTupleGetOid(typeTup);
|
plan->types[i] = typeId;
|
||||||
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
|
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
|
||||||
if (typeStruct->typtype != 'c')
|
if (typeStruct->typtype != 'c')
|
||||||
PLy_output_datum_func(&plan->args[i], typeTup);
|
PLy_output_datum_func(&plan->args[i], typeTup);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* pltcl.c - PostgreSQL support for Tcl as
|
* pltcl.c - PostgreSQL support for Tcl as
|
||||||
* procedural language (PL)
|
* procedural language (PL)
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.110 2007/02/09 03:35:35 tgl Exp $
|
* $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.111 2007/02/21 03:27:32 adunstan Exp $
|
||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
@ -1808,23 +1808,22 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
|
|||||||
PG_TRY();
|
PG_TRY();
|
||||||
{
|
{
|
||||||
/************************************************************
|
/************************************************************
|
||||||
* Lookup the argument types by name in the system cache
|
* Resolve argument type names and then look them up by oid
|
||||||
* and remember the required information for input conversion
|
* in the system cache, and remember the required information
|
||||||
|
* for input conversion.
|
||||||
************************************************************/
|
************************************************************/
|
||||||
for (i = 0; i < nargs; i++)
|
for (i = 0; i < nargs; i++)
|
||||||
{
|
{
|
||||||
List *names;
|
Oid typId, typInput, typIOParam;
|
||||||
HeapTuple typeTup;
|
int32 typmod;
|
||||||
|
|
||||||
/* Parse possibly-qualified type name and look it up in pg_type */
|
parseTypeString(args[i], &typId, &typmod);
|
||||||
names = stringToQualifiedNameList(args[i],
|
|
||||||
"pltcl_SPI_prepare");
|
getTypeInputInfo(typId, &typInput, &typIOParam);
|
||||||
typeTup = typenameType(NULL, makeTypeNameFromNameList(names));
|
|
||||||
qdesc->argtypes[i] = HeapTupleGetOid(typeTup);
|
qdesc->argtypes[i] = typId;
|
||||||
perm_fmgr_info(((Form_pg_type) GETSTRUCT(typeTup))->typinput,
|
perm_fmgr_info(typInput, &(qdesc->arginfuncs[i]));
|
||||||
&(qdesc->arginfuncs[i]));
|
qdesc->argtypioparams[i] = typIOParam;
|
||||||
qdesc->argtypioparams[i] = getTypeIOParam(typeTup);
|
|
||||||
ReleaseSysCache(typeTup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************
|
/************************************************************
|
||||||
|
Reference in New Issue
Block a user