Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] psql commandline conninfo

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] psql commandline conninfo
Date: 2006-12-16 04:55:04
Message-ID: 24948.1166244904@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
"Andrew Dunstan" <andrew(at)dunslane(dot)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

In response to

Responses

pgsql-hackers by date

Next:From: tomasDate: 2006-12-16 05:39:37
Subject: Re: Operator class group proposal
Previous:From: Andrew DunstanDate: 2006-12-16 03:59:58
Subject: Re: [HACKERS] psql commandline conninfo

pgsql-patches by date

Next:From: Andrew DunstanDate: 2006-12-16 13:11:09
Subject: Re: [HACKERS] psql commandline conninfo
Previous:From: Andrew DunstanDate: 2006-12-16 03:59:58
Subject: Re: [HACKERS] psql commandline conninfo

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group