Miscellaneous cleanups of places that needed to account for new

pg_language entries.
This commit is contained in:
Tom Lane 2000-05-28 20:34:52 +00:00
parent ab843085f1
commit 80648891cc
4 changed files with 36 additions and 53 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.48 2000/05/18 16:09:38 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.49 2000/05/28 20:34:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -367,7 +367,8 @@ RemoveFunction(char *functionName, /* function name to be removed */
func_error("RemoveFunction", functionName, nargs, argList, NULL);
}
if ((((Form_pg_proc) GETSTRUCT(tup))->prolang) == INTERNALlanguageId)
if (((Form_pg_proc) GETSTRUCT(tup))->prolang == INTERNALlanguageId ||
((Form_pg_proc) GETSTRUCT(tup))->prolang == NEWINTERNALlanguageId)
{
heap_close(relation, RowExclusiveLock);
elog(NOTICE, "Removing built-in function \"%s\"", functionName);

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.65 2000/05/28 17:55:55 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.66 2000/05/28 20:34:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -58,6 +58,7 @@ CreateTrigger(CreateTrigStmt *stmt)
Relation idescs[Num_pg_trigger_indices];
Relation ridescs[Num_pg_class_indices];
Oid fargtypes[FUNC_MAX_ARGS];
Oid funclang;
int found = 0;
int i;
char constrtrigname[NAMEDATALEN];
@ -154,24 +155,26 @@ CreateTrigger(CreateTrigStmt *stmt)
Int32GetDatum(0),
PointerGetDatum(fargtypes),
0);
if (!HeapTupleIsValid(tuple) ||
((Form_pg_proc) GETSTRUCT(tuple))->pronargs != 0)
if (!HeapTupleIsValid(tuple))
elog(ERROR, "CreateTrigger: function %s() does not exist",
stmt->funcname);
if (((Form_pg_proc) GETSTRUCT(tuple))->prorettype != 0)
elog(ERROR, "CreateTrigger: function %s() must return OPAQUE",
stmt->funcname);
if (((Form_pg_proc) GETSTRUCT(tuple))->prolang != ClanguageId &&
((Form_pg_proc) GETSTRUCT(tuple))->prolang != INTERNALlanguageId)
funclang = ((Form_pg_proc) GETSTRUCT(tuple))->prolang;
if (funclang != ClanguageId &&
funclang != NEWClanguageId &&
funclang != INTERNALlanguageId &&
funclang != NEWINTERNALlanguageId)
{
HeapTuple langTup;
langTup = SearchSysCacheTuple(LANGOID,
ObjectIdGetDatum(((Form_pg_proc) GETSTRUCT(tuple))->prolang),
ObjectIdGetDatum(funclang),
0, 0, 0);
if (!HeapTupleIsValid(langTup))
elog(ERROR, "CreateTrigger: cache lookup for PL %u failed",
((Form_pg_proc) GETSTRUCT(tuple))->prolang);
funclang);
if (((Form_pg_language) GETSTRUCT(langTup))->lanispl == false)
elog(ERROR, "CreateTrigger: only builtin, C and PL functions are supported");
}

View File

@ -22,7 +22,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.147 2000/04/14 01:34:24 tgl Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.148 2000/05/28 20:34:52 tgl Exp $
*
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
*
@ -2575,6 +2575,10 @@ dumpOneFunc(FILE *fout, FuncInfo *finfo, int i,
int j;
char *func_def;
char func_lang[NAMEDATALEN + 1];
PGresult *res;
int nlangs;
int i_lanname;
char query[256];
if (finfo[i].dumped)
return;
@ -2583,54 +2587,29 @@ dumpOneFunc(FILE *fout, FuncInfo *finfo, int i,
becomeUser(fout, finfo[i].usename);
if (finfo[i].lang == INTERNALlanguageId)
sprintf(query, "SELECT lanname FROM pg_language WHERE oid = %u",
finfo[i].lang);
res = PQexec(g_conn, query);
if (!res ||
PQresultStatus(res) != PGRES_TUPLES_OK)
{
func_def = finfo[i].prosrc;
strcpy(func_lang, "INTERNAL");
fprintf(stderr, "dumpOneFunc(): SELECT for procedural language failed. Explanation from backend: '%s'.\n", PQerrorMessage(g_conn));
exit_nicely(g_conn);
}
else if (finfo[i].lang == ClanguageId)
nlangs = PQntuples(res);
if (nlangs != 1)
{
func_def = finfo[i].probin;
strcpy(func_lang, "C");
fprintf(stderr, "dumpOneFunc(): procedural language for function %s not found\n", finfo[i].proname);
exit_nicely(g_conn);
}
else if (finfo[i].lang == SQLlanguageId)
{
func_def = finfo[i].prosrc;
strcpy(func_lang, "SQL");
}
else
{
PGresult *res;
int nlangs;
int i_lanname;
char query[256];
sprintf(query, "SELECT lanname FROM pg_language "
"WHERE oid = %u",
finfo[i].lang);
res = PQexec(g_conn, query);
if (!res ||
PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "dumpOneFunc(): SELECT for procedural language failed. Explanation from backend: '%s'.\n", PQerrorMessage(g_conn));
exit_nicely(g_conn);
}
nlangs = PQntuples(res);
i_lanname = PQfnumber(res, "lanname");
if (nlangs != 1)
{
fprintf(stderr, "dumpOneFunc(): procedural language for function %s not found\n", finfo[i].proname);
exit_nicely(g_conn);
}
func_def = finfo[i].prosrc;
strcpy(func_lang, PQgetvalue(res, 0, i_lanname));
i_lanname = PQfnumber(res, "lanname");
func_def = finfo[i].prosrc;
strcpy(func_lang, PQgetvalue(res, 0, i_lanname));
PQclear(res);
}
PQclear(res);
if (dropSchema)
{

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: parsenodes.h,v 1.104 2000/04/12 17:16:40 momjian Exp $
* $Id: parsenodes.h,v 1.105 2000/05/28 20:34:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -248,7 +248,7 @@ typedef struct CreateTrigStmt
bool before; /* BEFORE/AFTER */
bool row; /* ROW/STATEMENT */
char actions[4]; /* Insert, Update, Delete */
char *lang; /* NULL (which means Clanguage) */
char *lang; /* currently not used, always NULL */
char *text; /* AS 'text' */
List *attr; /* UPDATE OF a, b,... (NI) or NULL */
char *when; /* WHEN 'a > 10 ...' (NI) or NULL */