9
9
*
10
10
*
11
11
* 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 $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -42,9 +42,9 @@ assign_datestyle(const char *value, bool doit, GucSource source)
42
42
{
43
43
int newDateStyle = DateStyle ;
44
44
int newDateOrder = DateOrder ;
45
+ bool have_style = false;
46
+ bool have_order = false;
45
47
bool ok = true;
46
- int scnt = 0 ,
47
- ocnt = 0 ;
48
48
char * rawstring ;
49
49
char * result ;
50
50
List * elemlist ;
@@ -74,44 +74,58 @@ assign_datestyle(const char *value, bool doit, GucSource source)
74
74
75
75
if (pg_strcasecmp (tok , "ISO" ) == 0 )
76
76
{
77
+ if (have_style && newDateStyle != USE_ISO_DATES )
78
+ ok = false; /* conflicting styles */
77
79
newDateStyle = USE_ISO_DATES ;
78
- scnt ++ ;
80
+ have_style = true ;
79
81
}
80
82
else if (pg_strcasecmp (tok , "SQL" ) == 0 )
81
83
{
84
+ if (have_style && newDateStyle != USE_SQL_DATES )
85
+ ok = false; /* conflicting styles */
82
86
newDateStyle = USE_SQL_DATES ;
83
- scnt ++ ;
87
+ have_style = true ;
84
88
}
85
89
else if (pg_strncasecmp (tok , "POSTGRES" , 8 ) == 0 )
86
90
{
91
+ if (have_style && newDateStyle != USE_POSTGRES_DATES )
92
+ ok = false; /* conflicting styles */
87
93
newDateStyle = USE_POSTGRES_DATES ;
88
- scnt ++ ;
94
+ have_style = true ;
89
95
}
90
96
else if (pg_strcasecmp (tok , "GERMAN" ) == 0 )
91
97
{
98
+ if (have_style && newDateStyle != USE_GERMAN_DATES )
99
+ ok = false; /* conflicting styles */
92
100
newDateStyle = USE_GERMAN_DATES ;
93
- scnt ++ ;
101
+ have_style = true ;
94
102
/* GERMAN also sets DMY, unless explicitly overridden */
95
- if (ocnt == 0 )
103
+ if (! have_order )
96
104
newDateOrder = DATEORDER_DMY ;
97
105
}
98
106
else if (pg_strcasecmp (tok , "YMD" ) == 0 )
99
107
{
108
+ if (have_order && newDateOrder != DATEORDER_YMD )
109
+ ok = false; /* conflicting orders */
100
110
newDateOrder = DATEORDER_YMD ;
101
- ocnt ++ ;
111
+ have_order = true ;
102
112
}
103
113
else if (pg_strcasecmp (tok , "DMY" ) == 0 ||
104
114
pg_strncasecmp (tok , "EURO" , 4 ) == 0 )
105
115
{
116
+ if (have_order && newDateOrder != DATEORDER_DMY )
117
+ ok = false; /* conflicting orders */
106
118
newDateOrder = DATEORDER_DMY ;
107
- ocnt ++ ;
119
+ have_order = true ;
108
120
}
109
121
else if (pg_strcasecmp (tok , "MDY" ) == 0 ||
110
122
pg_strcasecmp (tok , "US" ) == 0 ||
111
123
pg_strncasecmp (tok , "NONEURO" , 7 ) == 0 )
112
124
{
125
+ if (have_order && newDateOrder != DATEORDER_MDY )
126
+ ok = false; /* conflicting orders */
113
127
newDateOrder = DATEORDER_MDY ;
114
- ocnt ++ ;
128
+ have_order = true ;
115
129
}
116
130
else if (pg_strcasecmp (tok , "DEFAULT" ) == 0 )
117
131
{
@@ -128,9 +142,9 @@ assign_datestyle(const char *value, bool doit, GucSource source)
128
142
129
143
subval = assign_datestyle (GetConfigOptionResetString ("datestyle" ),
130
144
true, source );
131
- if (scnt == 0 )
145
+ if (! have_style )
132
146
newDateStyle = DateStyle ;
133
- if (ocnt == 0 )
147
+ if (! have_order )
134
148
newDateOrder = DateOrder ;
135
149
DateStyle = saveDateStyle ;
136
150
DateOrder = saveDateOrder ;
@@ -155,9 +169,6 @@ assign_datestyle(const char *value, bool doit, GucSource source)
155
169
}
156
170
}
157
171
158
- if (scnt > 1 || ocnt > 1 )
159
- ok = false;
160
-
161
172
pfree (rawstring );
162
173
list_free (elemlist );
163
174
0 commit comments