Allow pltcl args to spi_prepare and plpython args to plpy.prepare to be standard...
authorAndrew Dunstan <andrew@dunslane.net>
Wed, 21 Feb 2007 03:27:32 +0000 (03:27 +0000)
committerAndrew Dunstan <andrew@dunslane.net>
Wed, 21 Feb 2007 03:27:32 +0000 (03:27 +0000)
doc/src/sgml/pltcl.sgml
src/pl/plpython/plpython.c
src/pl/tcl/pltcl.c

index 70055e5be962bd8520f6a583accef5e0032da397..77a7cd0e3d0f66bb99abcc94b26a41f898244e08 100644 (file)
@@ -331,9 +331,6 @@ spi_exec -array C "SELECT * FROM pg_class" {
         If the query uses parameters, the names of the parameter types
         must be given as a Tcl list.  (Write an empty list for
         <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>
         The return value from <function>spi_prepare</function> is a query ID
index 2ef4778cdfff46708db6610ccf229e46dba3642e..aeaccf681009403ba2f5b8feef484b978dce7602 100644 (file)
@@ -2309,27 +2309,34 @@ PLy_spi_prepare(PyObject * self, PyObject * args)
                                for (i = 0; i < nargs; i++)
                                {
                                        char       *sptr;
-                                       List       *names;
                                        HeapTuple       typeTup;
+                                       Oid         typeId;
+                                       int32       typmod;
                                        Form_pg_type typeStruct;
 
                                        optr = PySequence_GetItem(list, i);
                                        if (!PyString_Check(optr))
                                                elog(ERROR, "Type names must be strings.");
                                        sptr = PyString_AsString(optr);
+                                       
+                                       /********************************************************
+                                        * Resolve argument type names and then look them up by 
+                                        * oid in the system cache, and remember the required 
+                                        *information for input conversion.
+                                        ********************************************************/ 
+
+                                       parseTypeString(sptr, &typeId, &typmod);
+                                       typeTup = SearchSysCache(TYPEOID,
+                                                                                        ObjectIdGetDatum(typeId),
+                                                                                        0,0,0);
+                                       if (!HeapTupleIsValid(typeTup))
+                                               elog(ERROR, "cache lookup failed for type %u", typeId);
 
-                                       /*
-                                        * Parse possibly-qualified type name and look it up in
-                                        * pg_type
-                                        */
-                                       names = stringToQualifiedNameList(sptr,
-                                                                                                         "PLy_spi_prepare");
-                                       typeTup = typenameType(NULL,
-                                                                                  makeTypeNameFromNameList(names));
                                        Py_DECREF(optr);
                                        optr = NULL;    /* this is important */
 
-                                       plan->types[i] = HeapTupleGetOid(typeTup);
+                                       plan->types[i] = typeId;
                                        typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
                                        if (typeStruct->typtype != 'c')
                                                PLy_output_datum_func(&plan->args[i], typeTup);
index fa69acbf9254d87b193edb3c1b554dbaccee75ad..d03aaed0ebf628d09170ea9af1f5a282c64bace6 100644 (file)
@@ -1808,23 +1808,22 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
        PG_TRY();
        {
                /************************************************************
-                * Lookup the argument types by name in the system cache
-                * and remember the required information for input conversion
+                * Resolve argument type names and then look them up by oid 
+         * in the system cache, and remember the required information 
+         * for input conversion.
                 ************************************************************/
                for (i = 0; i < nargs; i++)
                {
-                       List       *names;
-                       HeapTuple       typeTup;
+                       Oid         typId, typInput, typIOParam;
+            int32       typmod;
 
-                       /* Parse possibly-qualified type name and look it up in pg_type */
-                       names = stringToQualifiedNameList(args[i],
-                                                                                         "pltcl_SPI_prepare");
-                       typeTup = typenameType(NULL, makeTypeNameFromNameList(names));
-                       qdesc->argtypes[i] = HeapTupleGetOid(typeTup);
-                       perm_fmgr_info(((Form_pg_type) GETSTRUCT(typeTup))->typinput,
-                                                  &(qdesc->arginfuncs[i]));
-                       qdesc->argtypioparams[i] = getTypeIOParam(typeTup);
-                       ReleaseSysCache(typeTup);
+                       parseTypeString(args[i], &typId, &typmod);
+
+                       getTypeInputInfo(typId, &typInput, &typIOParam);
+
+                       qdesc->argtypes[i] = typId;
+                       perm_fmgr_info(typInput, &(qdesc->arginfuncs[i]));
+                       qdesc->argtypioparams[i] = typIOParam;
                }
 
                /************************************************************