Skip to content

Commit 4cd639b

Browse files
committed
Revert "psql: fix \connect with URIs and conninfo strings"
This reverts commit fcef161, about which both the buildfarm and my local machine are very unhappy.
1 parent 7dae3cf commit 4cd639b

File tree

8 files changed

+79
-175
lines changed

8 files changed

+79
-175
lines changed

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -796,31 +796,23 @@ testdb=>
796796
</varlistentry>
797797

798798
<varlistentry>
799-
<term><literal>\c</literal> or <literal>\connect</literal> <literal>[ <replaceable class="parameter">dbname</replaceable> [ <replaceable class="parameter">username</replaceable> ] [ <replaceable class="parameter">host</replaceable> ] [ <replaceable class="parameter">port</replaceable> ] ] | <replaceable class="parameter">conninfo</replaceable> </literal></term>
799+
<term><literal>\c</literal> or <literal>\connect</literal> <literal>[ <replaceable class="parameter">dbname</replaceable> [ <replaceable class="parameter">username</replaceable> ] [ <replaceable class="parameter">host</replaceable> ] [ <replaceable class="parameter">port</replaceable> ] ]</literal></term>
800800
<listitem>
801801
<para>
802802
Establishes a new connection to a <productname>PostgreSQL</>
803-
server. The connection parameters to use can be specified either
804-
using a positional syntax, or using <literal>conninfo</> connection
805-
strings as detailed in <xref linkend="libpq-connstring">.
803+
server. If the new connection is successfully made, the
804+
previous connection is closed. If any of <replaceable
805+
class="parameter">dbname</replaceable>, <replaceable
806+
class="parameter">username</replaceable>, <replaceable
807+
class="parameter">host</replaceable> or <replaceable
808+
class="parameter">port</replaceable> are omitted or specified
809+
as <literal>-</literal>, the value of that parameter from the
810+
previous connection is used. If there is no previous
811+
connection, the <application>libpq</application> default for
812+
the parameter's value is used.
806813
</para>
807814

808815
<para>
809-
When using positional parameters, if any of
810-
<replaceable class="parameter">dbname</replaceable>,
811-
<replaceable class="parameter">username</replaceable>,
812-
<replaceable class="parameter">host</replaceable> or
813-
<replaceable class="parameter">port</replaceable> are omitted or
814-
specified as <literal>-</literal>, the value of that parameter from
815-
the previous connection is used; if there is no previous connection,
816-
the <application>libpq</application> default for the parameter's value
817-
is used. When using <literal>conninfo</> strings, no values from the
818-
previous connection are used for the new connection.
819-
</para>
820-
821-
<para>
822-
If the new connection is successfully made, the previous
823-
connection is closed.
824816
If the connection attempt failed (wrong user name, access
825817
denied, etc.), the previous connection will only be kept if
826818
<application>psql</application> is in interactive mode. When
@@ -830,16 +822,6 @@ testdb=&gt;
830822
mechanism that scripts are not accidentally acting on the
831823
wrong database on the other hand.
832824
</para>
833-
834-
<para>
835-
Examples:
836-
</para>
837-
<programlisting>
838-
=&gt; \c mydb myuser host.dom 6432
839-
=&gt; \c service=foo
840-
=&gt; \c "host=localhost port=5432 dbname=mydb connect_timeout=10 sslmode=disable"
841-
=&gt; \c postgresql://tom@localhost/mydb?application_name=myapp
842-
</programlisting>
843825
</listitem>
844826
</varlistentry>
845827

src/bin/psql/command.c

Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <sys/stat.h> /* for stat() */
3232
#endif
3333

34-
#include "common/connstrings.h"
3534
#include "portability/instr_time.h"
3635

3736
#include "libpq-fe.h"
@@ -1609,8 +1608,6 @@ do_connect(char *dbname, char *user, char *host, char *port)
16091608
PGconn *o_conn = pset.db,
16101609
*n_conn;
16111610
char *password = NULL;
1612-
bool keep_password;
1613-
bool has_connection_string;
16141611

16151612
if (!o_conn && (!dbname || !user || !host || !port))
16161613
{
@@ -1624,35 +1621,15 @@ do_connect(char *dbname, char *user, char *host, char *port)
16241621
return false;
16251622
}
16261623

1627-
/* grab values from the old connection, unless supplied by caller */
1624+
if (!dbname)
1625+
dbname = PQdb(o_conn);
16281626
if (!user)
16291627
user = PQuser(o_conn);
16301628
if (!host)
16311629
host = PQhost(o_conn);
16321630
if (!port)
16331631
port = PQport(o_conn);
16341632

