Skip to content

Commit 423ebb0

Browse files
committed
#824 Oracle Compatibility: Support for nls_currency/nls_iso_currency/nls_territory
1 parent 00e95cc commit 423ebb0

File tree

1 file changed

+119
-1
lines changed

1 file changed

+119
-1
lines changed

src/backend/utils/misc/ivy_guc.c

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ int identifier_case_switch = INTERCHANGE;
2121
bool identifier_case_from_pg_dump = false;
2222
bool enable_case_switch = true;
2323

24-
24+
char *nls_territory = "";
25+
char *nls_currency = "";
26+
char *nls_iso_currency = "";
2527
// int *nls_length_semantics = NULL;
2628
// char *nls_date_format = "";
2729
// char *nls_timestamp_format = "";
@@ -88,6 +90,10 @@ static bool check_nls_length_semantics(int *newval, void **extra, GucSource sour
8890
static bool check_compatible_mode(int *newval, void **extra, GucSource source);
8991
static bool check_database_mode(int *newval, void **extra, GucSource source);
9092
void assign_compatible_mode(int newval, void *extra);
93+
94+
static void nls_case_conversion(char **param, char type);
95+
static bool nls_length_check(char **newval, void **extra, GucSource source);
96+
static bool nls_territory_check(char **newval, void **extra, GucSource source);
9197
#endif
9298

9399
#if 0
@@ -269,6 +275,35 @@ static struct config_string Ivy_ConfigureNamesString[] =
269275
"YYYY-MM-DD HH24:MI:SS.FF6 TZH:TZM",
270276
NULL, NULL, NULL
271277
},
278+
{
279+
{"nls_territory", PGC_USERSET, COMPAT_ORACLE_OPTIONS,
280+
gettext_noop("Compatible Oracle NLS parameter for NLS_TERRITORY."),
281+
NULL
282+
},
283+
&nls_territory,
284+
"AMERICA",
285+
nls_territory_check, NULL, NULL
286+
},
287+
288+
{
289+
{"nls_currency", PGC_USERSET, COMPAT_ORACLE_OPTIONS,
290+
gettext_noop("Compatible Oracle NLS parameter for NLS_CURRENCY."),
291+
NULL
292+
},
293+
&nls_currency,
294+
"$",
295+
nls_length_check, NULL, NULL
296+
},
297+
298+
{
299+
{"nls_iso_currency", PGC_USERSET, COMPAT_ORACLE_OPTIONS,
300+
gettext_noop("Compatible Oracle NLS parameter for NLS_ISO_CURRENCY."),
301+
NULL
302+
},
303+
&nls_iso_currency,
304+
"AMERICA",
305+
nls_territory_check, NULL, NULL
306+
},
272307
#endif
273308
#if 0
274309
/* End-of-list marker */
@@ -438,4 +473,87 @@ assign_compatible_mode(int newval, void *extra)
438473
}
439474
}
440475
}
476+
477+
static void
478+
nls_case_conversion(char **param, char type)
479+
{
480+
char *p;
481+
482+
CASE_CONVERSION:
483+
if (type == 'u')
484+
{
485+
for (p = *param; p < *param + strlen(*param); ++p)
486+
if (97 <= *p && *p <= 122)
487+
*p -= 32;
488+
*p = '\0';
489+
}
490+
else if (type == 'l')
491+
{
492+
for (p = *param; p < *param + strlen(*param); ++p)
493+
if (65 <= *p && *p <= 90)
494+
*p += 32;
495+
*p = '\0';
496+
}
497+
else if (type == 'b')
498+
{
499+
bool has_upper = false,
500+
has_lower = false;
501+
502+
for (p = *param; p < *param + strlen(*param); ++p)
503+
{
504+
if (65 <= *p && *p <= 90)
505+
has_upper = true;
506+
else if (97 <= *p && *p <= 122)
507+
has_lower = true;
508+
if (has_upper && has_lower)
509+
return;
510+
}
511+
512+
if (has_upper && !has_lower)
513+
{
514+
type = 'l';
515+
goto CASE_CONVERSION;
516+
}
517+
else if (!has_upper && has_lower)
518+
{
519+
type = 'u';
520+
goto CASE_CONVERSION;
521+
}
522+
}
523+
}
524+
static bool
525+
nls_length_check(char **newval, void **extra, GucSource source)
526+
{
527+
if (DB_ORACLE == database_mode
528+
&& (IsNormalProcessingMode() || (IsUnderPostmaster && MyProcPort)))
529+
{
530+
if (strlen(*newval) > 255)
531+
ereport(ERROR, (errmsg("parameter value longer than 255 characters")));
532+
else if (isdigit(**newval))
533+
ereport(ERROR, (errmsg("Cannot access NLS data files "
534+
"or invalid environment specified")));
535+
else if (identifier_case_switch == INTERCHANGE)
536+
nls_case_conversion(newval, 'b');
537+
}
538+
539+
return true;
540+
}
541+
542+
static bool
543+
nls_territory_check(char **newval, void **extra, GucSource source)
544+
{
545+
if (DB_ORACLE == database_mode
546+
&& (IsNormalProcessingMode() || (IsUnderPostmaster && MyProcPort)))
547+
{
548+
if (pg_strcasecmp(*newval, "CHINA") == 0)
549+
memcpy(*newval, "CHINA", 5);
550+
else if (pg_strcasecmp(*newval, "AMERICA") == 0)
551+
memcpy(*newval, "AMERICA", 7);
552+
else
553+
ereport(ERROR, (errmsg("Cannot access NLS data files "
554+
"or invalid environment specified")));
555+
}
556+
557+
return true;
558+
}
441559
#endif

0 commit comments

Comments
 (0)