Re: [INTERFACES] libpq & user

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: rknop(at)mh1(dot)lbl(dot)gov
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [INTERFACES] libpq & user
Date: 1998-07-15 09:40:36
Message-ID: l03110704b1d220f2ec4a@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

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

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Herouth Maoz 1998-07-15 10:04:26 Re: [INTERFACES][HACKERS] atttypmod now 32 bits, interface change
Previous Message Ewan Mellor 1998-07-15 09:19:16 Non-blocking queries using libpq