1635-
has_connection_string =
1636-
dbname ? libpq_connstring_is_recognized(dbname) : false;
1637-
1638-
/*
1639-
* Any change in the parameters read above makes us discard the password.
1640-
* We also discard it if we're to use a conninfo rather than the positional
1641-
* syntax.
1642-
*/
1643-
keep_password =
1644-
((strcmp(user, PQuser(o_conn)) == 0) &&
1645-
(!host || strcmp(host, PQhost(o_conn)) == 0) &&
1646-
(strcmp(port, PQport(o_conn)) == 0) &&
1647-
!has_connection_string);
1648-
1649-
/*
1650-
* Grab dbname from old connection unless supplied by caller. No password
1651-
* discard if this changes: passwords aren't (usually) database-specific.
1652-
*/
1653-
if (!dbname)
1654-
dbname = PQdb(o_conn);
1655-
16561633
/*
16571634
* If the user asked to be prompted for a password, ask for one now. If
16581635
* not, use the password from the old connection, provided the username
@@ -1667,53 +1644,42 @@ do_connect(char *dbname, char *user, char *host, char *port)
16671644
{
16681645
password = prompt_for_password(user);
16691646
}
1670-
else if (o_conn && keep_password)
1647+
else if (o_conn && user && strcmp(PQuser(o_conn), user) == 0)
16711648
{
1672-
password = PQpass(o_conn);
1673-
if (password && *password)
1674-
password = pg_strdup(password);
1675-
else
1676-
password = NULL;
1649+
password = pg_strdup(PQpass(o_conn));
16771650
}
16781651

16791652
while (true)
16801653
{
16811654
#define PARAMS_ARRAY_SIZE 8
16821655
const char **keywords = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
16831656
const char **values = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
1684-
int paramnum = 0;
1685-
1686-
keywords[0] = "dbname";
1687-
values[0] = dbname;
1688-
1689-
if (!has_connection_string)
1690-
{
1691-
keywords[++paramnum] = "host";
1692-
values[paramnum] = host;
1693-
keywords[++paramnum] = "port";
1694-
values[paramnum] = port;
1695-
keywords[++paramnum] = "user";
1696-
values[paramnum] = user;
1697-
}
1698-
keywords[++paramnum] = "password";
1699-
values[paramnum] = password;
1700-
keywords[++paramnum] = "fallback_application_name";
1701-
values[paramnum] = pset.progname;
1702-
keywords[++paramnum] = "client_encoding";
1703-
values[paramnum] = (pset.notty || getenv("PGCLIENTENCODING")) ? NULL : "auto";
17041657

1705-
/* add array terminator */
1706-
keywords[++paramnum] = NULL;
1707-
values[paramnum] = NULL;
1658+
keywords[0] = "host";
1659+
values[0] = host;
1660+
keywords[1] = "port";
1661+
values[1] = port;
1662+
keywords[2] = "user";
1663+
values[2] = user;
1664+
keywords[3] = "password";
1665+
values[3] = password;
1666+
keywords[4] = "dbname";
1667+
values[4] = dbname;
1668+
keywords[5] = "fallback_application_name";
1669+
values[5] = pset.progname;
1670+
keywords[6] = "client_encoding";
1671+
values[6] = (pset.notty || getenv("PGCLIENTENCODING")) ? NULL : "auto";
1672+
keywords[7] = NULL;
1673+
values[7] = NULL;
17081674

17091675
n_conn = PQconnectdbParams(keywords, values, true);
17101676

1711-
pg_free(keywords);
1712-
pg_free(values);
1677+
free(keywords);
1678+
free(values);
17131679

17141680
/* We can immediately discard the password -- no longer needed */
17151681
if (password)
1716-
pg_free(password);
1682+
free(password);
17171683

17181684
if (PQstatus(n_conn) == CONNECTION_OK)
17191685
break;

src/bin/psql/help.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ slashUsage(unsigned short int pager)
260260

261261
fprintf(output, _("Connection\n"));
262262
if (currdb)
263-
fprintf(output, _(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n"
263+
fprintf(output, _(" \\c[onnect] [DBNAME|- USER|- HOST|- PORT|-]\n"
264264
" connect to new database (currently \"%s\")\n"),
265265
currdb);
266266
else
267-
fprintf(output, _(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n"
267+
fprintf(output, _(" \\c[onnect] [DBNAME|- USER|- HOST|- PORT|-]\n"
268268
" connect to new database (currently no connection)\n"));
269269
fprintf(output, _(" \\encoding [ENCODING] show or set client encoding\n"));
270270
fprintf(output, _(" \\password [USERNAME] securely change the password for a user\n"));

src/bin/psql/tab-complete.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#include "libpq-fe.h"
5353
#include "pqexpbuffer.h"
5454
#include "common.h"
55-
#include "common/connstrings.h"
5655
#include "settings.h"
5756
#include "stringutils.h"
5857

@@ -3707,18 +3706,10 @@ psql_completion(const char *text, int start, int end)
37073706

37083707
COMPLETE_WITH_LIST_CS(my_list);
37093708
}
3710-
37113709
else if (strcmp(prev_wd, "\\connect") == 0 || strcmp(prev_wd, "\\c") == 0)
3712-
{
3713-
if (!libpq_connstring_is_recognized(text))
3714-
COMPLETE_WITH_QUERY(Query_for_list_of_databases);
3715-
/* TODO: URI/service completion. Nothing for now */
3716-
}
3710+
COMPLETE_WITH_QUERY(Query_for_list_of_databases);
37173711
else if (strcmp(prev2_wd, "\\connect") == 0 || strcmp(prev2_wd, "\\c") == 0)
3718-
{
3719-
if (!libpq_connstring_is_recognized(prev_wd))
3720-
COMPLETE_WITH_QUERY(Query_for_list_of_roles);
3721-
}
3712+
COMPLETE_WITH_QUERY(Query_for_list_of_roles);
37223713

37233714
else if (strncmp(prev_wd, "\\da", strlen("\\da")) == 0)
37243715
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_aggregates, NULL);

src/common/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ LIBS += $(PTHREAD_LIBS)
2626
OBJS_COMMON = exec.o pg_crc.o pg_lzcompress.o pgfnames.o psprintf.o relpath.o \
2727
rmtree.o string.o username.o wait_error.o
2828

29-
OBJS_FRONTEND = $(OBJS_COMMON) fe_memutils.o restricted_token.o connstrings.o
29+
OBJS_FRONTEND = $(OBJS_COMMON) fe_memutils.o restricted_token.o
3030

3131
OBJS_SRV = $(OBJS_COMMON:%.o=%_srv.o)
3232

src/common/connstrings.c

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/include/common/connstrings.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy