diff options
| author | Tom Lane | 2002-03-29 19:06:29 +0000 |
|---|---|---|
| committer | Tom Lane | 2002-03-29 19:06:29 +0000 |
| commit | d5e99ab4d6718e8ef515575e33fb5c6181cdcc96 (patch) | |
| tree | 6c817d6358f50ae920207245c3b862b2cdd74ceb /src/pl | |
| parent | 7c1ff354105e2256d7904497d8e282ccec53d2e6 (diff) | |
pg_type has a typnamespace column; system now supports creating types
in different namespaces. Also, cleanup work on relation namespace
support: drop, alter, rename commands work for tables in non-default
namespaces.
Diffstat (limited to 'src/pl')
| -rw-r--r-- | src/pl/plpgsql/src/pl_comp.c | 70 | ||||
| -rw-r--r-- | src/pl/plpython/plpython.c | 26 | ||||
| -rw-r--r-- | src/pl/tcl/pltcl.c | 24 |
3 files changed, 58 insertions, 62 deletions
diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c index 44c5146eb63..b648c163369 100644 --- a/src/pl/plpgsql/src/pl_comp.c +++ b/src/pl/plpgsql/src/pl_comp.c @@ -3,7 +3,7 @@ * procedural language * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.39 2002/03/26 19:17:02 tgl Exp $ + * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.40 2002/03/29 19:06:27 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -47,14 +47,15 @@ #include "access/heapam.h" #include "catalog/catname.h" #include "catalog/namespace.h" -#include "catalog/pg_proc.h" -#include "catalog/pg_type.h" -#include "catalog/pg_class.h" #include "catalog/pg_attribute.h" #include "catalog/pg_attrdef.h" +#include "catalog/pg_class.h" +#include "catalog/pg_proc.h" +#include "catalog/pg_type.h" #include "commands/trigger.h" #include "executor/spi.h" #include "fmgr.h" +#include "nodes/makefuncs.h" #include "parser/gramparse.h" #include "parser/parse_type.h" #include "tcop/tcopprot.h" @@ -851,10 +852,8 @@ plpgsql_parse_wordtype(char *word) { PLpgSQL_nsitem *nse; char *cp; - HeapTuple typeTup; - Form_pg_type typeStruct; - char *typeXlated; bool old_nsstate; + Oid typeOid; /* * We do our lookups case insensitive @@ -887,39 +886,46 @@ plpgsql_parse_wordtype(char *word) /* * Word wasn't found on the namestack. Try to find a data type with * that name, but ignore pg_type entries that are in fact class types. + * + * XXX this should be improved to handle qualified-type-name references. */ - typeXlated = xlateSqlType(cp); - typeTup = SearchSysCache(TYPENAME, - PointerGetDatum(typeXlated), - 0, 0, 0); - if (HeapTupleIsValid(typeTup)) + typeOid = LookupTypeName(makeTypeName(xlateSqlType(cp))); + if (OidIsValid(typeOid)) { - PLpgSQL_type *typ; + HeapTuple typeTup; - typeStruct = (Form_pg_type) GETSTRUCT(typeTup); - - if (typeStruct->typrelid != InvalidOid) + typeTup = SearchSysCache(TYPEOID, + ObjectIdGetDatum(typeOid), + 0, 0, 0); + if (HeapTupleIsValid(typeTup)) { - ReleaseSysCache(typeTup); - pfree(cp); - return T_ERROR; - } + Form_pg_type typeStruct = (Form_pg_type) GETSTRUCT(typeTup); + PLpgSQL_type *typ; + + if (!typeStruct->typisdefined || + typeStruct->typrelid != InvalidOid) + { + ReleaseSysCache(typeTup); + pfree(cp); + return T_ERROR; + } - typ = (PLpgSQL_type *) malloc(sizeof(PLpgSQL_type)); + typ = (PLpgSQL_type *) malloc(sizeof(PLpgSQL_type)); - typ->typname = strdup(NameStr(typeStruct->typname)); - typ->typoid = typeTup->t_data->t_oid; - perm_fmgr_info(typeStruct->typinput, &(typ->typinput)); - typ->typelem = typeStruct->typelem; - typ->typbyval = typeStruct->typbyval; - typ->typlen = typeStruct->typlen; - typ->atttypmod = -1; + typ->typname = strdup(NameStr(typeStruct->typname)); + typ->typoid = typeOid; + perm_fmgr_info(typeStruct->typinput, &(typ->typinput)); + typ->typelem = typeStruct->typelem; + typ->typbyval = typeStruct->typbyval; + typ->typlen = typeStruct->typlen; + typ->atttypmod = -1; - plpgsql_yylval.dtype = typ; + plpgsql_yylval.dtype = typ; - ReleaseSysCache(typeTup); - pfree(cp); - return T_DTYPE; + ReleaseSysCache(typeTup); + pfree(cp); + return T_DTYPE; + } } /* diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c index e56f9254cff..9821f75335b 100644 --- a/src/pl/plpython/plpython.c +++ b/src/pl/plpython/plpython.c @@ -29,7 +29,7 @@ * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.16 2002/03/06 18:50:32 momjian Exp $ + * $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.17 2002/03/29 19:06:27 tgl Exp $ * ********************************************************************* */ @@ -49,16 +49,16 @@ /* postgreSQL stuff */ -#include "executor/spi.h" +#include "access/heapam.h" +#include "catalog/pg_proc.h" +#include "catalog/pg_type.h" #include "commands/trigger.h" -#include "utils/elog.h" +#include "executor/spi.h" #include "fmgr.h" -#include "access/heapam.h" - +#include "nodes/makefuncs.h" +#include "parser/parse_type.h" #include "tcop/tcopprot.h" #include "utils/syscache.h" -#include "catalog/pg_proc.h" -#include "catalog/pg_type.h" #include <Python.h> #include "plpython.h" @@ -2086,16 +2086,8 @@ PLy_spi_prepare(PyObject * self, PyObject * args) RAISE_EXC(1); } sptr = PyString_AsString(optr); - typeTup = SearchSysCache(TYPENAME, PointerGetDatum(sptr), - 0, 0, 0); - if (!HeapTupleIsValid(typeTup)) - { - PLy_exception_set(PLy_exc_spi_error, - "Cache lookup for type `%s' failed.", - sptr); - RAISE_EXC(1); - } - + /* XXX should extend this to allow qualified type names */ + typeTup = typenameType(makeTypeName(sptr)); Py_DECREF(optr); optr = NULL; /* this is important */ diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c index 34bc731e9ab..3335e8ed176 100644 --- a/src/pl/tcl/pltcl.c +++ b/src/pl/tcl/pltcl.c @@ -31,7 +31,7 @@ * ENHANCEMENTS, OR MODIFICATIONS. * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.52 2002/03/06 18:50:33 momjian Exp $ + * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.53 2002/03/29 19:06:28 tgl Exp $ * **********************************************************************/ @@ -47,17 +47,18 @@ #include <string.h> #include <setjmp.h> -#include "executor/spi.h" +#include "access/heapam.h" +#include "catalog/pg_language.h" +#include "catalog/pg_proc.h" +#include "catalog/pg_type.h" #include "commands/trigger.h" -#include "utils/builtins.h" +#include "executor/spi.h" #include "fmgr.h" -#include "access/heapam.h" - +#include "nodes/makefuncs.h" +#include "parser/parse_type.h" #include "tcop/tcopprot.h" +#include "utils/builtins.h" #include "utils/syscache.h" -#include "catalog/pg_proc.h" -#include "catalog/pg_language.h" -#include "catalog/pg_type.h" #if defined(UNICODE_CONVERSION) && TCL_MAJOR_VERSION == 8 \ && TCL_MINOR_VERSION > 0 @@ -1750,11 +1751,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp, ************************************************************/ for (i = 0; i < nargs; i++) { - typeTup = SearchSysCache(TYPENAME, - PointerGetDatum(args[i]), - 0, 0, 0); - if (!HeapTupleIsValid(typeTup)) - elog(ERROR, "pltcl: Cache lookup of type %s failed", args[i]); + /* XXX should extend this to allow qualified type names */ + typeTup = typenameType(makeTypeName(args[i])); qdesc->argtypes[i] = typeTup->t_data->t_oid; perm_fmgr_info(((Form_pg_type) GETSTRUCT(typeTup))->typinput, &(qdesc->arginfuncs[i])); |
