Skip to content

Commit 8714d9c

Browse files
committed
Fix assign_datestyle() so that it doesn't misleadingly complain about
'conflicting datestyle specifications' for input that's actually only redundant, such as SET DATESTYLE = MDY, MDY. Per recent gripe.
1 parent 56b01dc commit 8714d9c

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/backend/commands/variable.c

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.107 2005/06/05 01:48:34 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.108 2005/06/09 21:52:07 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -42,9 +42,9 @@ assign_datestyle(const char *value, bool doit, GucSource source)
4242
{
4343
int newDateStyle = DateStyle;
4444
int newDateOrder = DateOrder;
45+
bool have_style = false;
46+
bool have_order = false;
4547
bool ok = true;
46-
int scnt = 0,
47-
ocnt = 0;
4848
char *rawstring;
4949
char *result;
5050
List *elemlist;
@@ -74,44 +74,58 @@ assign_datestyle(const char *value, bool doit, GucSource source)
7474

7575
if (pg_strcasecmp(tok, "ISO") == 0)
7676
{
77+
if (have_style && newDateStyle != USE_ISO_DATES)
78+
ok = false; /* conflicting styles */
7779
newDateStyle = USE_ISO_DATES;
78-
scnt++;
80+
have_style = true;
7981
}
8082
else if (pg_strcasecmp(tok, "SQL") == 0)
8183
{
84+
if (have_style && newDateStyle != USE_SQL_DATES)
85+
ok = false; /* conflicting styles */
8286
newDateStyle = USE_SQL_DATES;
83-
scnt++;
87+
have_style = true;
8488
}
8589
else if (pg_strncasecmp(tok, "POSTGRES", 8) == 0)
8690
{
91+
if (have_style && newDateStyle != USE_POSTGRES_DATES)
92+
ok = false; /* conflicting styles */
8793
newDateStyle = USE_POSTGRES_DATES;
88-
scnt++;
94+
have_style = true;
8995
}
9096
else if (pg_strcasecmp(tok, "GERMAN") == 0)
9197
{
98+
if (have_style && newDateStyle != USE_GERMAN_DATES)
99+
ok = false; /* conflicting styles */
92100
newDateStyle = USE_GERMAN_DATES;
93-
scnt++;
101+
have_style = true;
94102
/* GERMAN also sets DMY, unless explicitly overridden */
95-
if (ocnt == 0)
103+
if (!have_order)
96104
newDateOrder = DATEORDER_DMY;
97105
}
98106
else if (pg_strcasecmp(tok, "YMD") == 0)
99107
{
108+
if (have_order && newDateOrder != DATEORDER_YMD)
109+
ok = false; /* conflicting orders */
100110
newDateOrder = DATEORDER_YMD;
101-
ocnt++;
111+
have_order = true;
102112
}
103113
else if (pg_strcasecmp(tok, "DMY") == 0 ||
104114
pg_strncasecmp(tok, "EURO", 4) == 0)
105115
{
116+
if (have_order && newDateOrder != DATEORDER_DMY)
117+
ok = false; /* conflicting orders */
106118
newDateOrder = DATEORDER_DMY;
107-
ocnt++;
119+
have_order = true;
108120
}
109121
else if (pg_strcasecmp(tok, "MDY") == 0 ||
110122
pg_strcasecmp(tok, "US") == 0 ||
111123
pg_strncasecmp(tok, "NONEURO", 7) == 0)
112124
{
125+
if (have_order && newDateOrder != DATEORDER_MDY)
126+
ok = false; /* conflicting orders */
113127
newDateOrder = DATEORDER_MDY;
114-
ocnt++;
128+
have_order = true;
115129
}
116130
else if (pg_strcasecmp(tok, "DEFAULT") == 0)
117131
{
@@ -128,9 +142,9 @@ assign_datestyle(const char *value, bool doit, GucSource source)
128142

129143
subval = assign_datestyle(GetConfigOptionResetString("datestyle"),
130144
true, source);
131-
if (scnt == 0)
145+
if (!have_style)
132146
newDateStyle = DateStyle;
133-
if (ocnt == 0)
147+
if (!have_order)
134148
newDateOrder = DateOrder;
135149
DateStyle = saveDateStyle;
136150
DateOrder = saveDateOrder;
@@ -155,9 +169,6 @@ assign_datestyle(const char *value, bool doit, GucSource source)
155169
}
156170
}
157171

158-
if (scnt > 1 || ocnt > 1)
159-
ok = false;
160-
161172
pfree(rawstring);
162173
list_free(elemlist);
163174

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