aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/variable.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-07-29 00:03:19 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-07-29 00:03:19 +0000
commit9c2a7c2269d1ecebd7f83e769bb2640cb82fa0e0 (patch)
treef868b45501a84e01215cefb03754bab63e23730b /src/backend/commands/variable.c
parent2baf4efe09f65d8e8cac32fb882ab9f0fd601574 (diff)
downloadpostgresql-9c2a7c2269d1ecebd7f83e769bb2640cb82fa0e0.tar.gz
postgresql-9c2a7c2269d1ecebd7f83e769bb2640cb82fa0e0.zip
Apply (a somewhat revised version of) Greg Mullane's patch to eliminate
heuristic determination of day vs month in date/time input. Add the ability to specify that input is interpreted as yy-mm-dd order (which formerly worked, but only for yy greater than 31). DateStyle's input component now has the preferred spellings DMY, MDY, or YMD; the older keywords European and US are now aliases for the first two of these. Per recent discussions on pgsql-general.
Diffstat (limited to 'src/backend/commands/variable.c')
-rw-r--r--src/backend/commands/variable.c74
1 files changed, 45 insertions, 29 deletions
diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c
index a9fc94adc3d..e0b041636e6 100644
--- a/src/backend/commands/variable.c
+++ b/src/backend/commands/variable.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.84 2003/07/28 00:09:14 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.85 2003/07/29 00:03:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -51,10 +51,10 @@ const char *
assign_datestyle(const char *value, bool doit, bool interactive)
{
int newDateStyle = DateStyle;
- bool newEuroDates = EuroDates;
+ int newDateOrder = DateOrder;
bool ok = true;
- int dcnt = 0,
- ecnt = 0;
+ int scnt = 0,
+ ocnt = 0;
char *rawstring;
char *result;
List *elemlist;
@@ -85,38 +85,43 @@ assign_datestyle(const char *value, bool doit, bool interactive)
if (strcasecmp(tok, "ISO") == 0)
{
newDateStyle = USE_ISO_DATES;
- dcnt++;
+ scnt++;
}
else if (strcasecmp(tok, "SQL") == 0)
{
newDateStyle = USE_SQL_DATES;
- dcnt++;
+ scnt++;
}
else if (strncasecmp(tok, "POSTGRES", 8) == 0)
{
newDateStyle = USE_POSTGRES_DATES;
- dcnt++;
+ scnt++;
}
else if (strcasecmp(tok, "GERMAN") == 0)
{
newDateStyle = USE_GERMAN_DATES;
- dcnt++;
- if ((ecnt > 0) && (!newEuroDates))
- ok = false;
- newEuroDates = TRUE;
+ scnt++;
+ /* GERMAN also sets DMY, unless explicitly overridden */
+ if (ocnt == 0)
+ newDateOrder = DATEORDER_DMY;
}
- else if (strncasecmp(tok, "EURO", 4) == 0)
+ else if (strcasecmp(tok, "YMD") == 0)
{
- newEuroDates = TRUE;
- ecnt++;
+ newDateOrder = DATEORDER_YMD;
+ ocnt++;
}
- else if (strcasecmp(tok, "US") == 0
- || strncasecmp(tok, "NONEURO", 7) == 0)
+ else if (strcasecmp(tok, "DMY") == 0 ||
+ strncasecmp(tok, "EURO", 4) == 0)
{
- newEuroDates = FALSE;
- ecnt++;
- if ((dcnt > 0) && (newDateStyle == USE_GERMAN_DATES))
- ok = false;
+ newDateOrder = DATEORDER_DMY;
+ ocnt++;
+ }
+ else if (strcasecmp(tok, "MDY") == 0 ||
+ strcasecmp(tok, "US") == 0 ||
+ strncasecmp(tok, "NONEURO", 7) == 0)
+ {
+ newDateOrder = DATEORDER_MDY;
+ ocnt++;
}
else if (strcasecmp(tok, "DEFAULT") == 0)
{
@@ -128,15 +133,17 @@ assign_datestyle(const char *value, bool doit, bool interactive)
* to handle constructs like "DEFAULT, ISO".
*/
int saveDateStyle = DateStyle;
- bool saveEuroDates = EuroDates;
+ int saveDateOrder = DateOrder;
const char *subval;
subval = assign_datestyle(GetConfigOptionResetString("datestyle"),
true, interactive);
- newDateStyle = DateStyle;
- newEuroDates = EuroDates;
+ if (scnt == 0)
+ newDateStyle = DateStyle;
+ if (ocnt == 0)
+ newDateOrder = DateOrder;
DateStyle = saveDateStyle;
- EuroDates = saveEuroDates;
+ DateOrder = saveDateOrder;
if (!subval)
{
ok = false;
@@ -145,8 +152,6 @@ assign_datestyle(const char *value, bool doit, bool interactive)
/* Here we know that our own return value is always malloc'd */
/* when doit is true */
free((char *) subval);
- dcnt++;
- ecnt++;
}
else
{
@@ -160,7 +165,7 @@ assign_datestyle(const char *value, bool doit, bool interactive)
}
}
- if (dcnt > 1 || ecnt > 1)
+ if (scnt > 1 || ocnt > 1)
ok = false;
pfree(rawstring);
@@ -203,14 +208,25 @@ assign_datestyle(const char *value, bool doit, bool interactive)
strcpy(result, "Postgres");
break;
}
- strcat(result, newEuroDates ? ", European" : ", US");
+ switch (newDateOrder)
+ {
+ case DATEORDER_YMD:
+ strcat(result, ", YMD");
+ break;
+ case DATEORDER_DMY:
+ strcat(result, ", DMY");
+ break;
+ default:
+ strcat(result, ", MDY");
+ break;
+ }
/*
* Finally, it's safe to assign to the global variables; the
* assignment cannot fail now.
*/
DateStyle = newDateStyle;
- EuroDates = newEuroDates;
+ DateOrder = newDateOrder;
return result;
}