Skip to content

Commit 86a0714

Browse files
committed
Tweak psql's \connect command to not downcase unquoted database and user
names. This is a temporary measure to allow backwards compatibility with 7.2 and earlier pg_dump. 7.2.1 and later pg_dump will double-quote mixed case names in \connect. Once we feel that older dumps are not a problem anymore, we can revert this change and treat \connect arguments as normal SQL identifiers.
1 parent 7cfbbb2 commit 86a0714

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/bin/psql/command.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.65 2002/02/20 22:47:12 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.66 2002/02/25 21:37:42 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -54,11 +54,17 @@ static backslashResult exec_command(const char *cmd,
5454
const char **continue_parse,
5555
PQExpBuffer query_buf);
5656

57+
/* different ways for scan_option to handle parameter words */
5758
enum option_type
5859
{
59-
OT_NORMAL, OT_SQLID, OT_FILEPIPE
60+
OT_NORMAL, /* normal case */
61+
OT_SQLID, /* treat as SQL identifier */
62+
OT_SQLIDHACK, /* SQL identifier, but don't downcase */
63+
OT_FILEPIPE /* it's a file or pipe */
6064
};
61-
static char *scan_option(char **string, enum option_type type, char *quote, bool semicolon);
65+
66+
static char *scan_option(char **string, enum option_type type,
67+
char *quote, bool semicolon);
6268
static char *unescape(const unsigned char *source, size_t len);
6369

6470
static bool do_edit(const char *filename_arg, PQExpBuffer query_buf);
@@ -243,8 +249,17 @@ exec_command(const char *cmd,
243249
char opt1q,
244250
opt2q;
245251

246-
opt1 = scan_option(&string, OT_SQLID, &opt1q, true);
247-
opt2 = scan_option(&string, OT_SQLID, &opt2q, true);
252+
/*
253+
* Ideally we should treat the arguments as SQL identifiers. But for
254+
* backwards compatibility with 7.2 and older pg_dump files, we have
255+
* to take unquoted arguments verbatim (don't downcase them).
256+
* For now, double-quoted arguments may be stripped of double quotes
257+
* (as if SQL identifiers). By 7.4 or so, pg_dump files can be
258+
* expected to double-quote all mixed-case \connect arguments,
259+
* and then we can get rid of OT_SQLIDHACK.
260+
*/
261+
opt1 = scan_option(&string, OT_SQLIDHACK, &opt1q, true);
262+
opt2 = scan_option(&string, OT_SQLIDHACK, &opt2q, true);
248263

249264
if (opt2)
250265
/* gave username */
@@ -909,7 +924,7 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon)
909924
* then we strip out the double quotes
910925
*/
911926

912-
if (type == OT_SQLID)
927+
if (type == OT_SQLID || type == OT_SQLIDHACK)
913928
{
914929
unsigned int k,
915930
cc;
@@ -930,7 +945,6 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon)
930945
}
931946
return_val[cc] = '\0';
932947
}
933-
934948
else
935949
{
936950
strncpy(return_val, &options_string[pos], jj - pos + 1);

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