Received: from shaked.cc.openu.ac.il (shaked.cc.openu.ac.il [147.233.145.65]) by hub.org (8.8.8/8.7.5) with ESMTP id FAA27486 for ; Wed, 15 Jul 1998 05:40:54 -0400 (EDT) Received: from [147.233.159.109] (herouth@mac-herouth.pc.openu.ac.il [147.233.159.109]) by shaked.cc.openu.ac.il (8.8.5/8.8.5) with ESMTP id MAA13388; Wed, 15 Jul 1998 12:40:37 +0300 (IDT) X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Wed, 15 Jul 1998 12:40:36 +0300 To: rknop@mh1.lbl.gov From: Herouth Maoz Subject: Re: [INTERFACES] libpq & user Cc: pgsql-interfaces@postgresql.org 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