aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-05-07 00:24:59 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-05-07 00:24:59 +0000
commit0bd61548ab8d1ac5fee63f48ee9b384502a51ad6 (patch)
treeb0c63b75585d0c396e67a3acd204e226b13eae4b /src/backend/utils/adt
parent4d46274b33db52618ccf49550213b4d5ce4a7981 (diff)
downloadpostgresql-0bd61548ab8d1ac5fee63f48ee9b384502a51ad6.tar.gz
postgresql-0bd61548ab8d1ac5fee63f48ee9b384502a51ad6.zip
Solve the 'Turkish problem' with undesirable locale behavior for case
conversion of basic ASCII letters. Remove all uses of strcasecmp and strncasecmp in favor of new functions pg_strcasecmp and pg_strncasecmp; remove most but not all direct uses of toupper and tolower in favor of pg_toupper and pg_tolower. These functions use the same notions of case folding already developed for identifier case conversion. I left the straight locale-based folding in place for situations where we are just manipulating user data and not trying to match it to built-in strings --- for example, the SQL upper() function is still locale dependent. Perhaps this will prove not to be what's wanted, but at the moment we can initdb and pass regression tests in Turkish locale.
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r--src/backend/utils/adt/acl.c82
-rw-r--r--src/backend/utils/adt/bool.c14
-rw-r--r--src/backend/utils/adt/cash.c4
-rw-r--r--src/backend/utils/adt/date.c63
-rw-r--r--src/backend/utils/adt/datetime.c12
-rw-r--r--src/backend/utils/adt/encode.c4
-rw-r--r--src/backend/utils/adt/float.c14
-rw-r--r--src/backend/utils/adt/formatting.c22
-rw-r--r--src/backend/utils/adt/numeric.c4
-rw-r--r--src/backend/utils/adt/regexp.c8
-rw-r--r--src/backend/utils/adt/regproc.c4
-rw-r--r--src/backend/utils/adt/tid.c4
-rw-r--r--src/backend/utils/adt/timestamp.c193
13 files changed, 152 insertions, 276 deletions
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index 5883c188784..214bda2245a 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.103 2004/05/02 13:38:27 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.104 2004/05/07 00:24:57 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -882,29 +882,29 @@ convert_priv_string(text *priv_type_text)
priv_type = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(priv_type_text)));
- if (strcasecmp(priv_type, "SELECT") == 0)
+ if (pg_strcasecmp(priv_type, "SELECT") == 0)
return ACL_SELECT;
- if (strcasecmp(priv_type, "INSERT") == 0)
+ if (pg_strcasecmp(priv_type, "INSERT") == 0)
return ACL_INSERT;
- if (strcasecmp(priv_type, "UPDATE") == 0)
+ if (pg_strcasecmp(priv_type, "UPDATE") == 0)
return ACL_UPDATE;
- if (strcasecmp(priv_type, "DELETE") == 0)
+ if (pg_strcasecmp(priv_type, "DELETE") == 0)
return ACL_DELETE;
- if (strcasecmp(priv_type, "RULE") == 0)
+ if (pg_strcasecmp(priv_type, "RULE") == 0)
return ACL_RULE;
- if (strcasecmp(priv_type, "REFERENCES") == 0)
+ if (pg_strcasecmp(priv_type, "REFERENCES") == 0)
return ACL_REFERENCES;
- if (strcasecmp(priv_type, "TRIGGER") == 0)
+ if (pg_strcasecmp(priv_type, "TRIGGER") == 0)
return ACL_TRIGGER;
- if (strcasecmp(priv_type, "EXECUTE") == 0)
+ if (pg_strcasecmp(priv_type, "EXECUTE") == 0)
return ACL_EXECUTE;
- if (strcasecmp(priv_type, "USAGE") == 0)
+ if (pg_strcasecmp(priv_type, "USAGE") == 0)
return ACL_USAGE;
- if (strcasecmp(priv_type, "CREATE") == 0)
+ if (pg_strcasecmp(priv_type, "CREATE") == 0)
return ACL_CREATE;
- if (strcasecmp(priv_type, "TEMP") == 0)
+ if (pg_strcasecmp(priv_type, "TEMP") == 0)
return ACL_CREATE_TEMP;
- if (strcasecmp(priv_type, "TEMPORARY") == 0)
+ if (pg_strcasecmp(priv_type, "TEMPORARY") == 0)
return ACL_CREATE_TEMP;
ereport(ERROR,
@@ -1097,39 +1097,39 @@ convert_table_priv_string(text *priv_type_text)
/*
* Return mode from priv_type string
*/
- if (strcasecmp(priv_type, "SELECT") == 0)
+ if (pg_strcasecmp(priv_type, "SELECT") == 0)
return ACL_SELECT;
- if (strcasecmp(priv_type, "SELECT WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "SELECT WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_SELECT);
- if (strcasecmp(priv_type, "INSERT") == 0)
+ if (pg_strcasecmp(priv_type, "INSERT") == 0)
return ACL_INSERT;
- if (strcasecmp(priv_type, "INSERT WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "INSERT WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_INSERT);
- if (strcasecmp(priv_type, "UPDATE") == 0)
+ if (pg_strcasecmp(priv_type, "UPDATE") == 0)
return ACL_UPDATE;
- if (strcasecmp(priv_type, "UPDATE WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "UPDATE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_UPDATE);
- if (strcasecmp(priv_type, "DELETE") == 0)
+ if (pg_strcasecmp(priv_type, "DELETE") == 0)
return ACL_DELETE;
- if (strcasecmp(priv_type, "DELETE WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "DELETE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_DELETE);
- if (strcasecmp(priv_type, "RULE") == 0)
+ if (pg_strcasecmp(priv_type, "RULE") == 0)
return ACL_RULE;
- if (strcasecmp(priv_type, "RULE WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "RULE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_RULE);
- if (strcasecmp(priv_type, "REFERENCES") == 0)
+ if (pg_strcasecmp(priv_type, "REFERENCES") == 0)
return ACL_REFERENCES;
- if (strcasecmp(priv_type, "REFERENCES WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "REFERENCES WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_REFERENCES);
- if (strcasecmp(priv_type, "TRIGGER") == 0)
+ if (pg_strcasecmp(priv_type, "TRIGGER") == 0)
return ACL_TRIGGER;
- if (strcasecmp(priv_type, "TRIGGER WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "TRIGGER WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_TRIGGER);
ereport(ERROR,
@@ -1329,19 +1329,19 @@ convert_database_priv_string(text *priv_type_text)
/*
* Return mode from priv_type string
*/
- if (strcasecmp(priv_type, "CREATE") == 0)
+ if (pg_strcasecmp(priv_type, "CREATE") == 0)
return ACL_CREATE;
- if (strcasecmp(priv_type, "CREATE WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "CREATE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_CREATE);
- if (strcasecmp(priv_type, "TEMPORARY") == 0)
+ if (pg_strcasecmp(priv_type, "TEMPORARY") == 0)
return ACL_CREATE_TEMP;
- if (strcasecmp(priv_type, "TEMPORARY WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "TEMPORARY WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP);
- if (strcasecmp(priv_type, "TEMP") == 0)
+ if (pg_strcasecmp(priv_type, "TEMP") == 0)
return ACL_CREATE_TEMP;
- if (strcasecmp(priv_type, "TEMP WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "TEMP WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP);
ereport(ERROR,
@@ -1543,9 +1543,9 @@ convert_function_priv_string(text *priv_type_text)
/*
* Return mode from priv_type string
*/
- if (strcasecmp(priv_type, "EXECUTE") == 0)
+ if (pg_strcasecmp(priv_type, "EXECUTE") == 0)
return ACL_EXECUTE;
- if (strcasecmp(priv_type, "EXECUTE WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "EXECUTE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_EXECUTE);
ereport(ERROR,
@@ -1747,9 +1747,9 @@ convert_language_priv_string(text *priv_type_text)
/*
* Return mode from priv_type string
*/
- if (strcasecmp(priv_type, "USAGE") == 0)
+ if (pg_strcasecmp(priv_type, "USAGE") == 0)
return ACL_USAGE;
- if (strcasecmp(priv_type, "USAGE WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "USAGE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_USAGE);
ereport(ERROR,
@@ -1951,14 +1951,14 @@ convert_schema_priv_string(text *priv_type_text)
/*
* Return mode from priv_type string
*/
- if (strcasecmp(priv_type, "CREATE") == 0)
+ if (pg_strcasecmp(priv_type, "CREATE") == 0)
return ACL_CREATE;
- if (strcasecmp(priv_type, "CREATE WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "CREATE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_CREATE);
- if (strcasecmp(priv_type, "USAGE") == 0)
+ if (pg_strcasecmp(priv_type, "USAGE") == 0)
return ACL_USAGE;
- if (strcasecmp(priv_type, "USAGE WITH GRANT OPTION") == 0)
+ if (pg_strcasecmp(priv_type, "USAGE WITH GRANT OPTION") == 0)
return ACL_GRANT_OPTION_FOR(ACL_USAGE);
ereport(ERROR,
diff --git a/src/backend/utils/adt/bool.c b/src/backend/utils/adt/bool.c
index 05f03c26344..ddb8c923591 100644
--- a/src/backend/utils/adt/bool.c
+++ b/src/backend/utils/adt/bool.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/bool.c,v 1.31 2003/11/29 19:51:58 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/bool.c,v 1.32 2004/05/07 00:24:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -39,35 +39,35 @@ boolin(PG_FUNCTION_ARGS)
{
case 't':
case 'T':
- if (strncasecmp(b, "true", strlen(b)) == 0)
+ if (pg_strncasecmp(b, "true", strlen(b)) == 0)
PG_RETURN_BOOL(true);
break;
case 'f':
case 'F':
- if (strncasecmp(b, "false", strlen(b)) == 0)
+ if (pg_strncasecmp(b, "false", strlen(b)) == 0)
PG_RETURN_BOOL(false);
break;
case 'y':
case 'Y':
- if (strncasecmp(b, "yes", strlen(b)) == 0)
+ if (pg_strncasecmp(b, "yes", strlen(b)) == 0)
PG_RETURN_BOOL(true);
break;
case '1':
- if (strncasecmp(b, "1", strlen(b)) == 0)
+ if (pg_strncasecmp(b, "1", strlen(b)) == 0)
PG_RETURN_BOOL(true);
break;
case 'n':
case 'N':
- if (strncasecmp(b, "no", strlen(b)) == 0)
+ if (pg_strncasecmp(b, "no", strlen(b)) == 0)
PG_RETURN_BOOL(false);
break;
case '0':
- if (strncasecmp(b, "0", strlen(b)) == 0)
+ if (pg_strncasecmp(b, "0", strlen(b)) == 0)
PG_RETURN_BOOL(false);
break;
diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c
index dfe8331b010..166decb74e4 100644
--- a/src/backend/utils/adt/cash.c
+++ b/src/backend/utils/adt/cash.c
@@ -9,7 +9,7 @@
* workings can be found in the book "Software Solutions in C" by
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.62 2003/11/29 19:51:58 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.63 2004/05/07 00:24:58 tgl Exp $
*/
#include "postgres.h"
@@ -745,7 +745,7 @@ cash_words(PG_FUNCTION_ARGS)
strcat(buf, m0 == 1 ? " cent" : " cents");
/* capitalize output */
- buf[0] = toupper((unsigned char) buf[0]);
+ buf[0] = pg_toupper((unsigned char) buf[0]);
/* make a text type for output */
result = (text *) palloc(strlen(buf) + VARHDRSZ);
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index 9346f2ab68c..555ba5455ad 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.95 2004/02/14 20:16:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.96 2004/05/07 00:24:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -23,6 +23,7 @@
#include "access/hash.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
+#include "parser/scansup.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/nabstime.h"
@@ -1627,23 +1628,11 @@ time_part(PG_FUNCTION_ARGS)
float8 result;
int type,
val;
- int i;
- char *up,
- *lp,
- lowunits[MAXDATELEN + 1];
-
- if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("\"time\" units \"%s\" not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))))));
+ char *lowunits;
- up = VARDATA(units);
- lp = lowunits;
- for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
- *lp++ = tolower((unsigned char) *up++);
- *lp = '\0';
+ lowunits = downcase_truncate_identifier(VARDATA(units),
+ VARSIZE(units) - VARHDRSZ,
+ false);
type = DecodeUnits(0, lowunits, &val);
if (type == UNKNOWN_FIELD)
@@ -2390,23 +2379,11 @@ timetz_part(PG_FUNCTION_ARGS)
float8 result;
int type,
val;
- int i;
- char *up,
- *lp,
- lowunits[MAXDATELEN + 1];
-
- if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("\"time with time zone\" units \"%s\" not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))))));
+ char *lowunits;
- up = VARDATA(units);
- lp = lowunits;
- for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
- *lp++ = tolower((unsigned char) *up++);
- *lp = '\0';
+ lowunits = downcase_truncate_identifier(VARDATA(units),
+ VARSIZE(units) - VARHDRSZ,
+ false);
type = DecodeUnits(0, lowunits, &val);
if (type == UNKNOWN_FIELD)
@@ -2523,23 +2500,11 @@ timetz_zone(PG_FUNCTION_ARGS)
int tz;
int type,
val;
- int i;
- char *up,
- *lp,
- lowzone[MAXDATELEN + 1];
-
- if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("time zone \"%s\" not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(zone))))));
+ char *lowzone;
- up = VARDATA(zone);
- lp = lowzone;
- for (i = 0; i < (VARSIZE(zone) - VARHDRSZ); i++)
- *lp++ = tolower((unsigned char) *up++);
- *lp = '\0';
+ lowzone = downcase_truncate_identifier(VARDATA(zone),
+ VARSIZE(zone) - VARHDRSZ,
+ false);
type = DecodeSpecial(0, lowzone, &val);
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index be764ce45e2..040e1691daf 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.126 2004/03/30 15:53:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.127 2004/05/07 00:24:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -794,7 +794,7 @@ ParseDateTime(const char *timestr, char *lowstr,
{
ftype[nf] = DTK_DATE;
while (isalnum((unsigned char) *cp) || (*cp == delim))
- *lp++ = tolower((unsigned char) *cp++);
+ *lp++ = pg_tolower((unsigned char) *cp++);
}
}
@@ -822,9 +822,9 @@ ParseDateTime(const char *timestr, char *lowstr,
else if (isalpha((unsigned char) *cp))
{
ftype[nf] = DTK_STRING;
- *lp++ = tolower((unsigned char) *cp++);
+ *lp++ = pg_tolower((unsigned char) *cp++);
while (isalpha((unsigned char) *cp))
- *lp++ = tolower((unsigned char) *cp++);
+ *lp++ = pg_tolower((unsigned char) *cp++);
/*
* Full date string with leading text month? Could also be a
@@ -860,9 +860,9 @@ ParseDateTime(const char *timestr, char *lowstr,
else if (isalpha((unsigned char) *cp))
{
ftype[nf] = DTK_SPECIAL;
- *lp++ = tolower((unsigned char) *cp++);
+ *lp++ = pg_tolower((unsigned char) *cp++);
while (isalpha((unsigned char) *cp))
- *lp++ = tolower((unsigned char) *cp++);
+ *lp++ = pg_tolower((unsigned char) *cp++);
}
/* otherwise something wrong... */
else
diff --git a/src/backend/utils/adt/encode.c b/src/backend/utils/adt/encode.c
index e7edc83f6fd..488afa09666 100644
--- a/src/backend/utils/adt/encode.c
+++ b/src/backend/utils/adt/encode.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/encode.c,v 1.10 2003/11/29 19:51:58 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/encode.c,v 1.11 2004/05/07 00:24:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -549,7 +549,7 @@ pg_find_encoding(const char *name)
int i;
for (i = 0; enclist[i].name; i++)
- if (strcasecmp(enclist[i].name, name) == 0)
+ if (pg_strcasecmp(enclist[i].name, name) == 0)
return &enclist[i].enc;
return NULL;
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index a9032492155..c48af109e3e 100644
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.103 2004/04/01 23:52:18 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.104 2004/05/07 00:24:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -291,17 +291,17 @@ float4in(PG_FUNCTION_ARGS)
* set ERANGE anyway...) Therefore, we check for these inputs
* ourselves.
*/
- if (strncasecmp(num, "NaN", 3) == 0)
+ if (pg_strncasecmp(num, "NaN", 3) == 0)
{
val = get_float4_nan();
endptr = num + 3;
}
- else if (strncasecmp(num, "Infinity", 8) == 0)
+ else if (pg_strncasecmp(num, "Infinity", 8) == 0)
{
val = get_float4_infinity();
endptr = num + 8;
}
- else if (strncasecmp(num, "-Infinity", 9) == 0)
+ else if (pg_strncasecmp(num, "-Infinity", 9) == 0)
{
val = - get_float4_infinity();
endptr = num + 9;
@@ -456,17 +456,17 @@ float8in(PG_FUNCTION_ARGS)
* set ERANGE anyway...) Therefore, we check for these inputs
* ourselves.
*/
- if (strncasecmp(num, "NaN", 3) == 0)
+ if (pg_strncasecmp(num, "NaN", 3) == 0)
{
val = get_float8_nan();
endptr = num + 3;
}
- else if (strncasecmp(num, "Infinity", 8) == 0)
+ else if (pg_strncasecmp(num, "Infinity", 8) == 0)
{
val = get_float8_infinity();
endptr = num + 8;
}
- else if (strncasecmp(num, "-Infinity", 9) == 0)
+ else if (pg_strncasecmp(num, "-Infinity", 9) == 0)
{
val = - get_float8_infinity();
endptr = num + 9;
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 3393a0ac4ce..6a9f26e0001 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------
* formatting.c
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.73 2004/03/30 15:53:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.74 2004/05/07 00:24:58 tgl Exp $
*
*
* Portions Copyright (c) 1999-2003, PostgreSQL Global Development Group
@@ -1477,7 +1477,7 @@ str_toupper(char *buff)
while (*p_buff)
{
- *p_buff = toupper((unsigned char) *p_buff);
+ *p_buff = pg_toupper((unsigned char) *p_buff);
++p_buff;
}
return buff;
@@ -1497,7 +1497,7 @@ str_tolower(char *buff)
while (*p_buff)
{
- *p_buff = tolower((unsigned char) *p_buff);
+ *p_buff = pg_tolower((unsigned char) *p_buff);
++p_buff;
}
return buff;
@@ -1523,9 +1523,9 @@ seq_search(char *name, char **array, int type, int max, int *len)
/* set first char */
if (type == ONE_UPPER || type == ALL_UPPER)
- *name = toupper((unsigned char) *name);
+ *name = pg_toupper((unsigned char) *name);
else if (type == ALL_LOWER)
- *name = tolower((unsigned char) *name);
+ *name = pg_tolower((unsigned char) *name);
for (last = 0, a = array; *a != NULL; a++)
{
@@ -1559,9 +1559,9 @@ seq_search(char *name, char **array, int type, int max, int *len)
if (i > last)
{
if (type == ONE_UPPER || type == ALL_LOWER)
- *n = tolower((unsigned char) *n);
+ *n = pg_tolower((unsigned char) *n);
else if (type == ALL_UPPER)
- *n = toupper((unsigned char) *n);
+ *n = pg_toupper((unsigned char) *n);
last = i;
}
@@ -2192,7 +2192,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
case DCH_month:
sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, months_full[tm->tm_mon - 1]);
- *inout = tolower((unsigned char) *inout);
+ *inout = pg_tolower((unsigned char) *inout);
if (S_FM(suf))
return strlen(p_inout) - 1;
else
@@ -2209,7 +2209,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
case DCH_mon:
strcpy(inout, months[tm->tm_mon - 1]);
- *inout = tolower((unsigned char) *inout);
+ *inout = pg_tolower((unsigned char) *inout);
return 2;
case DCH_MM:
@@ -2255,7 +2255,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
case DCH_day:
sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, days[tm->tm_wday]);
- *inout = tolower((unsigned char) *inout);
+ *inout = pg_tolower((unsigned char) *inout);
if (S_FM(suf))
return strlen(p_inout) - 1;
else
@@ -2272,7 +2272,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
case DCH_dy:
strcpy(inout, days[tm->tm_wday]);
- *inout = tolower((unsigned char) *inout);
+ *inout = pg_tolower((unsigned char) *inout);
return 2;
case DCH_DDD:
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 341bd9cc4c5..28390ee5c35 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -14,7 +14,7 @@
* Copyright (c) 1998-2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.72 2004/03/15 03:29:22 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.73 2004/05/07 00:24:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -315,7 +315,7 @@ numeric_in(PG_FUNCTION_ARGS)
/*
* Check for NaN
*/
- if (strcasecmp(str, "NaN") == 0)
+ if (pg_strcasecmp(str, "NaN") == 0)
PG_RETURN_NUMERIC(make_result(&const_nan));
/*
diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c
index cc26ab09d8c..6491bbca705 100644
--- a/src/backend/utils/adt/regexp.c
+++ b/src/backend/utils/adt/regexp.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.52 2004/02/03 17:52:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.53 2004/05/07 00:24:58 tgl Exp $
*
* Alistair Crooks added the code for the regex caching
* agc - cached the regular expressions used - there's a good chance
@@ -233,17 +233,17 @@ const char *
assign_regex_flavor(const char *value,
bool doit, GucSource source)
{
- if (strcasecmp(value, "advanced") == 0)
+ if (pg_strcasecmp(value, "advanced") == 0)
{
if (doit)
regex_flavor = REG_ADVANCED;
}
- else if (strcasecmp(value, "extended") == 0)
+ else if (pg_strcasecmp(value, "extended") == 0)
{
if (doit)
regex_flavor = REG_EXTENDED;
}
- else if (strcasecmp(value, "basic") == 0)
+ else if (pg_strcasecmp(value, "basic") == 0)
{
if (doit)
regex_flavor = REG_BASIC;
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 40203161e7d..fe2e7aa6cf8 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/regproc.c,v 1.86 2004/01/31 05:09:40 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/regproc.c,v 1.87 2004/05/07 00:24:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1259,7 +1259,7 @@ parseNameAndArgTypes(const char *string, const char *caller,
*ptr2 = '\0';
}
- if (allowNone && strcasecmp(typename, "none") == 0)
+ if (allowNone && pg_strcasecmp(typename, "none") == 0)
{
/* Special case for NONE */
typeid = InvalidOid;
diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c
index 0914abaaad9..8433bc98c4d 100644
--- a/src/backend/utils/adt/tid.c
+++ b/src/backend/utils/adt/tid.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/tid.c,v 1.42 2003/11/29 19:51:59 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/tid.c,v 1.43 2004/05/07 00:24:58 tgl Exp $
*
* NOTES
* input routine largely stolen from boxin().
@@ -218,7 +218,7 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
for (i = 0; i < natts; i++)
{
- if (strcasecmp(NameStr(att->attrs[i]->attname), "ctid") == 0)
+ if (strcmp(NameStr(att->attrs[i]->attname), "ctid") == 0)
{
if (att->attrs[i]->atttypid != TIDOID)
elog(ERROR, "ctid isn't of type TID");
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index b2628a3a6f6..cd59b7f34ad 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.104 2004/04/10 18:02:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.105 2004/05/07 00:24:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -26,6 +26,7 @@
#include "catalog/pg_type.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
+#include "parser/scansup.h"
#include "utils/array.h"
#include "utils/builtins.h"
@@ -2699,32 +2700,20 @@ timestamp_trunc(PG_FUNCTION_ARGS)
Timestamp result;
int type,
val;
- int i;
- char *up,
- *lp,
- lowunits[MAXDATELEN + 1];
+ char *lowunits;
fsec_t fsec;
struct tm tt,
*tm = &tt;
- if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("timestamp units \"%s\" not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))))));
+ if (TIMESTAMP_NOT_FINITE(timestamp))
+ PG_RETURN_TIMESTAMP(timestamp);
- up = VARDATA(units);
- lp = lowunits;
- for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
- *lp++ = tolower((unsigned char) *up++);
- *lp = '\0';
+ lowunits = downcase_truncate_identifier(VARDATA(units),
+ VARSIZE(units) - VARHDRSZ,
+ false);
type = DecodeUnits(0, lowunits, &val);
- if (TIMESTAMP_NOT_FINITE(timestamp))
- PG_RETURN_TIMESTAMP(timestamp);
-
if (type == UNITS)
{
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
@@ -2814,32 +2803,21 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
int tz;
int type,
val;
- int i;
- char *up,
- *lp,
- lowunits[MAXDATELEN + 1];
+ char *lowunits;
fsec_t fsec;
char *tzn;
struct tm tt,
*tm = &tt;
- if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("timestamp with time zone units \"%s\" not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))))));
- up = VARDATA(units);
- lp = lowunits;
- for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
- *lp++ = tolower((unsigned char) *up++);
- *lp = '\0';
-
- type = DecodeUnits(0, lowunits, &val);
-
if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_TIMESTAMPTZ(timestamp);
+ lowunits = downcase_truncate_identifier(VARDATA(units),
+ VARSIZE(units) - VARHDRSZ,
+ false);
+
+ type = DecodeUnits(0, lowunits, &val);
+
if (type == UNITS)
{
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
@@ -2929,27 +2907,16 @@ interval_trunc(PG_FUNCTION_ARGS)
Interval *result;
int type,
val;
- int i;
- char *up,
- *lp,
- lowunits[MAXDATELEN + 1];
+ char *lowunits;
fsec_t fsec;
struct tm tt,
*tm = &tt;
result = (Interval *) palloc(sizeof(Interval));
- if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("interval units \"%s\" not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))))));
- up = VARDATA(units);
- lp = lowunits;
- for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
- *lp++ = tolower((unsigned char) *up++);
- *lp = '\0';
+ lowunits = downcase_truncate_identifier(VARDATA(units),
+ VARSIZE(units) - VARHDRSZ,
+ false);
type = DecodeUnits(0, lowunits, &val);
@@ -3173,36 +3140,25 @@ timestamp_part(PG_FUNCTION_ARGS)
float8 result;
int type,
val;
- int i;
- char *up,
- *lp,
- lowunits[MAXDATELEN + 1];
+ char *lowunits;
fsec_t fsec;
struct tm tt,
*tm = &tt;
- if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("timestamp units \"%s\" not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))))));
- up = VARDATA(units);
- lp = lowunits;
- for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
- *lp++ = tolower((unsigned char) *up++);
- *lp = '\0';
-
- type = DecodeUnits(0, lowunits, &val);
- if (type == UNKNOWN_FIELD)
- type = DecodeSpecial(0, lowunits, &val);
-
if (TIMESTAMP_NOT_FINITE(timestamp))
{
result = 0;
PG_RETURN_FLOAT8(result);
}
+ lowunits = downcase_truncate_identifier(VARDATA(units),
+ VARSIZE(units) - VARHDRSZ,
+ false);
+
+ type = DecodeUnits(0, lowunits, &val);
+ if (type == UNKNOWN_FIELD)
+ type = DecodeSpecial(0, lowunits, &val);
+
if (type == UNITS)
{
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
@@ -3395,38 +3351,27 @@ timestamptz_part(PG_FUNCTION_ARGS)
int tz;
int type,
val;
- int i;
- char *up,
- *lp,
- lowunits[MAXDATELEN + 1];
+ char *lowunits;
double dummy;
fsec_t fsec;
char *tzn;
struct tm tt,
*tm = &tt;
- if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("timestamp with time zone units \"%s\" not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))))));
- up = VARDATA(units);
- lp = lowunits;
- for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
- *lp++ = tolower((unsigned char) *up++);
- *lp = '\0';
-
- type = DecodeUnits(0, lowunits, &val);
- if (type == UNKNOWN_FIELD)
- type = DecodeSpecial(0, lowunits, &val);
-
if (TIMESTAMP_NOT_FINITE(timestamp))
{
result = 0;
PG_RETURN_FLOAT8(result);
}
+ lowunits = downcase_truncate_identifier(VARDATA(units),
+ VARSIZE(units) - VARHDRSZ,
+ false);
+
+ type = DecodeUnits(0, lowunits, &val);
+ if (type == UNKNOWN_FIELD)
+ type = DecodeSpecial(0, lowunits, &val);
+
if (type == UNITS)
{
if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0)
@@ -3597,25 +3542,14 @@ interval_part(PG_FUNCTION_ARGS)
float8 result;
int type,
val;
- int i;
- char *up,
- *lp,
- lowunits[MAXDATELEN + 1];
+ char *lowunits;
fsec_t fsec;
struct tm tt,
*tm = &tt;
- if (VARSIZE(units) - VARHDRSZ > MAXDATELEN)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("interval units \"%s\" not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(units))))));
- up = VARDATA(units);
- lp = lowunits;
- for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++)
- *lp++ = tolower((unsigned char) *up++);
- *lp = '\0';
+ lowunits = downcase_truncate_identifier(VARDATA(units),
+ VARSIZE(units) - VARHDRSZ,
+ false);
type = DecodeUnits(0, lowunits, &val);
if (type == UNKNOWN_FIELD)
@@ -3744,26 +3678,14 @@ timestamp_zone(PG_FUNCTION_ARGS)
int tz;
int type,
val;
- int i;
- char *up,
- *lp,
- lowzone[MAXDATELEN + 1];
-
- if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("time zone \"%s\" not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(zone))))));
+ char *lowzone;
if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_TIMESTAMPTZ(timestamp);
- up = VARDATA(zone);
- lp = lowzone;
- for (i = 0; i < (VARSIZE(zone) - VARHDRSZ); i++)
- *lp++ = tolower((unsigned char) *up++);
- *lp = '\0';
+ lowzone = downcase_truncate_identifier(VARDATA(zone),
+ VARSIZE(zone) - VARHDRSZ,
+ false);
type = DecodeSpecial(0, lowzone, &val);
@@ -3903,28 +3825,17 @@ timestamptz_zone(PG_FUNCTION_ARGS)
int tz;
int type,
val;
- int i;
- char *up,
- *lp,
- lowzone[MAXDATELEN + 1];
-
- if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("time zone \"%s\" not recognized",
- DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(zone))))));
- up = VARDATA(zone);
- lp = lowzone;
- for (i = 0; i < (VARSIZE(zone) - VARHDRSZ); i++)
- *lp++ = tolower((unsigned char) *up++);
- *lp = '\0';
-
- type = DecodeSpecial(0, lowzone, &val);
+ char *lowzone;
if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_NULL();
+ lowzone = downcase_truncate_identifier(VARDATA(zone),
+ VARSIZE(zone) - VARHDRSZ,
+ false);
+
+ type = DecodeSpecial(0, lowzone, &val);
+
if ((type == TZ) || (type == DTZ))
{
tz = val * 60;