Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] PSQL man page patch

From: Peter T Mount <psqlhack(at)maidast(dot)demon(dot)co(dot)uk>
To: "Thomas G(dot) Lockhart" <lockhart(at)alumni(dot)caltech(dot)edu>
Cc: martin(at)biochemistry(dot)ucl(dot)ac(dot)uk, hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] PSQL man page patch
Date: 1998-01-17 14:26:31
Message-ID: Pine.LNX.3.95.980117140924.1911B-100000@maidast (view raw or flat)
Thread:
Lists: 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(at)earthling(dot)net or pmount(at)maidast(dot)demon(dot)co(dot)uk
Main Homepage: http://www.demon.co.uk/finder
Work Homepage: http://www.maidstone.gov.uk Work EMail: peter(at)maidstone(dot)gov(dot)uk


In response to

Responses

pgsql-hackers by date

Next:From: Bruce MomjianDate: 1998-01-17 16:00:25
Subject: Re: [HACKERS] subselects coding started
Previous:From: teunisDate: 1998-01-17 06:56:27
Subject: Re: [HACKERS] Re: [QUESTIONS] Arrays (inserting and removing)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group