Commit ee8ed85d authored by Peter Eisentraut's avatar Peter Eisentraut

Make LANCOMPILER clause in CREATE LANGUAGE optional. Allow "identifier"

syntax for language names (instead of 'string').

createlang now handles the case where a second language uses the same call
handler as an already installed language (e.g., plperl/plperlu).

droplang now handles the reverse case, i.e., dropping a language where
the call handler is still used by another language.  Moreover, droplang
can now be used to drop any user-defined language, not just the supplied
ones.
parent 38cfc958
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_function.sgml,v 1.24 2001/06/04 23:27:23 momjian Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_function.sgml,v 1.25 2001/08/13 21:34:51 petere Exp $
--> -->
<refentry id="SQL-CREATEFUNCTION"> <refentry id="SQL-CREATEFUNCTION">
...@@ -18,12 +18,12 @@ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_function.sgml,v 1.24 2001/06/04 ...@@ -18,12 +18,12 @@ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_function.sgml,v 1.24 2001/06/04
CREATE FUNCTION <replaceable class="parameter">name</replaceable> ( [ <replaceable class="parameter">argtype</replaceable> [, ...] ] ) CREATE FUNCTION <replaceable class="parameter">name</replaceable> ( [ <replaceable class="parameter">argtype</replaceable> [, ...] ] )
RETURNS <replaceable class="parameter">rettype</replaceable> RETURNS <replaceable class="parameter">rettype</replaceable>
AS '<replaceable class="parameter">definition</replaceable>' AS '<replaceable class="parameter">definition</replaceable>'
LANGUAGE '<replaceable class="parameter">langname</replaceable>' LANGUAGE <replaceable class="parameter">langname</replaceable>
[ WITH ( <replaceable class="parameter">attribute</replaceable> [, ...] ) ] [ WITH ( <replaceable class="parameter">attribute</replaceable> [, ...] ) ]
CREATE FUNCTION <replaceable class="parameter">name</replaceable> ( [ <replaceable class="parameter">argtype</replaceable> [, ...] ] ) CREATE FUNCTION <replaceable class="parameter">name</replaceable> ( [ <replaceable class="parameter">argtype</replaceable> [, ...] ] )
RETURNS <replaceable class="parameter">rettype</replaceable> RETURNS <replaceable class="parameter">rettype</replaceable>
AS '<replaceable class="parameter">obj_file</replaceable>', '<replaceable class="parameter">link_symbol</replaceable>' AS '<replaceable class="parameter">obj_file</replaceable>', '<replaceable class="parameter">link_symbol</replaceable>'
LANGUAGE '<replaceable class="parameter">langname</replaceable>' LANGUAGE <replaceable class="parameter">langname</replaceable>
[ WITH ( <replaceable class="parameter">attribute</replaceable> [, ...] ) ] [ WITH ( <replaceable class="parameter">attribute</replaceable> [, ...] ) ]
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
...@@ -123,13 +123,14 @@ CREATE FUNCTION <replaceable class="parameter">name</replaceable> ( [ <replaceab ...@@ -123,13 +123,14 @@ CREATE FUNCTION <replaceable class="parameter">name</replaceable> ( [ <replaceab
<listitem> <listitem>
<para> <para>
May be '<literal>sql</literal>', '<literal>C</literal>', May be <literal>SQL</literal>, <literal>C</literal>,
'<literal>internal</literal>', or '<replaceable <literal>internal</literal>, or <replaceable
class="parameter">plname</replaceable>', where '<replaceable class="parameter">plname</replaceable>, where <replaceable
class="parameter">plname</replaceable>' is the name of a class="parameter">plname</replaceable> is the name of a
created procedural language. See created procedural language. See
<xref linkend="sql-createlanguage"> <xref linkend="sql-createlanguage">
for details. for details. For backward compatibility, the name may be
enclosed by single quotes.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -261,7 +262,7 @@ CREATE FUNCTION <replaceable class="parameter">name</replaceable> ( [ <replaceab ...@@ -261,7 +262,7 @@ CREATE FUNCTION <replaceable class="parameter">name</replaceable> ( [ <replaceab
<programlisting> <programlisting>
CREATE FUNCTION one() RETURNS integer CREATE FUNCTION one() RETURNS integer
AS 'SELECT 1 AS RESULT;' AS 'SELECT 1 AS RESULT;'
LANGUAGE 'sql'; LANGUAGE SQL;
SELECT one() AS answer; SELECT one() AS answer;
<computeroutput> <computeroutput>
...@@ -281,7 +282,7 @@ SELECT one() AS answer; ...@@ -281,7 +282,7 @@ SELECT one() AS answer;
<programlisting> <programlisting>
CREATE FUNCTION ean_checkdigit(char, char) RETURNS boolean CREATE FUNCTION ean_checkdigit(char, char) RETURNS boolean
AS '/usr1/proj/bray/sql/funcs.so' LANGUAGE 'c'; AS '/usr1/proj/bray/sql/funcs.so' LANGUAGE C;
CREATE TABLE product ( CREATE TABLE product (
id char(8) PRIMARY KEY, id char(8) PRIMARY KEY,
...@@ -306,7 +307,7 @@ CREATE TABLE product ( ...@@ -306,7 +307,7 @@ CREATE TABLE product (
<programlisting> <programlisting>
CREATE FUNCTION point(complex) RETURNS point CREATE FUNCTION point(complex) RETURNS point
AS '/home/bernie/pgsql/lib/complex.so', 'complex_to_point' AS '/home/bernie/pgsql/lib/complex.so', 'complex_to_point'
LANGUAGE 'c'; LANGUAGE C;
</programlisting> </programlisting>
The C declaration of the function could be: The C declaration of the function could be:
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_language.sgml,v 1.14 2000/11/20 20:36:46 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_language.sgml,v 1.15 2001/08/13 21:34:51 petere Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -23,9 +23,8 @@ Postgres documentation ...@@ -23,9 +23,8 @@ Postgres documentation
<date>1999-07-20</date> <date>1999-07-20</date>
</refsynopsisdivinfo> </refsynopsisdivinfo>
<synopsis> <synopsis>
CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE '<replaceable class="parameter">langname</replaceable>' CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">langname</replaceable>
HANDLER <replaceable class="parameter">call_handler</replaceable> HANDLER <replaceable class="parameter">call_handler</replaceable>
LANCOMPILER '<replaceable class="parameter">comment</replaceable>'
</synopsis> </synopsis>
<refsect2 id="R2-SQL-CREATELANGUAGE-1"> <refsect2 id="R2-SQL-CREATELANGUAGE-1">
...@@ -62,6 +61,10 @@ CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE '<replaceable class="parameter">langn ...@@ -62,6 +61,10 @@ CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE '<replaceable class="parameter">langn
language cannot override one of the built-in languages of language cannot override one of the built-in languages of
<productname>Postgres</productname>. <productname>Postgres</productname>.
</para> </para>
<para>
For backward compatibility, the name may be enclosed by single
quotes.
</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -77,20 +80,6 @@ CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE '<replaceable class="parameter">langn ...@@ -77,20 +80,6 @@ CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE '<replaceable class="parameter">langn
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><replaceable class="parameter">comment</replaceable></term>
<listitem>
<para>
The <function>LANCOMPILER</function> argument is the
string that will be
inserted in the <literal>LANCOMPILER</literal> attribute
of the new
<filename>pg_language</filename> entry. At present,
<productname>Postgres</productname> does not use
this attribute in any way.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</para> </para>
...@@ -346,10 +335,9 @@ plsample_call_handler(PG_FUNCTION_ARGS) ...@@ -346,10 +335,9 @@ plsample_call_handler(PG_FUNCTION_ARGS)
<programlisting> <programlisting>
CREATE FUNCTION plsample_call_handler () RETURNS opaque CREATE FUNCTION plsample_call_handler () RETURNS opaque
AS '/usr/local/pgsql/lib/plsample.so' AS '/usr/local/pgsql/lib/plsample.so'
LANGUAGE 'C'; LANGUAGE C;
CREATE PROCEDURAL LANGUAGE 'plsample' CREATE LANGUAGE plsample
HANDLER plsample_call_handler HANDLER plsample_call_handler;
LANCOMPILER 'PL/Sample';
</programlisting> </programlisting>
</para> </para>
</refsect1> </refsect1>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_language.sgml,v 1.9 2000/12/25 23:15:26 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_language.sgml,v 1.10 2001/08/13 21:34:51 petere Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -23,7 +23,7 @@ Postgres documentation ...@@ -23,7 +23,7 @@ Postgres documentation
<date>1999-07-20</date> <date>1999-07-20</date>
</refsynopsisdivinfo> </refsynopsisdivinfo>
<synopsis> <synopsis>
DROP [ PROCEDURAL ] LANGUAGE '<replaceable class="PARAMETER">name</replaceable>' DROP [ PROCEDURAL ] LANGUAGE <replaceable class="PARAMETER">name</replaceable>
</synopsis> </synopsis>
<refsect2 id="R2-SQL-DROPLANGUAGE-1"> <refsect2 id="R2-SQL-DROPLANGUAGE-1">
...@@ -40,7 +40,8 @@ DROP [ PROCEDURAL ] LANGUAGE '<replaceable class="PARAMETER">name</replaceable>' ...@@ -40,7 +40,8 @@ DROP [ PROCEDURAL ] LANGUAGE '<replaceable class="PARAMETER">name</replaceable>'
<term><replaceable class="PARAMETER">name</replaceable></term> <term><replaceable class="PARAMETER">name</replaceable></term>
<listitem> <listitem>
<para> <para>
The name of an existing procedural language. The name of an existing procedural language. For backward
compatibility, the name may be enclosed by single quotes.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -132,7 +133,7 @@ ERROR: Language "<replaceable class="parameter">name</replaceable>" doesn't exis ...@@ -132,7 +133,7 @@ ERROR: Language "<replaceable class="parameter">name</replaceable>" doesn't exis
This command removes the PL/Sample language: This command removes the PL/Sample language:
<programlisting> <programlisting>
DROP PROCEDURAL LANGUAGE 'plsample'; DROP LANGUAGE plsample;
</programlisting> </programlisting>
</para> </para>
</refsect1> </refsect1>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/xplang.sgml,v 1.13 2001/05/19 09:01:10 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/xplang.sgml,v 1.14 2001/08/13 21:34:51 petere Exp $
--> -->
<chapter id="xplang"> <chapter id="xplang">
...@@ -79,7 +79,7 @@ createlang plpgsql template1 ...@@ -79,7 +79,7 @@ createlang plpgsql template1
<synopsis> <synopsis>
CREATE FUNCTION <replaceable>handler_function_name</replaceable> () CREATE FUNCTION <replaceable>handler_function_name</replaceable> ()
RETURNS OPAQUE AS RETURNS OPAQUE AS
'<replaceable>path-to-shared-object</replaceable>' LANGUAGE 'C'; '<replaceable>path-to-shared-object</replaceable>' LANGUAGE C;
</synopsis> </synopsis>
The special return type of <type>OPAQUE</type> tells The special return type of <type>OPAQUE</type> tells
the database that this function does not return one of the database that this function does not return one of
...@@ -92,9 +92,8 @@ CREATE FUNCTION <replaceable>handler_function_name</replaceable> () ...@@ -92,9 +92,8 @@ CREATE FUNCTION <replaceable>handler_function_name</replaceable> ()
<para> <para>
The PL must be declared with the command The PL must be declared with the command
<synopsis> <synopsis>
CREATE <optional>TRUSTED</optional> <optional>PROCEDURAL</optional> LANGUAGE '<replaceable>language-name</replaceable>' CREATE <optional>TRUSTED</optional> <optional>PROCEDURAL</optional> LANGUAGE <replaceable>language-name</replaceable>
HANDLER <replaceable>handler_function_name</replaceable> HANDLER <replaceable>handler_function_name</replaceable>;
LANCOMPILER '<replaceable>description</replaceable>';
</synopsis> </synopsis>
The optional key word <token>TRUSTED</token> tells The optional key word <token>TRUSTED</token> tells
whether ordinary database users that have no superuser whether ordinary database users that have no superuser
...@@ -130,7 +129,7 @@ CREATE <optional>TRUSTED</optional> <optional>PROCEDURAL</optional> LANGUAGE '<r ...@@ -130,7 +129,7 @@ CREATE <optional>TRUSTED</optional> <optional>PROCEDURAL</optional> LANGUAGE '<r
<programlisting> <programlisting>
CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS
'$libdir/plpgsql' LANGUAGE 'C'; '$libdir/plpgsql' LANGUAGE C;
</programlisting> </programlisting>
</para> </para>
</step> </step>
...@@ -139,9 +138,8 @@ CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS ...@@ -139,9 +138,8 @@ CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS
<para> <para>
The command The command
<programlisting> <programlisting>
CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql
HANDLER plpgsql_call_handler HANDLER plpgsql_call_handler;
LANCOMPILER 'PL/pgSQL';
</programlisting> </programlisting>
then defines that the previously declared call handler function then defines that the previously declared call handler function
should be invoked for functions and trigger procedures where the should be invoked for functions and trigger procedures where the
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.243 2001/08/10 18:57:36 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.244 2001/08/13 21:34:51 petere Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -163,7 +163,8 @@ static void doNegateFloat(Value *v); ...@@ -163,7 +163,8 @@ static void doNegateFloat(Value *v);
%type <list> OptUserList %type <list> OptUserList
%type <defelt> OptUserElem %type <defelt> OptUserElem
%type <boolean> TriggerActionTime, TriggerForSpec, PLangTrusted, opt_procedural %type <boolean> TriggerActionTime, TriggerForSpec, opt_trusted, opt_procedural
%type <str> opt_lancompiler
%type <str> OptConstrFromTable %type <str> OptConstrFromTable
...@@ -1688,23 +1689,26 @@ IntegerOnly: Iconst ...@@ -1688,23 +1689,26 @@ IntegerOnly: Iconst
* *
*****************************************************************************/ *****************************************************************************/
CreatePLangStmt: CREATE PLangTrusted opt_procedural LANGUAGE Sconst CreatePLangStmt: CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
HANDLER func_name LANCOMPILER Sconst HANDLER func_name opt_lancompiler
{ {
CreatePLangStmt *n = makeNode(CreatePLangStmt); CreatePLangStmt *n = makeNode(CreatePLangStmt);
n->plname = $5; n->plname = $5;
n->plhandler = $7; n->plhandler = $7;
n->plcompiler = $9; n->plcompiler = $8;
n->pltrusted = $2; n->pltrusted = $2;
$$ = (Node *)n; $$ = (Node *)n;
} }
; ;
PLangTrusted: TRUSTED { $$ = TRUE; } opt_trusted: TRUSTED { $$ = TRUE; }
| /*EMPTY*/ { $$ = FALSE; } | /*EMPTY*/ { $$ = FALSE; }
; ;
DropPLangStmt: DROP opt_procedural LANGUAGE Sconst opt_lancompiler: LANCOMPILER Sconst { $$ = $2; }
| /*EMPTY*/ { $$ = ""; }
DropPLangStmt: DROP opt_procedural LANGUAGE ColId_or_Sconst
{ {
DropPLangStmt *n = makeNode(DropPLangStmt); DropPLangStmt *n = makeNode(DropPLangStmt);
n->plname = $4; n->plname = $4;
...@@ -2511,7 +2515,7 @@ RecipeStmt: EXECUTE RECIPE recipe_name ...@@ -2511,7 +2515,7 @@ RecipeStmt: EXECUTE RECIPE recipe_name
*****************************************************************************/ *****************************************************************************/
ProcedureStmt: CREATE FUNCTION func_name func_args ProcedureStmt: CREATE FUNCTION func_name func_args
RETURNS func_return AS func_as LANGUAGE Sconst opt_with RETURNS func_return AS func_as LANGUAGE ColId_or_Sconst opt_with
{ {
ProcedureStmt *n = makeNode(ProcedureStmt); ProcedureStmt *n = makeNode(ProcedureStmt);
n->funcname = $3; n->funcname = $3;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.28 2001/06/18 21:40:06 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.29 2001/08/13 21:34:54 petere Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -121,7 +121,7 @@ do ...@@ -121,7 +121,7 @@ do
shift shift
done done
if [ "$usage" ]; then if [ -n "$usage" ]; then
echo "$CMDNAME installs a procedural language into a PostgreSQL database." echo "$CMDNAME installs a procedural language into a PostgreSQL database."
echo echo
echo "Usage:" echo "Usage:"
...@@ -158,7 +158,7 @@ fi ...@@ -158,7 +158,7 @@ fi
# List option # List option
# ---------- # ----------
if [ "$list" ]; then if [ "$list" ]; then
sqlcmd="SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\", lancompiler as \"Compiler\" FROM pg_language WHERE lanispl = 't';" sqlcmd="SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\" FROM pg_language WHERE lanispl = TRUE;"
if [ "$showsql" = yes ]; then if [ "$showsql" = yes ]; then
echo "$sqlcmd" echo "$sqlcmd"
fi fi
...@@ -185,46 +185,43 @@ fi ...@@ -185,46 +185,43 @@ fi
# ---------- # ----------
# Check if supported and set related values # Check if supported and set related values
# ---------- # ----------
langname=`echo "$langname" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
case "$langname" in case "$langname" in
plpgsql) plpgsql)
lancomp="PL/pgSQL"
trusted="TRUSTED " trusted="TRUSTED "
handler="plpgsql_call_handler" handler="plpgsql_call_handler"
object="plpgsql" object="plpgsql"
;; ;;
pltcl) pltcl)
lancomp="PL/Tcl"
trusted="TRUSTED " trusted="TRUSTED "
handler="pltcl_call_handler" handler="pltcl_call_handler"
object="pltcl" object="pltcl"
;; ;;
pltclu) pltclu)
lancomp="PL/Tcl (untrusted)"
trusted="" trusted=""
handler="pltclu_call_handler" handler="pltclu_call_handler"
object="pltcl" object="pltcl"
;; ;;
plperl) plperl)
lancomp="PL/Perl"
trusted="TRUSTED " trusted="TRUSTED "
handler="plperl_call_handler" handler="plperl_call_handler"
object="plperl" object="plperl"
;; ;;
plperlu) plperlu)
lancomp="PL/Perl (untrusted)"
trusted="" trusted=""
handler="plperl_call_handler" handler="plperl_call_handler"
object="plperl" object="plperl"
;; ;;
plpython) plpython)
lancomp="PL/Python"
trusted="TRUSTED " trusted="TRUSTED "
handler="plpython_call_handler" handler="plpython_call_handler"
object="plpython" object="plpython"
;; ;;
*) *)
echo "$CMDNAME: unsupported language '$langname'" 1>&2 echo "$CMDNAME: unsupported language \"$langname\"" 1>&2
echo "Supported languages are 'plpgsql', 'pltcl', 'pltclu', 'plperl', and 'plpython'." 1>&2 echo "Supported languages are plpgsql, pltcl, pltclu, plperl, plperlu, and plpython." 1>&2
exit 1 exit 1
;; ;;
esac esac
...@@ -244,39 +241,42 @@ if [ $? -ne 0 ]; then ...@@ -244,39 +241,42 @@ if [ $? -ne 0 ]; then
echo "$CMDNAME: external error" 1>&2 echo "$CMDNAME: external error" 1>&2
exit 1 exit 1
fi fi
if [ "$res" ]; then if [ -n "$res" ]; then
echo "$CMDNAME: '$langname' is already installed in database $dbname" 1>&2 echo "$CMDNAME: language \"$langname\" is already installed in database $dbname" 1>&2
# separate exit status for "already installed" # separate exit status for "already installed"
exit 2 exit 2
fi fi
# ---------- # ----------
# Check that there is no function named as the call handler # Check whether the call handler exists
# ---------- # ----------
sqlcmd="SELECT oid FROM pg_proc WHERE proname = '$handler';" sqlcmd="SELECT oid FROM pg_proc WHERE proname = '$handler' AND prorettype = 0 AND pronargs = 0;"
if [ "$showsql" = yes ]; then if [ "$showsql" = yes ]; then
echo "$sqlcmd" echo "$sqlcmd"
fi fi
res=`$PSQL "$sqlcmd"` res=`$PSQL "$sqlcmd"`
if [ ! -z "$res" ]; then if [ -n "$res" ]; then
echo "$CMDNAME: A function named '$handler' already exists. Installation aborted." 1>&2 handlerexists=yes
exit 1 else
handlerexists=no
fi fi
# ---------- # ----------
# Create the call handler and the language # Create the call handler and the language
# ---------- # ----------
sqlcmd="CREATE FUNCTION $handler () RETURNS OPAQUE AS '$PGLIB/${object}' LANGUAGE 'C';" if [ "$handlerexists" = no ]; then
if [ "$showsql" = yes ]; then sqlcmd="CREATE FUNCTION \"$handler\" () RETURNS OPAQUE AS '$PGLIB/${object}' LANGUAGE C;"
echo "$sqlcmd" if [ "$showsql" = yes ]; then
fi echo "$sqlcmd"
$PSQL "$sqlcmd" fi
if [ $? -ne 0 ]; then $PSQL "$sqlcmd"
echo "$CMDNAME: language installation failed" 1>&2 if [ $? -ne 0 ]; then
exit 1 echo "$CMDNAME: language installation failed" 1>&2
exit 1
fi
fi fi
sqlcmd="CREATE ${trusted}PROCEDURAL LANGUAGE '$langname' HANDLER $handler LANCOMPILER '$lancomp';" sqlcmd="CREATE ${trusted}LANGUAGE \"$langname\" HANDLER \"$handler\";"
if [ "$showsql" = yes ]; then if [ "$showsql" = yes ]; then
echo "$sqlcmd" echo "$sqlcmd"
fi fi
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.15 2001/05/12 01:30:30 petere Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.16 2001/08/13 21:34:54 petere Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -130,7 +130,7 @@ fi ...@@ -130,7 +130,7 @@ fi
if [ "$list" ]; then if [ "$list" ]; then
sqlcmd="SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\", lancompiler as \"Compiler\" FROM pg_language WHERE lanispl = 't'" sqlcmd="SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\" FROM pg_language WHERE lanispl = TRUE"
if [ "$showsql" = yes ]; then if [ "$showsql" = yes ]; then
echo "$sqlcmd" echo "$sqlcmd"
fi fi
...@@ -157,55 +157,23 @@ if [ -z "$langname" ]; then ...@@ -157,55 +157,23 @@ if [ -z "$langname" ]; then
read langname read langname
fi fi
# ----------
# Check if supported and set related values
# ----------
case "$langname" in
plpgsql)
lancomp="PL/pgSQL"
handler="plpgsql_call_handler"
;;
pltcl)
lancomp="PL/Tcl"
handler="pltcl_call_handler"
;;
pltclu)
lancomp="PL/Tcl (untrusted)"
handler="pltclu_call_handler"
;;
plperl)
lancomp="PL/Perl"
handler="plperl_call_handler"
;;
plpython)
lancomp="PL/Python"
handler="plpython_call_handler"
;;
*)
echo "$CMDNAME: unsupported language '$langname'" 1>&2
echo "Supported languages are 'plpgsql', 'pltcl', 'pltclu', 'plperl', and 'plpython'." 1>&2
exit 1
;;
esac
PSQL="${PATHNAME}psql -A -t -q $PSQLOPT -d $dbname -c" PSQL="${PATHNAME}psql -A -t -q $PSQLOPT -d $dbname -c"
# ---------- # ----------
# Make sure the language is installed # Make sure the language is installed and find the oid of the handler function
# ---------- # ----------
sqlcmd="SELECT oid FROM pg_language WHERE lanname = '$langname';" sqlcmd="SELECT lanplcallfoid FROM pg_language WHERE lanname = '$langname' AND lanispl;"
if [ "$showsql" = yes ]; then if [ "$showsql" = yes ]; then
echo "$sqlcmd" echo "$sqlcmd"
fi fi
res=`$PSQL "$sqlcmd"` lanplcallfoid=`$PSQL "$sqlcmd"`
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "$CMDNAME: external error" 1>&2 echo "$CMDNAME: external error" 1>&2
exit 1 exit 1
fi fi
if [ -z "$res" ]; then if [ -z "$lanplcallfoid" ]; then
echo "$CMDNAME: '$langname' is not installed in database $dbname" 1>&2 echo "$CMDNAME: language \"$langname\" is not installed in database $dbname" 1>&2
exit 1 exit 1
fi fi
...@@ -224,14 +192,32 @@ if [ $? -ne 0 ]; then ...@@ -224,14 +192,32 @@ if [ $? -ne 0 ]; then
fi fi
if [ "$res" -ne 0 ]; then if [ "$res" -ne 0 ]; then
echo "$CMDNAME: There are $res functions/trigger procedures declared in language" 1>&2 echo "$CMDNAME: There are $res functions/trigger procedures declared in language" 1>&2
echo "$lancomp. Language not removed." 1>&2 echo "$langname. Language not removed." 1>&2
exit 1 exit 1
fi fi
# ---------- # ----------
# Drop the language and the call handler function # Check that the handler function isn't used by some other language
# ---------- # ----------
sqlcmd="DROP PROCEDURAL LANGUAGE '$langname';" sqlcmd="SELECT count(*) FROM pg_language WHERE lanplcallfoid = $lanplcallfoid AND lanname <> '$langname';"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
res=`$PSQL "$sqlcmd"`
if [ $? -ne 0 ]; then
echo "$CMDNAME: external error" 1>&2
exit 1
fi
if [ "$res" -eq 0 ]; then
keephandler=no
else
keephandler=yes
fi
# ----------
# Drop the language
# ----------
sqlcmd="DROP LANGUAGE \"$langname\";"
if [ "$showsql" = yes ]; then if [ "$showsql" = yes ]; then
echo "$sqlcmd" echo "$sqlcmd"
fi fi
...@@ -241,7 +227,24 @@ if [ $? -ne 0 ]; then ...@@ -241,7 +227,24 @@ if [ $? -ne 0 ]; then
exit 1 exit 1
fi fi
sqlcmd="DROP FUNCTION $handler();" # ----------
# Drop the call handler
# ----------
if [ "$keephandler" = yes ]; then
exit 0
fi
sqlcmd="SELECT proname FROM pg_proc WHERE oid = $lanplcallfoid;"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
handler=`$PSQL "$sqlcmd"`
if [ $? -ne 0 ]; then
echo "$CMDNAME: external error" 1>&2
exit 1
fi
sqlcmd="DROP FUNCTION \"$handler\" ();"
if [ "$showsql" = yes ]; then if [ "$showsql" = yes ]; then
echo "$sqlcmd" echo "$sqlcmd"
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment