From: "Michael Meskes" <meskes@postgresql.org>
> On Tue, Dec 17, 2013 at 09:26:49PM +0900, MauMau wrote:
>> [Problem]
>> The ECPG app runs the statement:
>>
>> EXEC SQL CONNECT TO 'tcp:postgresql://?service=my_service';
>> ...
>> ECPGconnect() parses the URI and produces an empty host name. It
>> passes an empty string as the value for "host" connection parameter
>> to PQconnectdbParams().
>
> Interestingly enough it works flawlessly on my system. Any idea where the
> empoty host name comes from? Before accepting the patch I'd like to find
> out
> why you got an empty host variable and I don't.
You can confirm it by adding the following code fragment to
ecpglib/connect.c. The attached file contains this.
if (host)
printf("host=%s\n", host);
else
printf("host=NULL\n");
Build and run the attached sample program like this (this is an example on
Windows, but the result should be the same on Linux):
ecpg connect.pgc
cl /nologo /MD /I<pg_inst_dir>\include connect.c /link
/libpath:<pg_inst_dir>\lib libecpg.lib
connect.exe
The added code in ecpglib/connect.c displays "host=", which shows that an
empty host is passed to PQconnectdbParams().
Of course, on Linux, you can use gdb to run the sample program, set a
breakpoint at PQconnectDbParams(), and display the keywords/values arrays of
the argument.
An empty string is set to the host local variable at line 430 in
ecpglib/connect.c (this line number is that of PostgreSQL 9.4). That is the
else block shown below:
if (strncmp(dbname, "unix:", 5) == 0)
{
...
}
else
{
host = ecpg_strdup(dbname + offset, lineno);
connect_params++;
}
Regards
MauMau