Re: [HACKERS] psql commandline conninfo - Mailing list pgsql-patches
From | Andrew Dunstan |
---|---|
Subject | Re: [HACKERS] psql commandline conninfo |
Date | |
Msg-id | 4586C8BF.5070500@dunslane.net Whole thread Raw |
List | pgsql-patches |
Andrew Dunstan wrote: > > > Tom Lane wrote: >> Bruce Momjian <bruce@momjian.us> writes: >> >>> OK, good to know. Does the patch need documentation too? >>> >> >> Certainly. >> > > > That's why I haven't committed it yet. I intend to put info in the > psql manual as well as in the libpq reference. >> >>> Are we >>> deprecating the psql options now duplicated by the new functionality, >>> like host/port/username/password? >>> >> >> I'd vote not. This is just another way to do it. >> >> >> > > I entirely agree. It lets you do some nice things that aren't obvious > now, like: > > psql 'service=foo sslmode=require' > > Patch (Tom's code, my docs) attached. cheers andrew Index: doc/src/sgml/libpq.sgml =================================================================== RCS file: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v retrieving revision 1.220 diff -c -r1.220 libpq.sgml *** doc/src/sgml/libpq.sgml 10 Nov 2006 22:15:26 -0000 1.220 --- doc/src/sgml/libpq.sgml 18 Dec 2006 16:52:39 -0000 *************** *** 324,336 **** const char *login, const char *pwd); </synopsis> ! </para> ! <para> ! This is the predecessor of <function>PQconnectdb</function> with a fixed ! set of parameters. It has the same functionality except that the ! missing parameters will always take on default values. Write <symbol>NULL</symbol> or an ! empty string for any one of the fixed parameters that is to be defaulted. </para> </listitem> </varlistentry> --- 324,342 ---- const char *login, const char *pwd); </synopsis> ! </para> ! <para> ! This is the predecessor of <function>PQconnectdb</function> with a fixed ! set of parameters. It has the same functionality except that the ! missing parameters will always take on default values. Write <symbol>NULL</symbol> or an ! empty string for any one of the fixed parameters that is to be defaulted. ! </para> ! <para> ! If the <parameter>dbName</parameter> contains an <symbol>=</symbol> sign, it ! is taken as a <parameter>conninfo</parameter> string in exactly the same way as ! if it had been passed to <function>PQconnectdb</function>, and the remaining ! parameters are then applied as above. </para> </listitem> </varlistentry> Index: doc/src/sgml/ref/psql-ref.sgml =================================================================== RCS file: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v retrieving revision 1.175 diff -c -r1.175 psql-ref.sgml *** doc/src/sgml/ref/psql-ref.sgml 21 Nov 2006 17:01:58 -0000 1.175 --- doc/src/sgml/ref/psql-ref.sgml 18 Dec 2006 16:52:40 -0000 *************** *** 112,117 **** --- 112,121 ---- class="parameter">dbname</replaceable> as the first non-option argument on the command line. </para> + <para> + If this parameter contains an <symbol>=</symbol> sign, it it treated as a + <parameter>conninfo</parameter> string. See <xref linkend="libpq-connect"> for more information. + </para> </listitem> </varlistentry> *************** *** 554,559 **** --- 558,575 ---- passwords. See <xref linkend="libpq-pgpass"> for more information. </para> + <para> + An alternative way to specify connection parameters is in a + <parameter>conninfo</parameter> string, which is used instead of a + database name. This mechanism give you very wide control over the + connection. For example, + <programlisting> + $ <userinput>psql "service=myservice sslmode=require"</userinput> + </programlisting> + See <xref linkend="libpq-connect"> for more information on all the + available connection options. + </para> + <para> If the connection could not be made for any reason (e.g., insufficient privileges, server is not running on the targeted host, etc.), Index: src/interfaces/libpq/fe-connect.c =================================================================== RCS file: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v retrieving revision 1.339 diff -c -r1.339 fe-connect.c *** src/interfaces/libpq/fe-connect.c 21 Nov 2006 16:28:00 -0000 1.339 --- src/interfaces/libpq/fe-connect.c 18 Dec 2006 16:52:43 -0000 *************** *** 574,589 **** conn = makeEmptyPGconn(); if (conn == NULL) return NULL; ! ! /* ! * Parse an empty conninfo string in order to set up the same defaults ! * that PQconnectdb() would use. ! */ ! if (!connectOptions1(conn, "")) ! return conn; ! ! /* ! * Absorb specified options into conn structure, overriding defaults */ if (pghost && pghost[0] != '\0') { --- 574,609 ---- conn = makeEmptyPGconn(); if (conn == NULL) return NULL; ! /* ! * 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). */ if (pghost && pghost[0] != '\0') { *************** *** 613,625 **** conn->pgtty = strdup(pgtty); } - if (dbName && dbName[0] != '\0') - { - if (conn->dbName) - free(conn->dbName); - conn->dbName = strdup(dbName); - } - if (login && login[0] != '\0') { if (conn->pguser) --- 633,638 ----
pgsql-patches by date: