Commit 2c6373fa authored by Peter Eisentraut's avatar Peter Eisentraut

Add --echo option to createlang and droplang.

from Oliver Elphick
parent 91e3b855
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createlang.sgml,v 1.15 2000/12/25 23:15:26 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/createlang.sgml,v 1.16 2001/05/09 22:08:18 petere Exp $
Postgres documentation Postgres documentation
--> -->
<refentry id="APP-CREATELANG"> <refentry id="APP-CREATELANG">
<docinfo> <docinfo>
<date>2000-11-11</date> <date>2001-05-09</date>
</docinfo> </docinfo>
<refmeta> <refmeta>
...@@ -61,6 +61,15 @@ Postgres documentation ...@@ -61,6 +61,15 @@ Postgres documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-e, --echo</term>
<listitem>
<para>
Displays SQL commands as they are executed.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-l, --list</term> <term>-l, --list</term>
<listitem> <listitem>
...@@ -71,6 +80,16 @@ Postgres documentation ...@@ -71,6 +80,16 @@ Postgres documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>--L <replaceable class="parameter">directory</replaceable></term>
<listitem>
<para>
Specifies the directory in which the language interpreter is
to be found. This is normally found automatically.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</para> </para>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/droplang.sgml,v 1.9 2000/12/25 23:15:26 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/droplang.sgml,v 1.10 2001/05/09 22:08:18 petere Exp $
Postgres documentation Postgres documentation
--> -->
<refentry id="APP-DROPLANG"> <refentry id="APP-DROPLANG">
<docinfo> <docinfo>
<date>2000-11-11</date> <date>2001-05-09</date>
</docinfo> </docinfo>
<refmeta> <refmeta>
...@@ -61,6 +61,15 @@ Postgres documentation ...@@ -61,6 +61,15 @@ Postgres documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-e, --echo</term>
<listitem>
<para>
Displays SQL commands as they are executed.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-l, --list</term> <term>-l, --list</term>
<listitem> <listitem>
......
#!/bin/sh #! /bin/sh
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# createlang.sh-- # createlang --
# Install a procedural language in a database # Install a procedural language in a database
# #
# 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.24 2001/05/09 22:08:19 petere Exp $
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.23 2001/02/18 18:34:01 momjian Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -20,6 +18,7 @@ PSQLOPT= ...@@ -20,6 +18,7 @@ PSQLOPT=
dbname= dbname=
langname= langname=
list= list=
showsql=
# Check for echo -n vs echo \c # Check for echo -n vs echo \c
...@@ -97,6 +96,9 @@ do ...@@ -97,6 +96,9 @@ do
--pglib=*) --pglib=*)
PGLIB=`echo "$1" | sed 's/^--pglib=//'` PGLIB=`echo "$1" | sed 's/^--pglib=//'`
;; ;;
--echo|-e)
showsql=yes
;;
-*) -*)
echo "$CMDNAME: invalid option: $1" 1>&2 echo "$CMDNAME: invalid option: $1" 1>&2
...@@ -146,7 +148,7 @@ fi ...@@ -146,7 +148,7 @@ fi
# ---------- # ----------
if [ -z "$dbname" ]; then if [ -z "$dbname" ]; then
echo "$CMDNAME: missing required argument database name" 1>&2 echo "$CMDNAME: missing required argument database name" 1>&2
echo "Try '$CMDNAME -?' for help." 1>&2 echo "Try '$CMDNAME --help' for help." 1>&2
exit 1 exit 1
fi fi
...@@ -155,7 +157,11 @@ fi ...@@ -155,7 +157,11 @@ fi
# List option # List option
# ---------- # ----------
if [ "$list" ]; then if [ "$list" ]; then
${PATHNAME}psql $PSQLOPT -d "$dbname" -P 'title=Procedural languages' -c "SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\", lancompiler as \"Compiler\" FROM pg_language WHERE lanispl = 't'" sqlcmd="SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\", lancompiler as \"Compiler\" FROM pg_language WHERE lanispl = 't';"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
${PATHNAME}psql $PSQLOPT -d "$dbname" -P 'title=Procedural languages' -c "$sqlcmd"
exit $? exit $?
fi fi
...@@ -237,7 +243,11 @@ PSQL="${PATHNAME}psql -A -t -q $PSQLOPT -d $dbname -c" ...@@ -237,7 +243,11 @@ PSQL="${PATHNAME}psql -A -t -q $PSQLOPT -d $dbname -c"
# ---------- # ----------
# Make sure the language isn't already installed # Make sure the language isn't already installed
# ---------- # ----------
res=`$PSQL "SELECT oid FROM pg_language WHERE lanname = '$langname'"` sqlcmd="SELECT oid FROM pg_language WHERE lanname = '$langname';"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
res=`$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
...@@ -251,7 +261,11 @@ fi ...@@ -251,7 +261,11 @@ fi
# ---------- # ----------
# Check that there is no function named as the call handler # Check that there is no function named as the call handler
# ---------- # ----------
res=`$PSQL "SELECT oid FROM pg_proc WHERE proname = '$handler'"` sqlcmd="SELECT oid FROM pg_proc WHERE proname = '$handler';"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
res=`$PSQL "$sqlcmd"`
if [ ! -z "$res" ]; then if [ ! -z "$res" ]; then
echo "$CMDNAME: A function named '$handler' already exists. Installation aborted." 1>&2 echo "$CMDNAME: A function named '$handler' already exists. Installation aborted." 1>&2
exit 1 exit 1
...@@ -260,13 +274,21 @@ fi ...@@ -260,13 +274,21 @@ fi
# ---------- # ----------
# Create the call handler and the language # Create the call handler and the language
# ---------- # ----------
$PSQL "CREATE FUNCTION $handler () RETURNS OPAQUE AS '$PGLIB/${object}$DLSUFFIX' LANGUAGE 'C'" sqlcmd="CREATE FUNCTION $handler () RETURNS OPAQUE AS '$PGLIB/${object}$DLSUFFIX' LANGUAGE 'C';"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
$PSQL "$sqlcmd"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "$CMDNAME: language installation failed" 1>&2 echo "$CMDNAME: language installation failed" 1>&2
exit 1 exit 1
fi fi
$PSQL "CREATE ${trusted}PROCEDURAL LANGUAGE '$langname' HANDLER $handler LANCOMPILER '$lancomp'" sqlcmd="CREATE ${trusted}PROCEDURAL LANGUAGE '$langname' HANDLER $handler LANCOMPILER '$lancomp';"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
$PSQL "$sqlcmd"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "$CMDNAME: language installation failed" 1>&2 echo "$CMDNAME: language installation failed" 1>&2
exit 1 exit 1
......
#!/bin/sh #! /bin/sh
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# createlang-- # droplang --
# Remove a procedural language from a database # Remove a procedural language from a database
# #
# 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.14 2001/05/09 22:08:19 petere Exp $
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.13 2001/02/18 18:34:01 momjian Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -21,6 +19,7 @@ dbname= ...@@ -21,6 +19,7 @@ dbname=
langname= langname=
echo= echo=
list= list=
showsql=
# Check for echo -n vs echo \c # Check for echo -n vs echo \c
...@@ -87,6 +86,9 @@ do ...@@ -87,6 +86,9 @@ do
--dbname=*) --dbname=*)
dbname=`echo "$1" | sed 's/^--dbname=//'` dbname=`echo "$1" | sed 's/^--dbname=//'`
;; ;;
--echo|-e)
showsql=yes
;;
-*) -*)
echo "$CMDNAME: invalid option: $1" 1>&2 echo "$CMDNAME: invalid option: $1" 1>&2
...@@ -128,7 +130,11 @@ fi ...@@ -128,7 +130,11 @@ fi
if [ "$list" ]; then if [ "$list" ]; then
${PATHNAME}psql $PSQLOPT -d "$dbname" -P 'title=Procedural languages' -c "SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\", lancompiler as \"Compiler\" FROM pg_language WHERE lanispl = 't'" sqlcmd="SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\", lancompiler as \"Compiler\" FROM pg_language WHERE lanispl = 't'"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
${PATHNAME}psql $PSQLOPT -d "$dbname" -P 'title=Procedural languages' -c "$sqlcmd"
exit $? exit $?
fi fi
...@@ -138,7 +144,7 @@ fi ...@@ -138,7 +144,7 @@ fi
# ---------- # ----------
if [ -z "$dbname" ]; then if [ -z "$dbname" ]; then
echo "$CMDNAME: missing required argument database name" 1>&2 echo "$CMDNAME: missing required argument database name" 1>&2
echo "Try '$CMDNAME -?' for help." 1>&2 echo "Try '$CMDNAME --help' for help." 1>&2
exit 1 exit 1
fi fi
...@@ -185,7 +191,11 @@ PSQL="${PATHNAME}psql -A -t -q $PSQLOPT -d $dbname -c" ...@@ -185,7 +191,11 @@ PSQL="${PATHNAME}psql -A -t -q $PSQLOPT -d $dbname -c"
# ---------- # ----------
# Make sure the language is installed # Make sure the language is installed
# ---------- # ----------
res=`$PSQL "SELECT oid FROM pg_language WHERE lanname = '$langname'"` sqlcmd="SELECT oid FROM pg_language WHERE lanname = '$langname';"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
res=`$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
...@@ -199,7 +209,11 @@ fi ...@@ -199,7 +209,11 @@ fi
# ---------- # ----------
# Check that there are no functions left defined in that language # Check that there are no functions left defined in that language
# ---------- # ----------
res=`$PSQL "SELECT COUNT(proname) FROM pg_proc P, pg_language L WHERE P.prolang = L.oid AND L.lanname = '$langname'"` sqlcmd="SELECT COUNT(proname) FROM pg_proc P, pg_language L WHERE P.prolang = L.oid AND L.lanname = '$langname';"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
res=`$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
...@@ -213,12 +227,21 @@ fi ...@@ -213,12 +227,21 @@ fi
# ---------- # ----------
# Drop the language and the call handler function # Drop the language and the call handler function
# ---------- # ----------
$PSQL "DROP PROCEDURAL LANGUAGE '$langname'" sqlcmd="DROP PROCEDURAL LANGUAGE '$langname';"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
$PSQL "$sqlcmd"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "$CMDNAME: language removal failed" 1>&2 echo "$CMDNAME: language removal failed" 1>&2
exit 1 exit 1
fi fi
$PSQL "DROP FUNCTION $handler()"
sqlcmd="DROP FUNCTION $handler();"
if [ "$showsql" = yes ]; then
echo "$sqlcmd"
fi
$PSQL "$sqlcmd"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "$CMDNAME: language removal failed" 1>&2 echo "$CMDNAME: language removal failed" 1>&2
exit 1 exit 1
......
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