Skip to content

Commit 8d6fbf6

Browse files
authored
Merge pull request #831 from OreoYang/nls_currency_territory_824
#824 Oracle Compatibility: Support for nls_currency/nls_iso_currency/…
2 parents c2399eb + 3398503 commit 8d6fbf6

File tree

1 file changed

+122
-1
lines changed

1 file changed

+122
-1
lines changed

src/backend/utils/misc/ivy_guc.c

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ int identifier_case_switch = INTERCHANGE;
3434
bool identifier_case_from_pg_dump = false;
3535
bool enable_case_switch = true;
3636

37-
37+
char *nls_territory = "AMERICA";
38+
char *nls_currency = "$";
39+
char *nls_iso_currency = "AMERICA";
3840
// int *nls_length_semantics = NULL;
3941
// char *nls_date_format = "";
4042
// char *nls_timestamp_format = "";
@@ -104,6 +106,10 @@ static bool check_nls_length_semantics(int *newval, void **extra, GucSource sour
104106
static bool check_compatible_mode(int *newval, void **extra, GucSource source);
105107
static bool check_database_mode(int *newval, void **extra, GucSource source);
106108
void assign_compatible_mode(int newval, void *extra);
109+
110+
static void nls_case_conversion(char **param, char type);
111+
static bool nls_length_check(char **newval, void **extra, GucSource source);
112+
static bool nls_territory_check(char **newval, void **extra, GucSource source);
107113
#endif
108114

109115
#if 0
@@ -311,6 +317,38 @@ static struct config_string Ivy_ConfigureNamesString[] =
311317
"YYYY-MM-DD HH24:MI:SS.FF6 TZH:TZM",
312318
NULL, NULL, NULL
313319
},
320+
{
321+
{"nls_territory", PGC_USERSET, COMPAT_ORACLE_OPTIONS,
322+
gettext_noop("Compatible Oracle NLS parameter for NLS_TERRITORY."),
323+
NULL,
324+
GUC_NOT_IN_SAMPLE
325+
},
326+
&nls_territory,
327+
"AMERICA",
328+
nls_territory_check, NULL, NULL
329+
},
330+
331+
{
332+
{"nls_currency", PGC_USERSET, COMPAT_ORACLE_OPTIONS,
333+
gettext_noop("Compatible Oracle NLS parameter for NLS_CURRENCY."),
334+
NULL,
335+
GUC_NOT_IN_SAMPLE
336+
},
337+
&nls_currency,
338+
"$",
339+
nls_length_check, NULL, NULL
340+
},
341+
342+
{
343+
{"nls_iso_currency", PGC_USERSET, COMPAT_ORACLE_OPTIONS,
344+
gettext_noop("Compatible Oracle NLS parameter for NLS_ISO_CURRENCY."),
345+
NULL,
346+
GUC_NOT_IN_SAMPLE
347+
},
348+
&nls_iso_currency,
349+
"AMERICA",
350+
nls_territory_check, NULL, NULL
351+
},
314352
#endif
315353
#if 0
316354
/* End-of-list marker */
@@ -480,4 +518,87 @@ assign_compatible_mode(int newval, void *extra)
480518
}
481519
}
482520
}
521+
522+
static void
523+
nls_case_conversion(char **param, char type)
524+
{
525+
char *p;
526+
527+
CASE_CONVERSION:
528+
if (type == 'u')
529+
{
530+
for (p = *param; p < *param + strlen(*param); ++p)
531+
if (97 <= *p && *p <= 122)
532+
*p -= 32;
533+
*p = '\0';
534+
}
535+
else if (type == 'l')
536+
{
537+
for (p = *param; p < *param + strlen(*param); ++p)
538+
if (65 <= *p && *p <= 90)
539+
*p += 32;
540+
*p = '\0';
541+
}
542+
else if (type == 'b')
543+
{
544+
bool has_upper = false,
545+
has_lower = false;
546+
547+
for (p = *param; p < *param + strlen(*param); ++p)
548+
{
549+
if (65 <= *p && *p <= 90)
550+
has_upper = true;
551+
else if (97 <= *p && *p <= 122)
552+
has_lower = true;
553+
if (has_upper && has_lower)
554+
return;
555+
}
556+
557+
if (has_upper && !has_lower)
558+
{
559+
type = 'l';
560+
goto CASE_CONVERSION;
561+
}
562+
else if (!has_upper && has_lower)
563+
{
564+
type = 'u';
565+
goto CASE_CONVERSION;
566+
}
567+
}
568+
}
569+
static bool
570+
nls_length_check(char **newval, void **extra, GucSource source)
571+
{
572+
if (DB_ORACLE == database_mode
573+
&& (IsNormalProcessingMode() || (IsUnderPostmaster && MyProcPort)))
574+
{
575+
if (strlen(*newval) > 255)
576+
ereport(ERROR, (errmsg("parameter value longer than 255 characters")));
577+
else if (isdigit(**newval))
578+
ereport(ERROR, (errmsg("Cannot access NLS data files "
579+
"or invalid environment specified")));
580+
else if (identifier_case_switch == INTERCHANGE)
581+
nls_case_conversion(newval, 'b');
582+
}
583+
584+
return true;
585+
}
586+
587+
static bool
588+
nls_territory_check(char **newval, void **extra, GucSource source)
589+
{
590+
if (DB_ORACLE == database_mode
591+
&& (IsNormalProcessingMode() || (IsUnderPostmaster && MyProcPort)))
592+
{
593+
if (pg_strcasecmp(*newval, "CHINA") == 0)
594+
memcpy(*newval, "CHINA", 5);
595+
else if (pg_strcasecmp(*newval, "AMERICA") == 0)
596+
memcpy(*newval, "AMERICA", 7);
597+
else
598+
ereport(ERROR, (errmsg("Cannot access NLS data files "
599+
"or invalid environment specified")));
600+
}
601+
602+
return true;
603+
}
483604
#endif

0 commit comments

Comments
 (0)