Re: [HACKERS] PSQL man page patch - Mailing list pgsql-hackers

From Peter T Mount
Subject Re: [HACKERS] PSQL man page patch
Date
Msg-id Pine.LNX.3.95.980117140924.1911B-100000@maidast
Whole thread Raw
In response to Re: [HACKERS] PSQL man page patch  ("Thomas G. Lockhart" <lockhart@alumni.caltech.edu>)
List pgsql-hackers
On Fri, 16 Jan 1998, Thomas G. Lockhart wrote:

> I'm in favor of it also, perhaps as a libpq function call which is used in
> psql. That way, other apps or frontends can choose to use it or not.
>
> Would much prefer leaving it out as a _mandatory_ part of connection
> initialization, since there will be side-effects for embedded apps. Combined
> with PGDATESTYLE and PGTZ there will be pretty good control over the frontend
> environment.

I agree entirely with you Tom, as this could cause problems if it was a
_mandatory_ part of connecting.

Infact, it would (with the JDBC driver) prevent it from being used with
Applets (accessing local files violate applet security).

It's best to make this an optional call for libpq.

For jdbc use, the following is the best way to do this (rather than
including it in the driver):

public void readRCfile(Statement stat,File file) throws SQLException
{
  try {
    FileInputStream fis = new FileInputStream(file);
    BufferedReader r = new BufferedReader(new Reader(fis));

    while((String line=r.readLine())!=null) {
      if(!line.startsWith("#"))
    stat.executeUpdate(line);
    }
    r.close();
  } catch(IOException ioe)
    throw new SQLException(ioe.toString());
}

public void initConnection(Connection con) throws SQLException
{
  Statement stat = con.createStatement();

  // Process ~/.psqlrc
  try {
    String dir=System.getProperty("user.home");
    if(dir!=null)
      readRCfile(stat,new File(dir,".psqlrc"));
  } catch(SQLException se) {
    // Ignore if it doesn't exist.
  }

  // Now /etc/psqlrc
  readRCfile(stat,new File("/etc/psqlrc"));

  stat.close();
}

I'll add this to the examples later.

--
Peter T Mount  petermount@earthling.net or pmount@maidast.demon.co.uk
Main Homepage: http://www.demon.co.uk/finder
Work Homepage: http://www.maidstone.gov.uk Work EMail: peter@maidstone.gov.uk


pgsql-hackers by date:

Previous
From: teunis
Date:
Subject: Re: [HACKERS] Re: [QUESTIONS] Arrays (inserting and removing)
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] subselects coding started