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{
4343int newDateStyle = DateStyle ;
4444int newDateOrder = DateOrder ;
45+ bool have_style = false;
46+ bool have_order = false;
4547bool ok = true;
46- int scnt = 0 ,
47- ocnt = 0 ;
4848char * rawstring ;
4949char * result ;
5050List * elemlist ;
@@ -74,44 +74,58 @@ assign_datestyle(const char *value, bool doit, GucSource source)
7474
7575if (pg_strcasecmp (tok ,"ISO" )== 0 )
7676{
77+ if (have_style && newDateStyle != USE_ISO_DATES )
78+ ok = false;/* conflicting styles */
7779newDateStyle = USE_ISO_DATES ;
78- scnt ++ ;
80+ have_style = true ;
7981}
8082else if (pg_strcasecmp (tok ,"SQL" )== 0 )
8183{
84+ if (have_style && newDateStyle != USE_SQL_DATES )
85+ ok = false;/* conflicting styles */
8286newDateStyle = USE_SQL_DATES ;
83- scnt ++ ;
87+ have_style = true ;
8488}
8589else if (pg_strncasecmp (tok ,"POSTGRES" ,8 )== 0 )
8690{
91+ if (have_style && newDateStyle != USE_POSTGRES_DATES )
92+ ok = false;/* conflicting styles */
8793newDateStyle = USE_POSTGRES_DATES ;
88- scnt ++ ;
94+ have_style = true ;
8995}
9096else if (pg_strcasecmp (tok ,"GERMAN" )== 0 )
9197{
98+ if (have_style && newDateStyle != USE_GERMAN_DATES )
99+ ok = false;/* conflicting styles */
92100newDateStyle = 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 )
96104newDateOrder = DATEORDER_DMY ;
97105}
98106else if (pg_strcasecmp (tok ,"YMD" )== 0 )
99107{
108+ if (have_order && newDateOrder != DATEORDER_YMD )
109+ ok = false;/* conflicting orders */
100110newDateOrder = DATEORDER_YMD ;
101- ocnt ++ ;
111+ have_order = true ;
102112}
103113else if (pg_strcasecmp (tok ,"DMY" )== 0 ||
104114pg_strncasecmp (tok ,"EURO" ,4 )== 0 )
105115{
116+ if (have_order && newDateOrder != DATEORDER_DMY )
117+ ok = false;/* conflicting orders */
106118newDateOrder = DATEORDER_DMY ;
107- ocnt ++ ;
119+ have_order = true ;
108120}
109121else if (pg_strcasecmp (tok ,"MDY" )== 0 ||
110122pg_strcasecmp (tok ,"US" )== 0 ||
111123pg_strncasecmp (tok ,"NONEURO" ,7 )== 0 )
112124{
125+ if (have_order && newDateOrder != DATEORDER_MDY )
126+ ok = false;/* conflicting orders */
113127newDateOrder = DATEORDER_MDY ;
114- ocnt ++ ;
128+ have_order = true ;
115129}
116130else if (pg_strcasecmp (tok ,"DEFAULT" )== 0 )
117131{
@@ -128,9 +142,9 @@ assign_datestyle(const char *value, bool doit, GucSource source)
128142
129143subval = assign_datestyle (GetConfigOptionResetString ("datestyle" ),
130144 true,source );
131- if (scnt == 0 )
145+ if (! have_style )
132146newDateStyle = DateStyle ;
133- if (ocnt == 0 )
147+ if (! have_order )
134148newDateOrder = DateOrder ;
135149DateStyle = saveDateStyle ;
136150DateOrder = 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-
161172pfree (rawstring );
162173list_free (elemlist );
163174