Re: make createlang match docs - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: make createlang match docs
Date
Msg-id 200201030608.g0368UP15445@candle.pha.pa.us
Whole thread Raw
In response to Re: make createlang match docs  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-patches
> I was going to add this to TODO:
>
>     Change 'createlang [langname] dbname' to 'createlang langname [dbname]'
>
> However, when I started to look at the createlang script, I saw:
>
>                 if [ "$list" != "t" ]
>                 then    langname="$1"
>                         if [ "$2" ]
>                         then
>                                 shift
>                                 dbname="$1"
>                         fi
>                 else    dbname="$1"
>                 fi
>
> which said that dbname was already behaving as optional, even though
> there was code to handle a missing langname.
>
> Rather than change the script to make langname optional, I have fixed
> the script to work the way everyone wants it to work, namely dbname is
> now optional.  I grabbed the dbname default code from createdb.

OK, turns out droplang has the same problem;  default are documented but
do not work.  Fixed to have dbname optional, just like createlang.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
Index: doc/src/sgml/ref/droplang.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/ref/droplang.sgml,v
retrieving revision 1.15
diff -c -r1.15 droplang.sgml
*** doc/src/sgml/ref/droplang.sgml    2001/12/08 03:24:36    1.15
--- doc/src/sgml/ref/droplang.sgml    2002/01/03 06:06:59
***************
*** 23,30 ****
    <cmdsynopsis>
     <command>droplang</command>
     <arg rep="repeat"><replaceable>connection-options</replaceable></arg>
!    <arg><replaceable>langname</replaceable></arg>
!    <arg choice="plain"><replaceable>dbname</replaceable></arg>
     <sbr>
     <command>droplang</command>
     <arg rep="repeat"><replaceable>connection-options</replaceable></arg>
--- 23,30 ----
    <cmdsynopsis>
     <command>droplang</command>
     <arg rep="repeat"><replaceable>connection-options</replaceable></arg>
!    <arg choice="plain"><replaceable>langname</replaceable></arg>
!    <arg><replaceable>dbname</replaceable></arg>
     <sbr>
     <command>droplang</command>
     <arg rep="repeat"><replaceable>connection-options</replaceable></arg>
***************
*** 45,53 ****
        <listitem>
         <para>
      Specifies the name of the backend programming language to be removed.
-     <application>droplang</application> will prompt for
-     <replaceable class="parameter">langname</replaceable>
-     if it is not specified on the command line.
         </para>
        </listitem>
       </varlistentry>
--- 45,50 ----
***************
*** 57,62 ****
--- 54,61 ----
        <listitem>
         <para>
      Specifies from which database the language should be removed.
+         The default is to create a database with the same name as the
+         current system user.
         </para>
        </listitem>
       </varlistentry>
Index: src/bin/scripts/droplang
===================================================================
RCS file: /cvsroot/pgsql/src/bin/scripts/droplang,v
retrieving revision 1.18
diff -c -r1.18 droplang
*** src/bin/scripts/droplang    2001/09/30 22:17:51    1.18
--- src/bin/scripts/droplang    2002/01/03 06:07:00
***************
*** 111,117 ****
          echo "$CMDNAME removes a procedural language from a database."
      echo
      echo "Usage:"
!         echo "  $CMDNAME [options] [langname [dbname]]"
          echo
      echo "Options:"
      echo "  -h, --host=HOSTNAME             Database server host"
--- 111,117 ----
          echo "$CMDNAME removes a procedural language from a database."
      echo
      echo "Usage:"
!         echo "  $CMDNAME [options] langname [dbname]"
          echo
      echo "Options:"
      echo "  -h, --host=HOSTNAME             Database server host"
***************
*** 121,134 ****
      echo "  -d, --dbname=DBNAME             Database to remove language from"
      echo "  -l, --list                      Show a list of currently installed languages"
          echo
-         echo "If 'langname' is not specified, you will be prompted interactively."
-         echo "A database name must be specified."
-         echo
      echo "Report bugs to <pgsql-bugs@postgresql.org>."
      exit 0
  fi


  if [ "$list" ]; then
      sqlcmd="SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\" FROM pg_language WHERE lanispl = TRUE"
      if [ "$showsql" = yes ]; then
--- 121,144 ----
      echo "  -d, --dbname=DBNAME             Database to remove language from"
      echo "  -l, --list                      Show a list of currently installed languages"
          echo
      echo "Report bugs to <pgsql-bugs@postgresql.org>."
      exit 0
  fi


+ if [ -z "$dbname" ]; then
+         if [ "$PGUSER" ]; then
+                 dbname="$PGUSER"
+         else
+                 dbname=`${PATHNAME}pg_id -u -n`
+         fi
+         [ "$?" -ne 0 ] && exit 1
+ fi
+
+
+ # ----------
+ # List option, doesn't need langname
+ # ----------
  if [ "$list" ]; then
      sqlcmd="SELECT lanname as \"Name\", lanpltrusted as \"Trusted?\" FROM pg_language WHERE lanispl = TRUE"
      if [ "$showsql" = yes ]; then
***************
*** 140,160 ****


  # ----------
! # Check that we have a database
  # ----------
! if [ -z "$dbname" ]; then
!     echo "$CMDNAME: missing required argument database name" 1>&2
          echo "Try '$CMDNAME --help' for help." 1>&2
      exit 1
- fi
-
-
- # ----------
- # If not given on the commandline, ask for the language
- # ----------
- if [ -z "$langname" ]; then
-     $ECHO_N "Language to remove from database $dbname: "$ECHO_C
-     read langname
  fi

  PSQL="${PATHNAME}psql -A -t -q $PSQLOPT -d $dbname -c"
--- 150,161 ----


  # ----------
! # We can't go any farther without a langname
  # ----------
! if [ -z "$langname" ]; then
!     echo "$CMDNAME: missing required argument language name" 1>&2
          echo "Try '$CMDNAME --help' for help." 1>&2
      exit 1
  fi

  PSQL="${PATHNAME}psql -A -t -q $PSQLOPT -d $dbname -c"

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: make createlang match docs
Next
From: Bruce Momjian
Date:
Subject: Re: Patch for ODBC driver (look for odbc.ini in more than