Re: [HACKERS] psql commandline conninfo - Mailing list pgsql-patches

From Tom Lane
Subject Re: [HACKERS] psql commandline conninfo
Date
Msg-id 24948.1166244904@sss.pgh.pa.us
Whole thread Raw
In response to Re: [HACKERS] psql commandline conninfo  ("Andrew Dunstan" <andrew@dunslane.net>)
Responses Re: [HACKERS] psql commandline conninfo  ("Andrew Dunstan" <andrew@dunslane.net>)
List pgsql-patches
"Andrew Dunstan" <andrew@dunslane.net> writes:
> Here's the patch for what I think is the consensus position. If there's no
> objection I will apply this and document it.

Please do something for the comment for the connectOptions1 call.
As you've coded it, that is doing two completely different things
and the comment is almost completely unhelpful at explaining this
complexity.  Oh, and casting away const gets no points for style.

I think you could do worse than to split it into two independent code
paths:

    /*
     * If the dbName parameter contains '=', assume it's a conninfo
     * string.
     */
    if (dbName && strchr(dbName,'='))
    {
        if (!connectOptions1(conn, dbName))
            return conn;
    }
    else
    {
        /*
         * Old-style path: first, parse an empty conninfo string in
         * order to set up the same defaults that PQconnectdb() would use.
         */
        if (!connectOptions1(conn, ""))
            return conn;

        /* Insert dbName parameter value into struct */
        if (dbName && dbName[0] != '\0')
        {
            if (conn->dbName)
                free(conn->dbName);
            conn->dbName = strdup(dbName);
        }
    }

    /*
     * Insert remaining parameters into struct, overriding defaults
     * (as well as any conflicting data from dbName taken as a conninfo).
     */

(This works because there's no reason the dbName parameter can't be
moved up to process before the rest.)

            regards, tom lane

pgsql-patches by date:

Previous
From: "Andrew Dunstan"
Date:
Subject: Re: [HACKERS] psql commandline conninfo
Next
From: "Andrew Dunstan"
Date:
Subject: Re: [HACKERS] psql commandline conninfo