Re: [bug fix] connection service file doesn't take effect with ECPG apps - Mailing list pgsql-hackers

From MauMau
Subject Re: [bug fix] connection service file doesn't take effect with ECPG apps
Date
Msg-id 908D5415F893439C87E7F1A44C84C716@maumau
Whole thread Raw
In response to Re: [bug fix] connection service file doesn't take effect with ECPG apps  (Michael Meskes <meskes@postgresql.org>)
Responses Re: [bug fix] connection service file doesn't take effect with ECPG apps
List pgsql-hackers
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

Attachment

pgsql-hackers by date:

Previous
From: David Rowley
Date:
Subject: [PATCH] work_mem calculation possible overflow
Next
From: Alexander Korotkov
Date:
Subject: Re: PoC: Partial sort