summaryrefslogtreecommitdiff
path: root/src/pl
diff options
context:
space:
mode:
authorTom Lane2002-08-22 00:01:51 +0000
committerTom Lane2002-08-22 00:01:51 +0000
commitb663f3443ba096a06970214c3e83e79f6e570b84 (patch)
tree049e26c1b02535c12bee6e60ba89cf1d42a41a72 /src/pl
parent606c9b9d4fafe9300d039c044edc9727c0ed43c9 (diff)
Add a bunch of pseudo-types to replace the behavior formerly associated
with OPAQUE, as per recent pghackers discussion. I still want to do some more work on the 'cstring' pseudo-type, but I'm going to commit the bulk of the changes now before the tree starts shifting under me ...
Diffstat (limited to 'src/pl')
-rw-r--r--src/pl/plperl/plperl.c49
-rw-r--r--src/pl/plpgsql/src/pl_comp.c38
-rw-r--r--src/pl/plpython/plpython.c4
-rw-r--r--src/pl/plpython/plpython_function.sql6
-rw-r--r--src/pl/tcl/pltcl.c49
-rw-r--r--src/pl/tcl/test/test_setup.sql8
6 files changed, 107 insertions, 47 deletions
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index 7533e578436..c617c861141 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -33,7 +33,7 @@
* ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.31 2002/06/15 19:54:24 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.32 2002/08/22 00:01:49 tgl Exp $
*
**********************************************************************/
@@ -619,15 +619,34 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
{
free(prodesc->proname);
free(prodesc);
- if (!OidIsValid(procStruct->prorettype))
- elog(ERROR, "plperl functions cannot return type \"opaque\""
- "\n\texcept when used as triggers");
- else
- elog(ERROR, "plperl: cache lookup for return type %u failed",
- procStruct->prorettype);
+ elog(ERROR, "plperl: cache lookup for return type %u failed",
+ procStruct->prorettype);
}
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
+ /* Disallow pseudotype result, except VOID */
+ if (typeStruct->typtype == 'p')
+ {
+ if (procStruct->prorettype == VOIDOID)
+ /* okay */;
+ else if (procStruct->prorettype == TRIGGEROID ||
+ procStruct->prorettype == OPAQUEOID)
+ {
+ free(prodesc->proname);
+ free(prodesc);
+ elog(ERROR, "plperl functions cannot return type %s"
+ "\n\texcept when used as triggers",
+ format_type_be(procStruct->prorettype));
+ }
+ else
+ {
+ free(prodesc->proname);
+ free(prodesc);
+ elog(ERROR, "plperl functions cannot return type %s",
+ format_type_be(procStruct->prorettype));
+ }
+ }
+
if (typeStruct->typrelid != InvalidOid)
{
free(prodesc->proname);
@@ -657,14 +676,20 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
{
free(prodesc->proname);
free(prodesc);
- if (!OidIsValid(procStruct->proargtypes[i]))
- elog(ERROR, "plperl functions cannot take type \"opaque\"");
- else
- elog(ERROR, "plperl: cache lookup for argument type %u failed",
- procStruct->proargtypes[i]);
+ elog(ERROR, "plperl: cache lookup for argument type %u failed",
+ procStruct->proargtypes[i]);
}
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
+ /* Disallow pseudotype argument */
+ if (typeStruct->typtype == 'p')
+ {
+ free(prodesc->proname);
+ free(prodesc);
+ elog(ERROR, "plperl functions cannot take type %s",
+ format_type_be(procStruct->proargtypes[i]));
+ }
+
if (typeStruct->typrelid != InvalidOid)
prodesc->arg_is_rel[i] = 1;
else
diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c
index ebb2312dae4..c85207780f1 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.46 2002/08/15 16:36:08 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.47 2002/08/22 00:01:50 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -212,15 +212,25 @@ plpgsql_compile(Oid fn_oid, int functype)
ObjectIdGetDatum(procStruct->prorettype),
0, 0, 0);
if (!HeapTupleIsValid(typeTup))
+ elog(ERROR, "cache lookup for return type %u failed",
+ procStruct->prorettype);
+ typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
+
+ /* Disallow pseudotype result, except VOID */
+ if (typeStruct->typtype == 'p')
{
- if (!OidIsValid(procStruct->prorettype))
- elog(ERROR, "plpgsql functions cannot return type \"opaque\""
- "\n\texcept when used as triggers");
+ if (procStruct->prorettype == VOIDOID)
+ /* okay */;
+ else if (procStruct->prorettype == TRIGGEROID ||
+ procStruct->prorettype == OPAQUEOID)
+ elog(ERROR, "plpgsql functions cannot return type %s"
+ "\n\texcept when used as triggers",
+ format_type_be(procStruct->prorettype));
else
- elog(ERROR, "cache lookup for return type %u failed",
- procStruct->prorettype);
+ elog(ERROR, "plpgsql functions cannot return type %s",
+ format_type_be(procStruct->prorettype));
}
- typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
+
if (typeStruct->typrelid != InvalidOid)
function->fn_retistuple = true;
else
@@ -248,15 +258,15 @@ plpgsql_compile(Oid fn_oid, int functype)
ObjectIdGetDatum(procStruct->proargtypes[i]),
0, 0, 0);
if (!HeapTupleIsValid(typeTup))
- {
- if (!OidIsValid(procStruct->proargtypes[i]))
- elog(ERROR, "plpgsql functions cannot take type \"opaque\"");
- else
- elog(ERROR, "cache lookup for argument type %u failed",
- procStruct->proargtypes[i]);
- }
+ elog(ERROR, "cache lookup for argument type %u failed",
+ procStruct->proargtypes[i]);
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
+ /* Disallow pseudotype argument */
+ if (typeStruct->typtype == 'p')
+ elog(ERROR, "plpgsql functions cannot take type %s",
+ format_type_be(procStruct->proargtypes[i]));
+
if (typeStruct->typrelid != InvalidOid)
{
/*
diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c
index 6d26cc75ddb..986937e5e0a 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.19 2002/07/20 05:16:59 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.20 2002/08/22 00:01:50 tgl Exp $
*
*********************************************************************
*/
@@ -447,7 +447,7 @@ plpython_call_handler(PG_FUNCTION_ARGS)
* this action. MODIFY means the tuple has been modified, so update
* tuple and perform action. SKIP and MODIFY assume the trigger fires
* BEFORE the event and is ROW level. postgres expects the function
- * to take no arguments and return an argument of type opaque.
+ * to take no arguments and return an argument of type trigger.
*/
HeapTuple
PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc)
diff --git a/src/pl/plpython/plpython_function.sql b/src/pl/plpython/plpython_function.sql
index 46083ab2ba2..46ab4babd35 100644
--- a/src/pl/plpython/plpython_function.sql
+++ b/src/pl/plpython/plpython_function.sql
@@ -92,7 +92,7 @@ return words'
-- vigorously resisted all efforts at correction. they have
-- since gone bankrupt...
-CREATE FUNCTION users_insert() returns opaque
+CREATE FUNCTION users_insert() returns trigger
AS
'if TD["new"]["fname"] == None or TD["new"]["lname"] == None:
return "SKIP"
@@ -108,7 +108,7 @@ return rv'
LANGUAGE 'plpython';
-CREATE FUNCTION users_update() returns opaque
+CREATE FUNCTION users_update() returns trigger
AS
'if TD["event"] == "UPDATE":
if TD["old"]["fname"] != TD["new"]["fname"] and TD["old"]["fname"] == TD["args"][0]:
@@ -117,7 +117,7 @@ return None'
LANGUAGE 'plpython';
-CREATE FUNCTION users_delete() RETURNS opaque
+CREATE FUNCTION users_delete() RETURNS trigger
AS
'if TD["old"]["fname"] == TD["args"][0]:
return "SKIP"
diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c
index 6f2080b1a43..477dd52d1fd 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.59 2002/07/20 05:16:59 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.60 2002/08/22 00:01:50 tgl Exp $
*
**********************************************************************/
@@ -1051,15 +1051,34 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
{
free(prodesc->proname);
free(prodesc);
- if (!OidIsValid(procStruct->prorettype))
- elog(ERROR, "pltcl functions cannot return type \"opaque\""
- "\n\texcept when used as triggers");
- else
- elog(ERROR, "pltcl: cache lookup for return type %u failed",
- procStruct->prorettype);
+ elog(ERROR, "pltcl: cache lookup for return type %u failed",
+ procStruct->prorettype);
}
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
+ /* Disallow pseudotype result, except VOID */
+ if (typeStruct->typtype == 'p')
+ {
+ if (procStruct->prorettype == VOIDOID)
+ /* okay */;
+ else if (procStruct->prorettype == TRIGGEROID ||
+ procStruct->prorettype == OPAQUEOID)
+ {
+ free(prodesc->proname);
+ free(prodesc);
+ elog(ERROR, "pltcl functions cannot return type %s"
+ "\n\texcept when used as triggers",
+ format_type_be(procStruct->prorettype));
+ }
+ else
+ {
+ free(prodesc->proname);
+ free(prodesc);
+ elog(ERROR, "pltcl functions cannot return type %s",
+ format_type_be(procStruct->prorettype));
+ }
+ }
+
if (typeStruct->typrelid != InvalidOid)
{
free(prodesc->proname);
@@ -1090,14 +1109,20 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
{
free(prodesc->proname);
free(prodesc);
- if (!OidIsValid(procStruct->proargtypes[i]))
- elog(ERROR, "pltcl functions cannot take type \"opaque\"");
- else
- elog(ERROR, "pltcl: cache lookup for argument type %u failed",
- procStruct->proargtypes[i]);
+ elog(ERROR, "pltcl: cache lookup for argument type %u failed",
+ procStruct->proargtypes[i]);
}
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
+ /* Disallow pseudotype argument */
+ if (typeStruct->typtype == 'p')
+ {
+ free(prodesc->proname);
+ free(prodesc);
+ elog(ERROR, "pltcl functions cannot take type %s",
+ format_type_be(procStruct->proargtypes[i]));
+ }
+
if (typeStruct->typrelid != InvalidOid)
{
prodesc->arg_is_rel[i] = 1;
diff --git a/src/pl/tcl/test/test_setup.sql b/src/pl/tcl/test/test_setup.sql
index 918e2212696..c7902386f40 100644
--- a/src/pl/tcl/test/test_setup.sql
+++ b/src/pl/tcl/test/test_setup.sql
@@ -58,7 +58,7 @@ create function check_pkey1_exists(int4, bpchar) returns bool as '
--
-- Trigger function on every change to T_pkey1
--
-create function trig_pkey1_before() returns opaque as '
+create function trig_pkey1_before() returns trigger as '
#
# Create prepared plans on the first call
#
@@ -152,7 +152,7 @@ create trigger pkey1_before before insert or update or delete on T_pkey1
-- Trigger function to check for duplicate keys in T_pkey2
-- and to force key2 to be upper case only without leading whitespaces
--
-create function trig_pkey2_before() returns opaque as '
+create function trig_pkey2_before() returns trigger as '
#
# Prepare plan on first call
#
@@ -195,7 +195,7 @@ create trigger pkey2_before before insert or update on T_pkey2
-- in T_pkey2 are done so the trigger for primkey check on T_dta2
-- fired on our updates will see the new key values in T_pkey2.
--
-create function trig_pkey2_after() returns opaque as '
+create function trig_pkey2_after() returns trigger as '
#
# Prepare plans on first call
#
@@ -282,7 +282,7 @@ create trigger pkey2_after after update or delete on T_pkey2
--
-- Generic trigger function to check references in T_dta1 and T_dta2
--
-create function check_primkey() returns opaque as '
+create function check_primkey() returns trigger as '
#
# For every trigger/relation pair we create
# a saved plan and hold them in GD