pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedECPG & 'exec sql connect to' question
3+ messages / 3 participants
[nested] [flat]
* ECPG & 'exec sql connect to' question
@ 1999-03-04 16:01 Pavel PaJaSoft Janousek <janousek@fonet.cz>
1999-03-04 19:17 ` Re: [INTERFACES] ECPG & 'exec sql connect to' question James Thompson <jamest@math.ksu.edu>
1999-03-05 14:49 ` Re: [INTERFACES] ECPG & 'exec sql connect to' question Michael Meskes <michael_meskes@topmail.de>
0 siblings, 2 replies; 3+ messages in thread
From: Pavel PaJaSoft Janousek @ 1999-03-04 16:01 UTC (permalink / raw)
To: pgsql-interfaces
Hi all,
I've one big problem. Last month I saw in this mailing-list one example, where was this line:
'exec sql connect to unix:postgresql://localhost:5432/mm; '
I thought, that this example is for ECPG, but....
I'm using PostgreSQL 6.4.2 - ECPG is from this release (without other patches, which are distributed in this mailing-list). I try compile my program, but I got always the same error: <source>:<line>: parse error at or near 'postgresql'.
So, I write small example:
All described this I make by psql monitor... I create database 'test'. Database 'test' is created by unix user 'paja' ('paja' is postgres user too). I create new postgres user 'petr' with password 'petr'. As 'paja', I connect to database 'test' and create table 'pom' with some cols, then execute this: 'grant insert on pom to petr;'. All is OK, but now, I want connect to database 'test' by user 'petr'... of course, I cant' use simple command:
'exec sql connect 'test';', because I want have only rights as user 'petr' (only inserting rows).
My problem is, that I don't know, how I can connect to database (on local system or remote...) with specifiing user and his password.
I know, that I can use libpq directly, but I want do this by ECPG, not by using the PostgreSQL C library.
Thank you for any ideas....
Pavel PaJaSoft Janousek
FoNet, spol. s r.o.
PS: A wrote this question in november 1998, but I didn't got some answer. Of course, I specify my question rather diferent...
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [INTERFACES] ECPG & 'exec sql connect to' question
1999-03-04 16:01 ECPG & 'exec sql connect to' question Pavel PaJaSoft Janousek <janousek@fonet.cz>
@ 1999-03-04 19:17 ` James Thompson <jamest@math.ksu.edu>
1 sibling, 0 replies; 3+ messages in thread
From: James Thompson @ 1999-03-04 19:17 UTC (permalink / raw)
To: Pavel PaJaSoft Janousek <janousek@fonet.cz>; +Cc: pgsql-interfaces
On Thu, 4 Mar 1999, Pavel PaJaSoft Janousek wrote:
> Hi all,
>
> I've one big problem. Last month I saw in this mailing-list one example, where was this line:
>
> 'exec sql connect to unix:postgresql://localhost:5432/mm; '
>
Here is a copy of the subroutine I use. I'm pretty sure it worked fine
with 6.4.2 and the ecpg that came with it. The obstrdup() is a simple
string copy function, obstrappend appends the second string arg to the
first. You should be able to get rid of them easily, if not I'll send you
those as well. Hope this helps.
int
db_connect(char *username, char *password, char *host)
{
exec sql begin declare section;
char *xpassword;
char *xusername;
char *xhost;
exec sql end declare section;
assert (username != NULL);
assert (password != NULL);
xpassword = obstrdup(password);
xusername = obstrdup(username);
if (host)
{
xhost = obstrdup("tcp:postgresql://");
xhost = obstrappend(xhost,host);
xhost = obstrappend(xhost,"/obe");
} else {
xhost = obstrdup("tcp:postgresql://127.0.0.1/obe");
}
/* <tcp|unix>:postgresql://server[:port][/dbname][?options] */
EXEC SQL CONNECT TO :xhost USER :xusername IDENTIFIED BY :xpassword;
return 0;
}
->->->->->->->->->->->->->->->->->->---<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<
James Thompson 138 Cardwell Hall Manhattan, Ks 66506 785-532-0561
Kansas State University Department of Mathematics
->->->->->->->->->->->->->->->->->->---<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [INTERFACES] ECPG & 'exec sql connect to' question
1999-03-04 16:01 ECPG & 'exec sql connect to' question Pavel PaJaSoft Janousek <janousek@fonet.cz>
@ 1999-03-05 14:49 ` Michael Meskes <michael_meskes@topmail.de>
1 sibling, 0 replies; 3+ messages in thread
From: Michael Meskes @ 1999-03-05 14:49 UTC (permalink / raw)
To: pgsql-interfaces
On Thu, Mar 04, 1999 at 05:01:05PM +0100, Pavel PaJaSoft Janousek wrote:
> 'exec sql connect to unix:postgresql://localhost:5432/mm; '
>
> I thought, that this example is for ECPG, but....
It is. However, the same dbname syntax applies to all programs using libpq.
> All described this I make by psql monitor... I create database 'test'. Database 'test' is created by unix user 'paja' ('paja' is postgres user too). I create new postgres user 'petr' with password 'petr'. As 'paja', I connect to database 'test' and create table 'pom' with some cols, then execute this: 'grant insert on pom to petr;'. All is OK, but now, I want connect to database 'test' by user 'petr'... of course, I cant' use simple command:
> 'exec sql connect 'test';', because I want have only rights as user 'petr' (only inserting rows).
> My problem is, that I don't know, how I can connect to database (on
> local system or remote...) with specifiing user and his password. I
> know, that I can use libpq directly, but I want do this by ECPG, not
> by using the PostgreSQL C library.
the syntax is 'exec sql <dbname> user <username> identified by <password>'
> PS: A wrote this question in november 1998, but I didn't got some answer.
> Of course, I specify my question rather diferent...
Seems I missed it. Sorry.
Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael.Meskes@gmx.net | Use PostgreSQL!
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~1999-03-05 14:49 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-03-04 16:01 ECPG & 'exec sql connect to' question Pavel PaJaSoft Janousek <janousek@fonet.cz>
1999-03-04 19:17 ` James Thompson <jamest@math.ksu.edu>
1999-03-05 14:49 ` Michael Meskes <michael_meskes@topmail.de>
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