diff options
author | Jan Wieck | 1999-05-20 16:50:08 +0000 |
---|---|---|
committer | Jan Wieck | 1999-05-20 16:50:08 +0000 |
commit | 3de11d6526165154fe90bc161384e579dcdf1715 (patch) | |
tree | 3caccc584122bbbe020375d09abd547e71e9edf0 /src | |
parent | 33773af95bb110e9bfe805370a8b236df03d98fb (diff) |
Removed the automatic installation of built procedural languages
from initdb again.
Added two new commands, createlang and destroylang to bin. These
hopefully end this damned mklang.sql discussion.
Jan
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/Makefile | 5 | ||||
-rw-r--r-- | src/bin/createlang/Makefile | 29 | ||||
-rw-r--r-- | src/bin/createlang/createlang.sh | 173 | ||||
-rw-r--r-- | src/bin/destroylang/Makefile | 28 | ||||
-rw-r--r-- | src/bin/destroylang/destroylang.sh | 139 | ||||
-rw-r--r-- | src/bin/initdb/Makefile | 3 | ||||
-rw-r--r-- | src/bin/initdb/initdb.sh | 22 | ||||
-rwxr-xr-x | src/test/regress/regress.sh | 9 |
8 files changed, 382 insertions, 26 deletions
diff --git a/src/bin/Makefile b/src/bin/Makefile index e8fad4374dd..6d7fabd1bdb 100644 --- a/src/bin/Makefile +++ b/src/bin/Makefile @@ -7,7 +7,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/Makefile,v 1.17 1998/12/18 17:53:21 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/Makefile,v 1.18 1999/05/20 16:49:59 wieck Exp $ # #------------------------------------------------------------------------- @@ -15,7 +15,8 @@ SRCDIR= .. include ../Makefile.global DIRS = pg_id pg_version psql pg_dump pg_passwd cleardbdir createdb \ - createuser destroydb destroyuser initdb vacuumdb initlocation ipcclean + createlang createuser destroydb destroylang destroyuser initdb \ + vacuumdb initlocation ipcclean ifdef MULTIBYTE DIRS += pg_encoding diff --git a/src/bin/createlang/Makefile b/src/bin/createlang/Makefile new file mode 100644 index 00000000000..35b18f93e18 --- /dev/null +++ b/src/bin/createlang/Makefile @@ -0,0 +1,29 @@ +#------------------------------------------------------------------------- +# +# Makefile.inc-- +# Makefile for bin/createlang +# +# Copyright (c) 1994, Regents of the University of California +# +# +# IDENTIFICATION +# $Header: /cvsroot/pgsql/src/bin/createlang/Attic/Makefile,v 1.1 1999/05/20 16:50:00 wieck Exp $ +# +#------------------------------------------------------------------------- + +SRCDIR= ../.. +include ../../Makefile.global + +all: createlang + +createlang: createlang.sh + sed -e 's/__DLSUFFIX__/$(DLSUFFIX)/' \ + createlang.sh > createlang + +install: createlang + $(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$< + +clean: + rm -f createlang + +dep depend: diff --git a/src/bin/createlang/createlang.sh b/src/bin/createlang/createlang.sh new file mode 100644 index 00000000000..1f8ff5b25a9 --- /dev/null +++ b/src/bin/createlang/createlang.sh @@ -0,0 +1,173 @@ +#!/bin/sh +#------------------------------------------------------------------------- +# +# createlang.sh-- +# Install a procedural language in a database +# +# Copyright (c) 1994, Regents of the University of California +# +# +# IDENTIFICATION +# $Header: /cvsroot/pgsql/src/bin/createlang/Attic/createlang.sh,v 1.1 1999/05/20 16:50:00 wieck Exp $ +# +#------------------------------------------------------------------------- + +CMDNAME=`basename $0` + +# ---------- +# Find the default PGLIB directory +# ---------- +postconfig_result="`sh -c postconfig 2>/dev/null`" +if [ ! -z "$postconfig_result" ]; then + set -a + eval "$postconfig_result" + set +a +fi + +# ---------- +# Determine username +# ---------- +if [ -z "$USER" ]; then + if [ -z "$LOGNAME" ]; then + if [ -z "`whoami`" ]; then + echo "$CMDNAME: cannot determine user name" + exit 1 + fi + else + USER=$LOGNAME + export USER + fi +fi + +# ---------- +# Get options, language name and dbname +# ---------- +dbname=$USER +while [ -n "$1" ] +do + case $1 in + --pglib) PGLIB=$2; shift;; + -a) AUTHSYS=$2; shift;; + -h) PGHOST=$2; shift;; + -p) PGPORT=$2; shift;; + *) langname=$1 + if [ -n "$2" ]; then + shift + dbname=$1 + fi;; + esac + shift; +done + +# ---------- +# Check that we have PGLIB +# ---------- +if [ -z "$PGLIB" ]; then + echo "Cannot determine PostgreSQL lib directory (PGLIB)." + echo "You must identify the PGLIB either with a --pglib option" + echo "or by setting the PGLIB environment variable." + exit 1 +fi + +# ---------- +# If not given on the commandline, ask for the language +# ---------- +if [ -z "$langname" ]; then + echo -n "Language to install in database $dbname: " + read langname +fi + +# ---------- +# Check if supported and set related values +# ---------- +case "$langname" in + plpgsql) lancomp="PL/pgSQL" + trusted="TRUSTED" + handler="plpgsql_call_handler";; + pltcl) lancomp="PL/Tcl" + trusted="TRUSTED" + handler="pltcl_call_handler";; + *) echo "$CMDNAME: unsupported language '$langname'" + echo " supported languages are plpgsql and pltcl" + exit 1;; +esac + +# ---------- +# Check that the shared object for the call handler is installed +# in PGLIB +# ---------- +if [ ! -f $PGLIB/${langname}__DLSUFFIX__ ]; then + echo "Cannot find the file $PGLIB/${langname}__DLSUFFIX__" + echo "This shared object contains the call handler for $lancomp." + echo "By default, only PL/pgSQL is built and installed. Other" + echo "languages must be explicitly enabled at configure." + echo "" + echo "To install PL/Tcl make sure the option --with-tcl is" + echo "given to configure, then recompile and install." + exit 1 +fi + +# ---------- +# Combine psql with options given +# ---------- +if [ -z "$AUTHSYS" ]; then + AUTHOPT="" +else + AUTHOPT="-a $AUTHSYS" +fi + +if [ -z "$PGHOST" ]; then + PGHOSTOPT="" +else + PGHOSTOPT="-h $PGHOST" +fi + +if [ -z "$PGPORT" ]; then + PGPORTOPT="" +else + PGPORTOPT="-p $PGPORT" +fi + +MONITOR="psql -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c" + +# ---------- +# Make sure the language isn't already installed +# ---------- +res=`$MONITOR "select oid from pg_language where lanname = '$langname'" $dbname` +if [ $? -ne 0 ]; then + echo "Cannot install language" + exit 1 +fi +if [ ! -z "$res" ]; then + echo "The language '$langname' is already installed in database $dbname" + exit 1 +fi + +# ---------- +# Check that there is no function named as the call handler +# ---------- +res=`$MONITOR "select oid from pg_proc where proname = '$handler'" $dbname` +if [ ! -z "$res" ]; then + echo "The language $lancomp isn't created up to now but there" + echo "is already a function named '$handler' declared." + echo "Language installation aborted." + exit 1 +fi + +# ---------- +# Create the call handler and the language +# ---------- +$MONITOR "create function $handler () returns opaque as '$PGLIB/${langname}__DLSUFFIX__' language 'C'" $dbname +if [ $? -ne 0 ]; then + echo "Language installation failed" + exit 1 +fi +$MONITOR "create $trusted procedural language '$langname' handler $handler lancompiler '$lancomp'" $dbname +if [ $? -ne 0 ]; then + echo "Language installation failed" + exit 1 +fi + + +exit 0 + diff --git a/src/bin/destroylang/Makefile b/src/bin/destroylang/Makefile new file mode 100644 index 00000000000..bd8b6ce1fb5 --- /dev/null +++ b/src/bin/destroylang/Makefile @@ -0,0 +1,28 @@ +#------------------------------------------------------------------------- +# +# Makefile.inc-- +# Makefile for bin/destroylang +# +# Copyright (c) 1994, Regents of the University of California +# +# +# IDENTIFICATION +# $Header: /cvsroot/pgsql/src/bin/destroylang/Attic/Makefile,v 1.1 1999/05/20 16:50:02 wieck Exp $ +# +#------------------------------------------------------------------------- + +SRCDIR= ../.. +include ../../Makefile.global + +all: destroylang + +destroylang: destroylang.sh + cp destroylang.sh destroylang + +install: destroylang + $(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$< + +clean: + rm -f destroylang + +dep depend: diff --git a/src/bin/destroylang/destroylang.sh b/src/bin/destroylang/destroylang.sh new file mode 100644 index 00000000000..908877a4b76 --- /dev/null +++ b/src/bin/destroylang/destroylang.sh @@ -0,0 +1,139 @@ +#!/bin/sh +#------------------------------------------------------------------------- +# +# createlang.sh-- +# Remove a procedural language from a database +# +# Copyright (c) 1994, Regents of the University of California +# +# +# IDENTIFICATION +# $Header: /cvsroot/pgsql/src/bin/destroylang/Attic/destroylang.sh,v 1.1 1999/05/20 16:50:03 wieck Exp $ +# +#------------------------------------------------------------------------- + +CMDNAME=`basename $0` + +# ---------- +# Determine username +# ---------- +if [ -z "$USER" ]; then + if [ -z "$LOGNAME" ]; then + if [ -z "`whoami`" ]; then + echo "$CMDNAME: cannot determine user name" + exit 1 + fi + else + USER=$LOGNAME + export USER + fi +fi + +# ---------- +# Get options, language name and dbname +# ---------- +dbname=$USER +while [ -n "$1" ] +do + case $1 in + -a) AUTHSYS=$2; shift;; + -h) PGHOST=$2; shift;; + -p) PGPORT=$2; shift;; + *) langname=$1 + if [ -n "$2" ]; then + shift + dbname=$1 + fi;; + esac + shift; +done + +# ---------- +# If not given on the commandline, ask for the language +# ---------- +if [ -z "$langname" ]; then + echo -n "Language to remove from database $dbname: " + read langname +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";; + *) echo "$CMDNAME: unsupported language '$langname'" + echo " supported languages are plpgsql and pltcl" + exit 1;; +esac + +# ---------- +# Combine psql with options given +# ---------- +if [ -z "$AUTHSYS" ]; then + AUTHOPT="" +else + AUTHOPT="-a $AUTHSYS" +fi + +if [ -z "$PGHOST" ]; then + PGHOSTOPT="" +else + PGHOSTOPT="-h $PGHOST" +fi + +if [ -z "$PGPORT" ]; then + PGPORTOPT="" +else + PGPORTOPT="-p $PGPORT" +fi + +MONITOR="psql -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c" + +# ---------- +# Make sure the language is installed +# ---------- +res=`$MONITOR "select oid from pg_language where lanname = '$langname'" $dbname` +if [ $? -ne 0 ]; then + echo "Cannot remove language" + exit 1 +fi +if [ -z "$res" ]; then + echo "The language '$langname' isn't installed in database $dbname" + exit 1 +fi + + +# ---------- +# Check that there are no functions left defined in that language +# ---------- +res=`$MONITOR "select count(proname) from pg_proc P, pg_language L where P.prolang = L.oid and L.lanname = '$langname'" $dbname` +if [ $? -ne 0 ]; then + echo "Cannot remove language" + exit 1 +fi +if [ $res -ne 0 ]; then + echo "There are $res functions/trigger procedures actually declared" + echo "in language $lancomp." + echo "Language not removed." + exit 1 +fi + +# ---------- +# Drop the language and the call handler function +# ---------- +$MONITOR "drop procedural language '$langname'" $dbname +if [ $? -ne 0 ]; then + echo "Language removal failed" + exit 1 +fi +$MONITOR "drop function $handler()" $dbname +if [ $? -ne 0 ]; then + echo "Language removal failed" + exit 1 +fi + +exit 0 + diff --git a/src/bin/initdb/Makefile b/src/bin/initdb/Makefile index 1f92057c014..facc454d88f 100644 --- a/src/bin/initdb/Makefile +++ b/src/bin/initdb/Makefile @@ -7,7 +7,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/initdb/Makefile,v 1.12 1999/05/12 10:35:43 wieck Exp $ +# $Header: /cvsroot/pgsql/src/bin/initdb/Makefile,v 1.13 1999/05/20 16:50:05 wieck Exp $ # #------------------------------------------------------------------------- @@ -18,7 +18,6 @@ all: initdb initdb: initdb.sh sed -e 's/__MULTIBYTE__/$(MULTIBYTE)/' \ - -e 's/__DLSUFFIX__/$(DLSUFFIX)/' \ initdb.sh > initdb install: initdb diff --git a/src/bin/initdb/initdb.sh b/src/bin/initdb/initdb.sh index b8316e26939..139c967b05c 100644 --- a/src/bin/initdb/initdb.sh +++ b/src/bin/initdb/initdb.sh @@ -26,7 +26,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.59 1999/05/12 10:35:43 wieck Exp $ +# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.60 1999/05/20 16:50:06 wieck Exp $ # #------------------------------------------------------------------------- @@ -491,26 +491,6 @@ echo "CREATE RULE \"_RETpg_indexes\" AS ON SELECT TO pg_indexes DO INSTEAD \ AND I.oid = X.indexrelid;" | \ postgres $PGSQL_OPT template1 > /dev/null -if [ -f $PGLIB/plpgsql__DLSUFFIX__ ] ; then - echo "Installing PL/pgSQL as trusted procedural language" - echo "CREATE FUNCTION plpgsql_call_handler () RETURNS opaque \ - AS '$PGLIB/plpgsql__DLSUFFIX__' LANGUAGE 'C';" | \ - postgres $PGSQL_OPT template1 > /dev/null - echo "CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' \ - HANDLER plpgsql_call_handler LANCOMPILER 'PL/pgSQL';" | \ - postgres $PGSQL_OPT template1 > /dev/null -fi - -if [ -f $PGLIB/pltcl__DLSUFFIX__ ] ; then - echo "Installing PL/Tcl as trusted procedural language" - echo "CREATE FUNCTION pltcl_call_handler () RETURNS opaque \ - AS '$PGLIB/pltcl__DLSUFFIX__' LANGUAGE 'C';" | \ - postgres $PGSQL_OPT template1 > /dev/null - echo "CREATE TRUSTED PROCEDURAL LANGUAGE 'pltcl' \ - HANDLER pltcl_call_handler LANCOMPILER 'PL/Tcl';" | \ - postgres $PGSQL_OPT template1 > /dev/null -fi - echo "Loading pg_description" echo "copy pg_description from '$TEMPLATE_DESCR'" | \ postgres $PGSQL_OPT template1 > /dev/null diff --git a/src/test/regress/regress.sh b/src/test/regress/regress.sh index 04244d6829f..51dbf67fcca 100755 --- a/src/test/regress/regress.sh +++ b/src/test/regress/regress.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $Header: /cvsroot/pgsql/src/test/regress/Attic/regress.sh,v 1.27 1999/05/07 02:31:43 momjian Exp $ +# $Header: /cvsroot/pgsql/src/test/regress/Attic/regress.sh,v 1.28 1999/05/20 16:50:08 wieck Exp $ # if [ $# -eq 0 ] then @@ -63,6 +63,13 @@ if [ $? -ne 0 ]; then exit 1 fi +echo "=============== installing PL/pgSQL... =================" +createlang $HOST plpgsql regression +if [ $? -ne 0 ]; then + echo createlang failed + exit 1 +fi + echo "=============== running regression queries... =================" echo "" > regression.diffs for i in `cat sql/tests` $mbtests |