Обсуждение: Re: [INTERFACES] Win32 interface

Поиск
Список
Период
Сортировка

Re: [INTERFACES] Win32 interface

От
"Ken J. Wright"
Дата:
At 14:02 09/02/1999 -0700, David Giffin wrote:
>
>I'm trying to use the postgresql win32 interface to connect ot a UNIX
>host. I'm using PQconnectDB() to get the connection. Each time I try to
>connect it says unknown host name:
>
>connectDB() --  unknown hostname: mobile
>
>reguardless of specifying the ip address or the complete host name. Any
>ideas??

are you using the proper parameter string? 
PQconnectDB('host=hostname dbname=databasename user=username')

Otherwise maybe send code snippet to look at?

Ken



Re: [INTERFACES] Win32 interface

От
David Giffin
Дата:

Yep I'm using the PQconnectDB("host=blah user=blah dbname=blah");

I noticed that psql.c uses the PQsetdbLogin maybe I should switch to that
function if this one is broken? Would have to parse a little extra but..

Here is the snippet... my char *dbname comes in the form of:host=hostname;dbname=database;port=portnum


int
pg_login(struct dbi *dbi, char *dbname, char *user, char *pass)
{char *connect;char *source;char *dest;char *src;int mem;int sourcelen;mem    = strlen(dbname);source = malloc(mem +
10);if(user && pass) {    mem += strlen(user) + strlen(pass);} else if (user) {    mem += strlen(user);}src =
dbname;dest= source;  while (*src) {    if (*src != ';') {        *dest++ = *src++;        continue;            }
*dest++= ' ';    src++;}     *dest = '\0';     if (LOG_LEVEL >= 3) {    fprintf(stderr,"pg_login: source ->
%s\n",source);}sourcelen= strlen(source); if (user && pass) {    connect =
malloc(sourcelen+strlen(user)+strlen(pass)+13);   sprintf(connect,"%s user=%s pass=%s",source, user, pass);} else if
(user){    connect = malloc(sourcelen+strlen(user) + 7);    sprintf(connect,"%s user=%s",source, user);} else {connect
=malloc(sourcelen + 1);sprintf(connect,"%s",source);    }     if (LOG_LEVEL >= 2) {    fprintf(stderr,"pg_login:
%s\n",connect);}dbi->conn= PQconnectdb(connect);
 
<SNIP>


On Thu, 2 Sep 1999, Ken J. Wright wrote:

> At 14:02 09/02/1999 -0700, David Giffin wrote:
> >
> >I'm trying to use the postgresql win32 interface to connect ot a UNIX
> >host. I'm using PQconnectDB() to get the connection. Each time I try to
> >connect it says unknown host name:
> >
> >connectDB() --  unknown hostname: mobile
> >
> >reguardless of specifying the ip address or the complete host name. Any
> >ideas??
> 
> are you using the proper parameter string? 
> PQconnectDB('host=hostname dbname=databasename user=username')
> 
> Otherwise maybe send code snippet to look at?
> 
> Ken
> 



Re: [INTERFACES] Win32 interface

От
Tom Lane
Дата:
David Giffin <david@agent911.com> writes:
> Yep I'm using the PQconnectDB("host=blah user=blah dbname=blah");
> I noticed that psql.c uses the PQsetdbLogin maybe I should switch to that
> function if this one is broken? Would have to parse a little extra but..
>>>> 
>>>> connectDB() --  unknown hostname: mobile

Assuming that "mobile" is the hostname you gave it, then parsing the
connectinfo string is not the problem.

The error message is coming out because gethostbyname() is failing ---
cf. connectDB() in interfaces/libpq/fe-connect.c.  (Or, perchance,
it is succeeding but delivering a non-INET address?  Seems unlikely
but if your LAN runs on non-TCP protocols then that's possible.)

My guess is that there is something broken with DNS name resolution
on your setup.  Hard to tell what from this much info.  You might
try making a one-liner program that just calls gethostbyname, and
work on debugging that simpler situation.
        regards, tom lane


Re: [INTERFACES] Win32 interface

От
David Giffin
Дата:
I figured out what was happening... Or at least what seem to happen. When
I linked in lipq.lib it would return unknown hostname. I switched it to
the libpqdll.lib and it worked fine.

I thought that libpq.lib would statically complie postgres into the .exe
but it didn't seem to work.

David

On Fri, 3 Sep 1999, Tom Lane wrote:

> David Giffin <david@agent911.com> writes:
> > Yep I'm using the PQconnectDB("host=blah user=blah dbname=blah");
> > I noticed that psql.c uses the PQsetdbLogin maybe I should switch to that
> > function if this one is broken? Would have to parse a little extra but..
> >>>> 
> >>>> connectDB() --  unknown hostname: mobile
> 
> Assuming that "mobile" is the hostname you gave it, then parsing the
> connectinfo string is not the problem.
> 
> The error message is coming out because gethostbyname() is failing ---
> cf. connectDB() in interfaces/libpq/fe-connect.c.  (Or, perchance,
> it is succeeding but delivering a non-INET address?  Seems unlikely
> but if your LAN runs on non-TCP protocols then that's possible.)
> 
> My guess is that there is something broken with DNS name resolution
> on your setup.  Hard to tell what from this much info.  You might
> try making a one-liner program that just calls gethostbyname, and
> work on debugging that simpler situation.
> 
>             regards, tom lane
>