pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: rknop@mh1.lbl.gov
Cc: pgsql-interfaces@postgresql.org
Subject: Re: [INTERFACES] libpq & user
Date: Wed, 15 Jul 1998 12:40:36 +0300
Message-ID: <l03110704b1d220f2ec4a@[147.233.159.109]> (raw)
In-Reply-To: <Pine.SOL.3.95.980714135850.7053F-100000@panisse.lbl.gov>

At 0:02 +0300 on 15/7/98, Robert Knop wrote:


> I'm trying to use libpq to read a Postgres database from C.  I use the
> following command to connect to the database:
>
>   PGconn *deep;
>   deep=PQsetdb("dara",NULL,"user=deep",NULL,"deep");

I didn't exactly get it from your problem description, but I take it that
putting the username in the options field doesn't work.

Well, two alternatives for solution:

In the psql source code, they set the user by setting the PGUSER
environment variable. The source of the PQsetdb function states that the
following environment variables are accepted (although this is not
documented - at least not in my old 6.2.1 version):

PGHOST, PGPORT, PGTTY, PGOPTIONS, PGUSER, PGPASSWORD, PGDATABASE

So you may set these variables from within your program or from the shell
script that calls it.

Another option: the psql source, when needing a password, uses the
undocumented function:

PQconnectdb( connection_string );

The connection string is a C character string containing pairs of names and
values. For example: "host=dara user=deep password=ocean dbname=deep".

The allowed parameters are:
host, port, tty, options, user, password, authtype, dbname

Which to use? Depends on which undocumented feature you prefer... Or maybe
the gurus who actually wrote the code can give us a hint.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma





view thread (12+ messages)  latest in thread

Message-ID: <l03110704b1d220f2ec4a@[147.233.159.109]>
Permalink:  ../l03110704b1d220f2ec4a@%5B147.233.159.109%5D/
Also on:    postgresql.org/message-id/l03110704b1d220f2ec4a@[147.233.159.109]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-interfaces@postgresql.org
  Cc: herouth@oumail.openu.ac.il, rknop@mh1.lbl.gov
  Subject: Re: [INTERFACES] libpq & user
  In-Reply-To: <l03110704b1d220f2ec4a@[147.233.159.109]>
  References: <Pine.SOL.3.95.980714135850.7053F-100000@panisse.lbl.gov> <l03110704b1d220f2ec4a@[147.233.159.109]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox