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
->->->->->->->->->->->->->->->->->->---<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<