PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pg_locale.c File Reference
#include "postgres.h"
#include <time.h>
#include "access/htup_details.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_database.h"
#include "common/hashfn.h"
#include "common/string.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/formatting.h"
#include "utils/guc_hooks.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/pg_locale.h"
#include "utils/syscache.h"
#include "lib/simplehash.h"
Include dependency graph for pg_locale.c:

Go to the source code of this file.

Data Structures

struct  collation_cache_entry
 

Macros

#define PGLOCALE_SUPPORT_ERROR(provider)    elog(ERROR, "unsupported collprovider for %s: %c", __func__, provider)
 
#define TEXTBUFLEN   1024
 
#define MAX_L10N_DATA   80
 
#define SH_PREFIX   collation_cache
 
#define SH_ELEMENT_TYPE   collation_cache_entry
 
#define SH_KEY_TYPE   Oid
 
#define SH_KEY   collid
 
#define SH_HASH_KEY(tb, key)   murmurhash32((uint32) key)
 
#define SH_EQUAL(tb, a, b)   (a == b)
 
#define SH_GET_HASH(tb, a)   a->hash
 
#define SH_SCOPE   static inline
 
#define SH_STORE_HASH
 
#define SH_DECLARE
 
#define SH_DEFINE
 

Functions

pg_locale_t create_pg_locale_builtin (Oid collid, MemoryContext context)
 
char * get_collation_actual_version_builtin (const char *collcollate)
 
pg_locale_t create_pg_locale_icu (Oid collid, MemoryContext context)
 
pg_locale_t create_pg_locale_libc (Oid collid, MemoryContext context)
 
char * get_collation_actual_version_libc (const char *collcollate)
 
size_t strlower_builtin (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t strtitle_builtin (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t strupper_builtin (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t strfold_builtin (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t strlower_icu (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t strtitle_icu (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t strupper_icu (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t strfold_icu (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t strlower_libc (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t strtitle_libc (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t strupper_libc (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
char * pg_perm_setlocale (int category, const char *locale)
 
bool check_locale (int category, const char *locale, char **canonname)
 
bool check_locale_monetary (char **newval, void **extra, GucSource source)
 
void assign_locale_monetary (const char *newval, void *extra)
 
bool check_locale_numeric (char **newval, void **extra, GucSource source)
 
void assign_locale_numeric (const char *newval, void *extra)
 
bool check_locale_time (char **newval, void **extra, GucSource source)
 
void assign_locale_time (const char *newval, void *extra)
 
bool check_locale_messages (char **newval, void **extra, GucSource source)
 
void assign_locale_messages (const char *newval, void *extra)
 
static void free_struct_lconv (struct lconv *s)
 
static bool struct_lconv_is_valid (struct lconv *s)
 
static void db_encoding_convert (int encoding, char **str)
 
struct lconv * PGLC_localeconv (void)
 
static void cache_single_string (char **dst, const char *src, int encoding)
 
void cache_locale_time (void)
 
static pg_locale_t create_pg_locale (Oid collid, MemoryContext context)
 
void init_database_collation (void)
 
pg_locale_t pg_newlocale_from_collation (Oid collid)
 
char * get_collation_actual_version (char collprovider, const char *collcollate)
 
size_t pg_strlower (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t pg_strtitle (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t pg_strupper (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t pg_strfold (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
int pg_strcoll (const char *arg1, const char *arg2, pg_locale_t locale)
 
int pg_strncoll (const char *arg1, ssize_t len1, const char *arg2, ssize_t len2, pg_locale_t locale)
 
bool pg_strxfrm_enabled (pg_locale_t locale)
 
size_t pg_strxfrm (char *dest, const char *src, size_t destsize, pg_locale_t locale)
 
size_t pg_strnxfrm (char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
bool pg_strxfrm_prefix_enabled (pg_locale_t locale)
 
size_t pg_strxfrm_prefix (char *dest, const char *src, size_t destsize, pg_locale_t locale)
 
size_t pg_strnxfrm_prefix (char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
int builtin_locale_encoding (const char *locale)
 
const char * builtin_validate_locale (int encoding, const char *locale)
 
char * icu_language_tag (const char *loc_str, int elevel)
 
void icu_validate_locale (const char *loc_str)
 

Variables

char * locale_messages
 
char * locale_monetary
 
char * locale_numeric
 
char * locale_time
 
int icu_validation_level = WARNING
 
char * localized_abbrev_days [7+1]
 
char * localized_full_days [7+1]
 
char * localized_abbrev_months [12+1]
 
char * localized_full_months [12+1]
 
bool database_ctype_is_c = false
 
static pg_locale_t default_locale = NULL
 
static bool CurrentLocaleConvValid = false
 
static bool CurrentLCTimeValid = false
 
static MemoryContext CollationCacheContext = NULL
 
static collation_cache_hash * CollationCache = NULL
 
static Oid last_collation_cache_oid = InvalidOid
 
static pg_locale_t last_collation_cache_locale = NULL
 

Macro Definition Documentation

◆ MAX_L10N_DATA

#define MAX_L10N_DATA   80

Definition at line 65 of file pg_locale.c.

◆ PGLOCALE_SUPPORT_ERROR

#define PGLOCALE_SUPPORT_ERROR (   provider)     elog(ERROR, "unsupported collprovider for %s: %c", __func__, provider)

Definition at line 56 of file pg_locale.c.

◆ SH_DECLARE

#define SH_DECLARE

Definition at line 157 of file pg_locale.c.

◆ SH_DEFINE

#define SH_DEFINE

Definition at line 158 of file pg_locale.c.

◆ SH_ELEMENT_TYPE

#define SH_ELEMENT_TYPE   collation_cache_entry

Definition at line 149 of file pg_locale.c.

◆ SH_EQUAL

#define SH_EQUAL (   tb,
  a,
  b 
)    (a == b)

Definition at line 153 of file pg_locale.c.

◆ SH_GET_HASH

#define SH_GET_HASH (   tb,
  a 
)    a->hash

Definition at line 154 of file pg_locale.c.

◆ SH_HASH_KEY

#define SH_HASH_KEY (   tb,
  key 
)    murmurhash32((uint32) key)

Definition at line 152 of file pg_locale.c.

◆ SH_KEY

#define SH_KEY   collid

Definition at line 151 of file pg_locale.c.

◆ SH_KEY_TYPE

#define SH_KEY_TYPE   Oid

Definition at line 150 of file pg_locale.c.

◆ SH_PREFIX

#define SH_PREFIX   collation_cache

Definition at line 148 of file pg_locale.c.

◆ SH_SCOPE

#define SH_SCOPE   static inline

Definition at line 155 of file pg_locale.c.

◆ SH_STORE_HASH

#define SH_STORE_HASH

Definition at line 156 of file pg_locale.c.

◆ TEXTBUFLEN

#define TEXTBUFLEN   1024

Definition at line 63 of file pg_locale.c.

Function Documentation

◆ assign_locale_messages()

void assign_locale_messages ( const char *  newval,
void *  extra 
)

Definition at line 427 of file pg_locale.c.

428{
429 /*
430 * LC_MESSAGES category does not exist everywhere, but accept it anyway.
431 * We ignore failure, as per comment above.
432 */
433#ifdef LC_MESSAGES
434 (void) pg_perm_setlocale(LC_MESSAGES, newval);
435#endif
436}
#define newval
char * pg_perm_setlocale(int category, const char *locale)
Definition: pg_locale.c:190

References newval, and pg_perm_setlocale().

◆ assign_locale_monetary()

void assign_locale_monetary ( const char *  newval,
void *  extra 
)

Definition at line 364 of file pg_locale.c.

365{
367}
static bool CurrentLocaleConvValid
Definition: pg_locale.c:133

References CurrentLocaleConvValid.

◆ assign_locale_numeric()

void assign_locale_numeric ( const char *  newval,
void *  extra 
)

Definition at line 376 of file pg_locale.c.

377{
379}

References CurrentLocaleConvValid.

◆ assign_locale_time()

void assign_locale_time ( const char *  newval,
void *  extra 
)

Definition at line 388 of file pg_locale.c.

389{
390 CurrentLCTimeValid = false;
391}
static bool CurrentLCTimeValid
Definition: pg_locale.c:134

References CurrentLCTimeValid.

◆ builtin_locale_encoding()

int builtin_locale_encoding ( const char *  locale)

Definition at line 1471 of file pg_locale.c.

1472{
1473 if (strcmp(locale, "C") == 0)
1474 return -1;
1475 else if (strcmp(locale, "C.UTF-8") == 0)
1476 return PG_UTF8;
1477 else if (strcmp(locale, "PG_UNICODE_FAST") == 0)
1478 return PG_UTF8;
1479
1480
1481 ereport(ERROR,
1482 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1483 errmsg("invalid locale name \"%s\" for builtin provider",
1484 locale)));
1485
1486 return 0; /* keep compiler quiet */
1487}
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
static char * locale
Definition: initdb.c:140
@ PG_UTF8
Definition: pg_wchar.h:232

References ereport, errcode(), errmsg(), ERROR, locale, and PG_UTF8.

Referenced by builtin_validate_locale(), and DefineCollation().

◆ builtin_validate_locale()

const char * builtin_validate_locale ( int  encoding,
const char *  locale 
)

Definition at line 1495 of file pg_locale.c.

1496{
1497 const char *canonical_name = NULL;
1498 int required_encoding;
1499
1500 if (strcmp(locale, "C") == 0)
1501 canonical_name = "C";
1502 else if (strcmp(locale, "C.UTF-8") == 0 || strcmp(locale, "C.UTF8") == 0)
1503 canonical_name = "C.UTF-8";
1504 else if (strcmp(locale, "PG_UNICODE_FAST") == 0)
1505 canonical_name = "PG_UNICODE_FAST";
1506
1507 if (!canonical_name)
1508 ereport(ERROR,
1509 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1510 errmsg("invalid locale name \"%s\" for builtin provider",
1511 locale)));
1512
1513 required_encoding = builtin_locale_encoding(canonical_name);
1514 if (required_encoding >= 0 && encoding != required_encoding)
1515 ereport(ERROR,
1516 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1517 errmsg("encoding \"%s\" does not match locale \"%s\"",
1519
1520 return canonical_name;
1521}
int32 encoding
Definition: pg_database.h:41
int builtin_locale_encoding(const char *locale)
Definition: pg_locale.c:1471
#define pg_encoding_to_char
Definition: pg_wchar.h:630

References builtin_locale_encoding(), encoding, ereport, errcode(), errmsg(), ERROR, locale, and pg_encoding_to_char.

Referenced by create_pg_locale_builtin(), createdb(), and DefineCollation().

◆ cache_locale_time()

void cache_locale_time ( void  )

Definition at line 720 of file pg_locale.c.

721{
722 char buf[(2 * 7 + 2 * 12) * MAX_L10N_DATA];
723 char *bufptr;
724 time_t timenow;
725 struct tm *timeinfo;
726 struct tm timeinfobuf;
727 bool strftimefail = false;
728 int encoding;
729 int i;
731
732 /* did we do this already? */
734 return;
735
736 elog(DEBUG3, "cache_locale_time() executed; locale: \"%s\"", locale_time);
737
738 errno = ENOENT;
739#ifdef WIN32
740 locale = _create_locale(LC_ALL, locale_time);
741 if (locale == (locale_t) 0)
742 _dosmaperr(GetLastError());
743#else
744 locale = newlocale(LC_ALL_MASK, locale_time, (locale_t) 0);
745#endif
746 if (!locale)
748
749 /* We use times close to current time as data for strftime(). */
750 timenow = time(NULL);
751 timeinfo = gmtime_r(&timenow, &timeinfobuf);
752
753 /* Store the strftime results in MAX_L10N_DATA-sized portions of buf[] */
754 bufptr = buf;
755
756 /*
757 * MAX_L10N_DATA is sufficient buffer space for every known locale, and
758 * POSIX defines no strftime() errors. (Buffer space exhaustion is not an
759 * error.) An implementation might report errors (e.g. ENOMEM) by
760 * returning 0 (or, less plausibly, a negative value) and setting errno.
761 * Report errno just in case the implementation did that, but clear it in
762 * advance of the calls so we don't emit a stale, unrelated errno.
763 */
764 errno = 0;
765
766 /* localized days */
767 for (i = 0; i < 7; i++)
768 {
769 timeinfo->tm_wday = i;
770 if (strftime_l(bufptr, MAX_L10N_DATA, "%a", timeinfo, locale) <= 0)
771 strftimefail = true;
772 bufptr += MAX_L10N_DATA;
773 if (strftime_l(bufptr, MAX_L10N_DATA, "%A", timeinfo, locale) <= 0)
774 strftimefail = true;
775 bufptr += MAX_L10N_DATA;
776 }
777
778 /* localized months */
779 for (i = 0; i < 12; i++)
780 {
781 timeinfo->tm_mon = i;
782 timeinfo->tm_mday = 1; /* make sure we don't have invalid date */
783 if (strftime_l(bufptr, MAX_L10N_DATA, "%b", timeinfo, locale) <= 0)
784 strftimefail = true;
785 bufptr += MAX_L10N_DATA;
786 if (strftime_l(bufptr, MAX_L10N_DATA, "%B", timeinfo, locale) <= 0)
787 strftimefail = true;
788 bufptr += MAX_L10N_DATA;
789 }
790
791#ifdef WIN32
792 _free_locale(locale);
793#else
794 freelocale(locale);
795#endif
796
797 /*
798 * At this point we've done our best to clean up, and can throw errors, or
799 * call functions that might throw errors, with a clean conscience.
800 */
801 if (strftimefail)
802 elog(ERROR, "strftime_l() failed");
803
804#ifndef WIN32
805
806 /*
807 * As in PGLC_localeconv(), we must convert strftime()'s output from the
808 * encoding implied by LC_TIME to the database encoding. If we can't
809 * identify the LC_TIME encoding, just perform encoding validation.
810 */
812 if (encoding < 0)
814
815#else
816
817 /*
818 * On Windows, strftime_win32() always returns UTF8 data, so convert from
819 * that if necessary.
820 */
822
823#endif /* WIN32 */
824
825 bufptr = buf;
826
827 /* localized days */
828 for (i = 0; i < 7; i++)
829 {
831 bufptr += MAX_L10N_DATA;
833 bufptr += MAX_L10N_DATA;
834 }
835 localized_abbrev_days[7] = NULL;
836 localized_full_days[7] = NULL;
837
838 /* localized months */
839 for (i = 0; i < 12; i++)
840 {
842 bufptr += MAX_L10N_DATA;
844 bufptr += MAX_L10N_DATA;
845 }
846 localized_abbrev_months[12] = NULL;
847 localized_full_months[12] = NULL;
848
849 CurrentLCTimeValid = true;
850}
#define DEBUG3
Definition: elog.h:28
#define elog(elevel,...)
Definition: elog.h:226
int i
Definition: isn.c:77
static struct pg_tm tm
Definition: localtime.c:104
char * localized_full_months[12+1]
Definition: pg_locale.c:125
char * locale_time
Definition: pg_locale.c:111
static void cache_single_string(char **dst, const char *src, int encoding)
Definition: pg_locale.c:697
#define MAX_L10N_DATA
Definition: pg_locale.c:65
char * localized_abbrev_months[12+1]
Definition: pg_locale.c:124
char * localized_full_days[7+1]
Definition: pg_locale.c:123
char * localized_abbrev_days[7+1]
Definition: pg_locale.c:122
void report_newlocale_failure(const char *localename)
static char * buf
Definition: pg_test_fsync.c:72
@ PG_SQL_ASCII
Definition: pg_wchar.h:226
int pg_get_encoding_from_locale(const char *ctype, bool write_message)
Definition: chklocale.c:301
#define locale_t
Definition: win32_port.h:432
void _dosmaperr(unsigned long)
Definition: win32error.c:177

References _dosmaperr(), buf, cache_single_string(), CurrentLCTimeValid, DEBUG3, elog, encoding, ERROR, i, locale, locale_t, locale_time, localized_abbrev_days, localized_abbrev_months, localized_full_days, localized_full_months, MAX_L10N_DATA, pg_get_encoding_from_locale(), PG_SQL_ASCII, PG_UTF8, report_newlocale_failure(), and tm.

Referenced by DCH_from_char(), and DCH_to_char().

◆ cache_single_string()

static void cache_single_string ( char **  dst,
const char *  src,
int  encoding 
)
static

Definition at line 697 of file pg_locale.c.

698{
699 char *ptr;
700 char *olddst;
701
702 /* Convert the string to the database encoding, or validate it's OK */
703 ptr = pg_any_to_server(src, strlen(src), encoding);
704
705 /* Store the string in long-lived storage, replacing any previous value */
706 olddst = *dst;
708 if (olddst)
709 pfree(olddst);
710
711 /* Might as well clean up any palloc'd conversion result, too */
712 if (ptr != src)
713 pfree(ptr);
714}
char * pg_any_to_server(const char *s, int len, int encoding)
Definition: mbutils.c:676
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:2308
void pfree(void *pointer)
Definition: mcxt.c:2146
MemoryContext TopMemoryContext
Definition: mcxt.c:165

References encoding, MemoryContextStrdup(), pfree(), pg_any_to_server(), and TopMemoryContext.

Referenced by cache_locale_time().

◆ check_locale()

bool check_locale ( int  category,
const char *  locale,
char **  canonname 
)

Definition at line 293 of file pg_locale.c.

294{
295 char *save;
296 char *res;
297
298 /* Don't let Windows' non-ASCII locale names in. */
299 if (!pg_is_ascii(locale))
300 {
302 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
303 errmsg("locale name \"%s\" contains non-ASCII characters",
304 locale)));
305 return false;
306 }
307
308 if (canonname)
309 *canonname = NULL; /* in case of failure */
310
311 save = setlocale(category, NULL);
312 if (!save)
313 return false; /* won't happen, we hope */
314
315 /* save may be pointing at a modifiable scratch variable, see above. */
316 save = pstrdup(save);
317
318 /* set the locale with setlocale, to see if it accepts it. */
319 res = setlocale(category, locale);
320
321 /* save canonical name if requested. */
322 if (res && canonname)
323 *canonname = pstrdup(res);
324
325 /* restore old value. */
326 if (!setlocale(category, save))
327 elog(WARNING, "failed to restore old locale \"%s\"", save);
328 pfree(save);
329
330 /* Don't let Windows' non-ASCII locale names out. */
331 if (canonname && *canonname && !pg_is_ascii(*canonname))
332 {
334 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
335 errmsg("locale name \"%s\" contains non-ASCII characters",
336 *canonname)));
337 pfree(*canonname);
338 *canonname = NULL;
339 return false;
340 }
341
342 return (res != NULL);
343}
#define WARNING
Definition: elog.h:36
char * pstrdup(const char *in)
Definition: mcxt.c:2321
bool pg_is_ascii(const char *str)
Definition: string.c:132
#define setlocale(a, b)
Definition: win32_port.h:475

References elog, ereport, errcode(), errmsg(), locale, pfree(), pg_is_ascii(), pstrdup(), setlocale, and WARNING.

Referenced by check_locale_messages(), check_locale_monetary(), check_locale_numeric(), check_locale_time(), and createdb().

◆ check_locale_messages()

bool check_locale_messages ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 404 of file pg_locale.c.

405{
406 if (**newval == '\0')
407 {
408 if (source == PGC_S_DEFAULT)
409 return true;
410 else
411 return false;
412 }
413
414 /*
415 * LC_MESSAGES category does not exist everywhere, but accept it anyway
416 *
417 * On Windows, we can't even check the value, so accept blindly
418 */
419#if defined(LC_MESSAGES) && !defined(WIN32)
420 return check_locale(LC_MESSAGES, *newval, NULL);
421#else
422 return true;
423#endif
424}
@ PGC_S_DEFAULT
Definition: guc.h:113
bool check_locale(int category, const char *locale, char **canonname)
Definition: pg_locale.c:293
static rewind_source * source
Definition: pg_rewind.c:89

References check_locale(), newval, PGC_S_DEFAULT, and source.

◆ check_locale_monetary()

bool check_locale_monetary ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 358 of file pg_locale.c.

359{
360 return check_locale(LC_MONETARY, *newval, NULL);
361}

References check_locale(), and newval.

◆ check_locale_numeric()

bool check_locale_numeric ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 370 of file pg_locale.c.

371{
372 return check_locale(LC_NUMERIC, *newval, NULL);
373}

References check_locale(), and newval.

◆ check_locale_time()

bool check_locale_time ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 382 of file pg_locale.c.

383{
384 return check_locale(LC_TIME, *newval, NULL);
385}

References check_locale(), and newval.

◆ create_pg_locale()

static pg_locale_t create_pg_locale ( Oid  collid,
MemoryContext  context 
)
static

Definition at line 1067 of file pg_locale.c.

1068{
1069 HeapTuple tp;
1070 Form_pg_collation collform;
1071 pg_locale_t result;
1072 Datum datum;
1073 bool isnull;
1074
1075 tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
1076 if (!HeapTupleIsValid(tp))
1077 elog(ERROR, "cache lookup failed for collation %u", collid);
1078 collform = (Form_pg_collation) GETSTRUCT(tp);
1079
1080 if (collform->collprovider == COLLPROVIDER_BUILTIN)
1081 result = create_pg_locale_builtin(collid, context);
1082 else if (collform->collprovider == COLLPROVIDER_ICU)
1083 result = create_pg_locale_icu(collid, context);
1084 else if (collform->collprovider == COLLPROVIDER_LIBC)
1085 result = create_pg_locale_libc(collid, context);
1086 else
1087 /* shouldn't happen */
1088 PGLOCALE_SUPPORT_ERROR(collform->collprovider);
1089
1090 result->is_default = false;
1091
1092 Assert((result->collate_is_c && result->collate == NULL) ||
1093 (!result->collate_is_c && result->collate != NULL));
1094
1095 datum = SysCacheGetAttr(COLLOID, tp, Anum_pg_collation_collversion,
1096 &isnull);
1097 if (!isnull)
1098 {
1099 char *actual_versionstr;
1100 char *collversionstr;
1101
1102 collversionstr = TextDatumGetCString(datum);
1103
1104 if (collform->collprovider == COLLPROVIDER_LIBC)
1105 datum = SysCacheGetAttrNotNull(COLLOID, tp, Anum_pg_collation_collcollate);
1106 else
1107 datum = SysCacheGetAttrNotNull(COLLOID, tp, Anum_pg_collation_colllocale);
1108
1109 actual_versionstr = get_collation_actual_version(collform->collprovider,
1110 TextDatumGetCString(datum));
1111 if (!actual_versionstr)
1112 {
1113 /*
1114 * This could happen when specifying a version in CREATE COLLATION
1115 * but the provider does not support versioning, or manually
1116 * creating a mess in the catalogs.
1117 */
1118 ereport(ERROR,
1119 (errmsg("collation \"%s\" has no actual version, but a version was recorded",
1120 NameStr(collform->collname))));
1121 }
1122
1123 if (strcmp(actual_versionstr, collversionstr) != 0)
1125 (errmsg("collation \"%s\" has version mismatch",
1126 NameStr(collform->collname)),
1127 errdetail("The collation in the database was created using version %s, "
1128 "but the operating system provides version %s.",
1129 collversionstr, actual_versionstr),
1130 errhint("Rebuild all objects affected by this collation and run "
1131 "ALTER COLLATION %s REFRESH VERSION, "
1132 "or build PostgreSQL with the right library version.",
1133 quote_qualified_identifier(get_namespace_name(collform->collnamespace),
1134 NameStr(collform->collname)))));
1135 }
1136
1137 ReleaseSysCache(tp);
1138
1139 return result;
1140}
#define TextDatumGetCString(d)
Definition: builtins.h:98
#define NameStr(name)
Definition: c.h:717
Oid collid
int errdetail(const char *fmt,...)
Definition: elog.c:1204
int errhint(const char *fmt,...)
Definition: elog.c:1318
Assert(PointerIsAligned(start, uint64))
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3506
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:58
pg_locale_t create_pg_locale_libc(Oid collid, MemoryContext context)
char * get_collation_actual_version(char collprovider, const char *collcollate)
Definition: pg_locale.c:1239
pg_locale_t create_pg_locale_builtin(Oid collid, MemoryContext context)
#define PGLOCALE_SUPPORT_ERROR(provider)
Definition: pg_locale.c:56
pg_locale_t create_pg_locale_icu(Oid collid, MemoryContext context)
uintptr_t Datum
Definition: postgres.h:69
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:13103
const struct collate_methods * collate
Definition: pg_locale.h:104
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:600
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition: syscache.c:631

References Assert(), pg_locale_struct::collate, pg_locale_struct::collate_is_c, collid, create_pg_locale_builtin(), create_pg_locale_icu(), create_pg_locale_libc(), elog, ereport, errdetail(), errhint(), errmsg(), ERROR, get_collation_actual_version(), get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, pg_locale_struct::is_default, NameStr, ObjectIdGetDatum(), PGLOCALE_SUPPORT_ERROR, quote_qualified_identifier(), ReleaseSysCache(), SearchSysCache1(), SysCacheGetAttr(), SysCacheGetAttrNotNull(), TextDatumGetCString, and WARNING.

Referenced by pg_newlocale_from_collation().

◆ create_pg_locale_builtin()

pg_locale_t create_pg_locale_builtin ( Oid  collid,
MemoryContext  context 
)

Definition at line 121 of file pg_locale_builtin.c.

122{
123 const char *locstr;
124 pg_locale_t result;
125
126 if (collid == DEFAULT_COLLATION_OID)
127 {
128 HeapTuple tp;
129 Datum datum;
130
132 if (!HeapTupleIsValid(tp))
133 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
134 datum = SysCacheGetAttrNotNull(DATABASEOID, tp,
135 Anum_pg_database_datlocale);
136 locstr = TextDatumGetCString(datum);
137 ReleaseSysCache(tp);
138 }
139 else
140 {
141 HeapTuple tp;
142 Datum datum;
143
145 if (!HeapTupleIsValid(tp))
146 elog(ERROR, "cache lookup failed for collation %u", collid);
147 datum = SysCacheGetAttrNotNull(COLLOID, tp,
148 Anum_pg_collation_colllocale);
149 locstr = TextDatumGetCString(datum);
150 ReleaseSysCache(tp);
151 }
152
154
155 result = MemoryContextAllocZero(context, sizeof(struct pg_locale_struct));
156
157 result->info.builtin.locale = MemoryContextStrdup(context, locstr);
158 result->info.builtin.casemap_full = (strcmp(locstr, "PG_UNICODE_FAST") == 0);
159 result->provider = COLLPROVIDER_BUILTIN;
160 result->deterministic = true;
161 result->collate_is_c = true;
162 result->ctype_is_c = (strcmp(locstr, "C") == 0);
163
164 return result;
165}
Oid MyDatabaseId
Definition: globals.c:95
int GetDatabaseEncoding(void)
Definition: mbutils.c:1261
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1290
const char * builtin_validate_locale(int encoding, const char *locale)
Definition: pg_locale.c:1495
struct pg_locale_struct::@161::@162 builtin
const char * locale
Definition: pg_locale.h:110
bool deterministic
Definition: pg_locale.h:99
union pg_locale_struct::@161 info

References pg_locale_struct::builtin, builtin_validate_locale(), pg_locale_struct::casemap_full, pg_locale_struct::collate_is_c, collid, pg_locale_struct::ctype_is_c, pg_locale_struct::deterministic, elog, ERROR, GetDatabaseEncoding(), HeapTupleIsValid, pg_locale_struct::info, pg_locale_struct::locale, MemoryContextAllocZero(), MemoryContextStrdup(), MyDatabaseId, ObjectIdGetDatum(), pg_locale_struct::provider, ReleaseSysCache(), SearchSysCache1(), SysCacheGetAttrNotNull(), and TextDatumGetCString.

Referenced by create_pg_locale(), and init_database_collation().

◆ create_pg_locale_icu()

pg_locale_t create_pg_locale_icu ( Oid  collid,
MemoryContext  context 
)

Definition at line 142 of file pg_locale_icu.c.

143{
144#ifdef USE_ICU
145 bool deterministic;
146 const char *iculocstr;
147 const char *icurules = NULL;
148 UCollator *collator;
149 pg_locale_t result;
150
151 if (collid == DEFAULT_COLLATION_OID)
152 {
153 HeapTuple tp;
154 Datum datum;
155 bool isnull;
156
158 if (!HeapTupleIsValid(tp))
159 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
160
161 /* default database collation is always deterministic */
162 deterministic = true;
163 datum = SysCacheGetAttrNotNull(DATABASEOID, tp,
164 Anum_pg_database_datlocale);
165 iculocstr = TextDatumGetCString(datum);
166 datum = SysCacheGetAttr(DATABASEOID, tp,
167 Anum_pg_database_daticurules, &isnull);
168 if (!isnull)
169 icurules = TextDatumGetCString(datum);
170
171 ReleaseSysCache(tp);
172 }
173 else
174 {
175 Form_pg_collation collform;
176 HeapTuple tp;
177 Datum datum;
178 bool isnull;
179
181 if (!HeapTupleIsValid(tp))
182 elog(ERROR, "cache lookup failed for collation %u", collid);
183 collform = (Form_pg_collation) GETSTRUCT(tp);
184 deterministic = collform->collisdeterministic;
185 datum = SysCacheGetAttrNotNull(COLLOID, tp,
186 Anum_pg_collation_colllocale);
187 iculocstr = TextDatumGetCString(datum);
188 datum = SysCacheGetAttr(COLLOID, tp,
189 Anum_pg_collation_collicurules, &isnull);
190 if (!isnull)
191 icurules = TextDatumGetCString(datum);
192
193 ReleaseSysCache(tp);
194 }
195
196 collator = make_icu_collator(iculocstr, icurules);
197
198 result = MemoryContextAllocZero(context, sizeof(struct pg_locale_struct));
199 result->info.icu.locale = MemoryContextStrdup(context, iculocstr);
200 result->info.icu.ucol = collator;
201 result->provider = COLLPROVIDER_ICU;
202 result->deterministic = deterministic;
203 result->collate_is_c = false;
204 result->ctype_is_c = false;
206 result->collate = &collate_methods_icu_utf8;
207 else
208 result->collate = &collate_methods_icu;
209
210 return result;
211#else
212 /* could get here if a collation was created by a build with ICU */
214 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
215 errmsg("ICU is not supported in this build")));
216
217 return NULL;
218#endif
219}

References pg_locale_struct::collate, pg_locale_struct::collate_is_c, collid, pg_locale_struct::ctype_is_c, pg_locale_struct::deterministic, elog, ereport, errcode(), errmsg(), ERROR, GetDatabaseEncoding(), GETSTRUCT(), HeapTupleIsValid, pg_locale_struct::info, pg_locale_struct::locale, MemoryContextAllocZero(), MemoryContextStrdup(), MyDatabaseId, ObjectIdGetDatum(), PG_UTF8, pg_locale_struct::provider, ReleaseSysCache(), SearchSysCache1(), SysCacheGetAttr(), SysCacheGetAttrNotNull(), and TextDatumGetCString.

Referenced by create_pg_locale(), and init_database_collation().

◆ create_pg_locale_libc()

pg_locale_t create_pg_locale_libc ( Oid  collid,
MemoryContext  context 
)

Definition at line 421 of file pg_locale_libc.c.

422{
423 const char *collate;
424 const char *ctype;
425 locale_t loc;
426 pg_locale_t result;
427
428 if (collid == DEFAULT_COLLATION_OID)
429 {
430 HeapTuple tp;
431 Datum datum;
432
434 if (!HeapTupleIsValid(tp))
435 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
436 datum = SysCacheGetAttrNotNull(DATABASEOID, tp,
437 Anum_pg_database_datcollate);
438 collate = TextDatumGetCString(datum);
439 datum = SysCacheGetAttrNotNull(DATABASEOID, tp,
440 Anum_pg_database_datctype);
441 ctype = TextDatumGetCString(datum);
442
443 ReleaseSysCache(tp);
444 }
445 else
446 {
447 HeapTuple tp;
448 Datum datum;
449
451 if (!HeapTupleIsValid(tp))
452 elog(ERROR, "cache lookup failed for collation %u", collid);
453
454 datum = SysCacheGetAttrNotNull(COLLOID, tp,
455 Anum_pg_collation_collcollate);
456 collate = TextDatumGetCString(datum);
457 datum = SysCacheGetAttrNotNull(COLLOID, tp,
458 Anum_pg_collation_collctype);
459 ctype = TextDatumGetCString(datum);
460
461 ReleaseSysCache(tp);
462 }
463
464
465 loc = make_libc_collator(collate, ctype);
466
467 result = MemoryContextAllocZero(context, sizeof(struct pg_locale_struct));
468 result->provider = COLLPROVIDER_LIBC;
469 result->deterministic = true;
470 result->collate_is_c = (strcmp(collate, "C") == 0) ||
471 (strcmp(collate, "POSIX") == 0);
472 result->ctype_is_c = (strcmp(ctype, "C") == 0) ||
473 (strcmp(ctype, "POSIX") == 0);
474 result->info.lt = loc;
475 if (!result->collate_is_c)
476 {
477#ifdef WIN32
479 result->collate = &collate_methods_libc_win32_utf8;
480 else
481#endif
482 result->collate = &collate_methods_libc;
483 }
484
485 return result;
486}
static locale_t make_libc_collator(const char *collate, const char *ctype)
static const struct collate_methods collate_methods_libc

References pg_locale_struct::collate, pg_locale_struct::collate_is_c, collate_methods_libc, collid, pg_locale_struct::ctype_is_c, pg_locale_struct::deterministic, elog, ERROR, GetDatabaseEncoding(), HeapTupleIsValid, pg_locale_struct::info, locale_t, pg_locale_struct::lt, make_libc_collator(), MemoryContextAllocZero(), MyDatabaseId, ObjectIdGetDatum(), PG_UTF8, pg_locale_struct::provider, ReleaseSysCache(), SearchSysCache1(), SysCacheGetAttrNotNull(), and TextDatumGetCString.

Referenced by create_pg_locale(), and init_database_collation().

◆ db_encoding_convert()

static void db_encoding_convert ( int  encoding,
char **  str 
)
static

Definition at line 494 of file pg_locale.c.

495{
496 char *pstr;
497 char *mstr;
498
499 /* convert the string to the database encoding */
500 pstr = pg_any_to_server(*str, strlen(*str), encoding);
501 if (pstr == *str)
502 return; /* no conversion happened */
503
504 /* need it malloc'd not palloc'd */
505 mstr = strdup(pstr);
506 if (mstr == NULL)
508 (errcode(ERRCODE_OUT_OF_MEMORY),
509 errmsg("out of memory")));
510
511 /* replace old string */
512 free(*str);
513 *str = mstr;
514
515 pfree(pstr);
516}
const char * str
#define free(a)
Definition: header.h:65

References encoding, ereport, errcode(), errmsg(), ERROR, free, pfree(), pg_any_to_server(), and str.

Referenced by PGLC_localeconv().

◆ free_struct_lconv()

static void free_struct_lconv ( struct lconv *  s)
static

Definition at line 444 of file pg_locale.c.

445{
446 free(s->decimal_point);
447 free(s->thousands_sep);
448 free(s->grouping);
449 free(s->int_curr_symbol);
450 free(s->currency_symbol);
451 free(s->mon_decimal_point);
452 free(s->mon_thousands_sep);
453 free(s->mon_grouping);
454 free(s->positive_sign);
455 free(s->negative_sign);
456}

References free.

Referenced by PGLC_localeconv().

◆ get_collation_actual_version()

char * get_collation_actual_version ( char  collprovider,
const char *  collcollate 
)

Definition at line 1239 of file pg_locale.c.

1240{
1241 char *collversion = NULL;
1242
1243 if (collprovider == COLLPROVIDER_BUILTIN)
1244 collversion = get_collation_actual_version_builtin(collcollate);
1245#ifdef USE_ICU
1246 else if (collprovider == COLLPROVIDER_ICU)
1247 collversion = get_collation_actual_version_icu(collcollate);
1248#endif
1249 else if (collprovider == COLLPROVIDER_LIBC)
1250 collversion = get_collation_actual_version_libc(collcollate);
1251
1252 return collversion;
1253}
char * get_collation_actual_version_libc(const char *collcollate)
char * get_collation_actual_version_builtin(const char *collcollate)

References get_collation_actual_version_builtin(), and get_collation_actual_version_libc().

Referenced by AlterCollation(), AlterDatabaseRefreshColl(), CheckMyDatabase(), create_pg_locale(), createdb(), DefineCollation(), pg_collation_actual_version(), pg_database_collation_actual_version(), and pg_import_system_collations().

◆ get_collation_actual_version_builtin()

char * get_collation_actual_version_builtin ( const char *  collcollate)

Definition at line 168 of file pg_locale_builtin.c.

169{
170 /*
171 * The only two supported locales (C and C.UTF-8) are both based on memcmp
172 * and are not expected to change, but track the version anyway.
173 *
174 * Note that the character semantics may change for some locales, but the
175 * collation version only tracks changes to sort order.
176 */
177 if (strcmp(collcollate, "C") == 0)
178 return "1";
179 else if (strcmp(collcollate, "C.UTF-8") == 0)
180 return "1";
181 else if (strcmp(collcollate, "PG_UNICODE_FAST") == 0)
182 return "1";
183 else
185 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
186 errmsg("invalid locale name \"%s\" for builtin provider",
187 collcollate)));
188
189 return NULL; /* keep compiler quiet */
190}

References ereport, errcode(), errmsg(), and ERROR.

Referenced by get_collation_actual_version().

◆ get_collation_actual_version_libc()

char * get_collation_actual_version_libc ( const char *  collcollate)

Definition at line 659 of file pg_locale_libc.c.

660{
661 char *collversion = NULL;
662
663 if (pg_strcasecmp("C", collcollate) != 0 &&
664 pg_strncasecmp("C.", collcollate, 2) != 0 &&
665 pg_strcasecmp("POSIX", collcollate) != 0)
666 {
667#if defined(__GLIBC__)
668 /* Use the glibc version because we don't have anything better. */
669 collversion = pstrdup(gnu_get_libc_version());
670#elif defined(LC_VERSION_MASK)
671 locale_t loc;
672
673 /* Look up FreeBSD collation version. */
674 loc = newlocale(LC_COLLATE_MASK, collcollate, NULL);
675 if (loc)
676 {
677 collversion =
678 pstrdup(querylocale(LC_COLLATE_MASK | LC_VERSION_MASK, loc));
679 freelocale(loc);
680 }
681 else
683 (errmsg("could not load locale \"%s\"", collcollate)));
684#elif defined(WIN32)
685 /*
686 * If we are targeting Windows Vista and above, we can ask for a name
687 * given a collation name (earlier versions required a location code
688 * that we don't have).
689 */
690 NLSVERSIONINFOEX version = {sizeof(NLSVERSIONINFOEX)};
691 WCHAR wide_collcollate[LOCALE_NAME_MAX_LENGTH];
692
693 MultiByteToWideChar(CP_ACP, 0, collcollate, -1, wide_collcollate,
694 LOCALE_NAME_MAX_LENGTH);
695 if (!GetNLSVersionEx(COMPARE_STRING, wide_collcollate, &version))
696 {
697 /*
698 * GetNLSVersionEx() wants a language tag such as "en-US", not a
699 * locale name like "English_United States.1252". Until those
700 * values can be prevented from entering the system, or 100%
701 * reliably converted to the more useful tag format, tolerate the
702 * resulting error and report that we have no version data.
703 */
704 if (GetLastError() == ERROR_INVALID_PARAMETER)
705 return NULL;
706
708 (errmsg("could not get collation version for locale \"%s\": error code %lu",
709 collcollate,
710 GetLastError())));
711 }
712 collversion = psprintf("%lu.%lu,%lu.%lu",
713 (version.dwNLSVersion >> 8) & 0xFFFF,
714 version.dwNLSVersion & 0xFF,
715 (version.dwDefinedVersion >> 8) & 0xFFFF,
716 version.dwDefinedVersion & 0xFF);
717#endif
718 }
719
720 return collversion;
721}
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43

References ereport, errmsg(), ERROR, locale_t, pg_strcasecmp(), pg_strncasecmp(), psprintf(), and pstrdup().

Referenced by get_collation_actual_version().

◆ icu_language_tag()

char * icu_language_tag ( const char *  loc_str,
int  elevel 
)

Definition at line 1535 of file pg_locale.c.

1536{
1537#ifdef USE_ICU
1538 UErrorCode status;
1539 char *langtag;
1540 size_t buflen = 32; /* arbitrary starting buffer size */
1541 const bool strict = true;
1542
1543 /*
1544 * A BCP47 language tag doesn't have a clearly-defined upper limit (cf.
1545 * RFC5646 section 4.4). Additionally, in older ICU versions,
1546 * uloc_toLanguageTag() doesn't always return the ultimate length on the
1547 * first call, necessitating a loop.
1548 */
1549 langtag = palloc(buflen);
1550 while (true)
1551 {
1552 status = U_ZERO_ERROR;
1553 uloc_toLanguageTag(loc_str, langtag, buflen, strict, &status);
1554
1555 /* try again if the buffer is not large enough */
1556 if ((status == U_BUFFER_OVERFLOW_ERROR ||
1557 status == U_STRING_NOT_TERMINATED_WARNING) &&
1558 buflen < MaxAllocSize)
1559 {
1560 buflen = Min(buflen * 2, MaxAllocSize);
1561 langtag = repalloc(langtag, buflen);
1562 continue;
1563 }
1564
1565 break;
1566 }
1567
1568 if (U_FAILURE(status))
1569 {
1570 pfree(langtag);
1571
1572 if (elevel > 0)
1573 ereport(elevel,
1574 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1575 errmsg("could not convert locale name \"%s\" to language tag: %s",
1576 loc_str, u_errorName(status))));
1577 return NULL;
1578 }
1579
1580 return langtag;
1581#else /* not USE_ICU */
1582 ereport(ERROR,
1583 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1584 errmsg("ICU is not supported in this build")));
1585 return NULL; /* keep compiler quiet */
1586#endif /* not USE_ICU */
1587}
#define Min(x, y)
Definition: c.h:975
#define MaxAllocSize
Definition: fe_memutils.h:22
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:2166
void * palloc(Size size)
Definition: mcxt.c:1939

References ereport, errcode(), errmsg(), ERROR, MaxAllocSize, Min, palloc(), pfree(), and repalloc().

Referenced by createdb(), DefineCollation(), and pg_import_system_collations().

◆ icu_validate_locale()

void icu_validate_locale ( const char *  loc_str)

Definition at line 1593 of file pg_locale.c.

1594{
1595#ifdef USE_ICU
1596 UCollator *collator;
1597 UErrorCode status;
1598 char lang[ULOC_LANG_CAPACITY];
1599 bool found = false;
1600 int elevel = icu_validation_level;
1601
1602 /* no validation */
1603 if (elevel < 0)
1604 return;
1605
1606 /* downgrade to WARNING during pg_upgrade */
1607 if (IsBinaryUpgrade && elevel > WARNING)
1608 elevel = WARNING;
1609
1610 /* validate that we can extract the language */
1611 status = U_ZERO_ERROR;
1612 uloc_getLanguage(loc_str, lang, ULOC_LANG_CAPACITY, &status);
1613 if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING)
1614 {
1615 ereport(elevel,
1616 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1617 errmsg("could not get language from ICU locale \"%s\": %s",
1618 loc_str, u_errorName(status)),
1619 errhint("To disable ICU locale validation, set the parameter \"%s\" to \"%s\".",
1620 "icu_validation_level", "disabled")));
1621 return;
1622 }
1623
1624 /* check for special language name */
1625 if (strcmp(lang, "") == 0 ||
1626 strcmp(lang, "root") == 0 || strcmp(lang, "und") == 0)
1627 found = true;
1628
1629 /* search for matching language within ICU */
1630 for (int32_t i = 0; !found && i < uloc_countAvailable(); i++)
1631 {
1632 const char *otherloc = uloc_getAvailable(i);
1633 char otherlang[ULOC_LANG_CAPACITY];
1634
1635 status = U_ZERO_ERROR;
1636 uloc_getLanguage(otherloc, otherlang, ULOC_LANG_CAPACITY, &status);
1637 if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING)
1638 continue;
1639
1640 if (strcmp(lang, otherlang) == 0)
1641 found = true;
1642 }
1643
1644 if (!found)
1645 ereport(elevel,
1646 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1647 errmsg("ICU locale \"%s\" has unknown language \"%s\"",
1648 loc_str, lang),
1649 errhint("To disable ICU locale validation, set the parameter \"%s\" to \"%s\".",
1650 "icu_validation_level", "disabled")));
1651
1652 /* check that it can be opened */
1653 collator = pg_ucol_open(loc_str);
1654 ucol_close(collator);
1655#else /* not USE_ICU */
1656 /* could get here if a collation was created by a build with ICU */
1657 ereport(ERROR,
1658 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1659 errmsg("ICU is not supported in this build")));
1660#endif /* not USE_ICU */
1661}
bool IsBinaryUpgrade
Definition: globals.c:122
int icu_validation_level
Definition: pg_locale.c:113

References ereport, errcode(), errhint(), errmsg(), ERROR, i, icu_validation_level, IsBinaryUpgrade, and WARNING.

Referenced by createdb(), and DefineCollation().

◆ init_database_collation()

void init_database_collation ( void  )

Definition at line 1146 of file pg_locale.c.

1147{
1148 HeapTuple tup;
1149 Form_pg_database dbform;
1150 pg_locale_t result;
1151
1152 Assert(default_locale == NULL);
1153
1154 /* Fetch our pg_database row normally, via syscache */
1155 tup = SearchSysCache1(DATABASEOID, ObjectIdGetDatum(MyDatabaseId));
1156 if (!HeapTupleIsValid(tup))
1157 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
1158 dbform = (Form_pg_database) GETSTRUCT(tup);
1159
1160 if (dbform->datlocprovider == COLLPROVIDER_BUILTIN)
1161 result = create_pg_locale_builtin(DEFAULT_COLLATION_OID,
1163 else if (dbform->datlocprovider == COLLPROVIDER_ICU)
1164 result = create_pg_locale_icu(DEFAULT_COLLATION_OID,
1166 else if (dbform->datlocprovider == COLLPROVIDER_LIBC)
1167 result = create_pg_locale_libc(DEFAULT_COLLATION_OID,
1169 else
1170 /* shouldn't happen */
1171 PGLOCALE_SUPPORT_ERROR(dbform->datlocprovider);
1172
1173 result->is_default = true;
1174 ReleaseSysCache(tup);
1175
1176 default_locale = result;
1177}
FormData_pg_database * Form_pg_database
Definition: pg_database.h:96
static pg_locale_t default_locale
Definition: pg_locale.c:130

References Assert(), create_pg_locale_builtin(), create_pg_locale_icu(), create_pg_locale_libc(), default_locale, elog, ERROR, GETSTRUCT(), HeapTupleIsValid, pg_locale_struct::is_default, MyDatabaseId, ObjectIdGetDatum(), PGLOCALE_SUPPORT_ERROR, ReleaseSysCache(), SearchSysCache1(), and TopMemoryContext.

Referenced by CheckMyDatabase().

◆ pg_newlocale_from_collation()

pg_locale_t pg_newlocale_from_collation ( Oid  collid)

Definition at line 1188 of file pg_locale.c.

1189{
1190 collation_cache_entry *cache_entry;
1191 bool found;
1192
1193 if (collid == DEFAULT_COLLATION_OID)
1194 return default_locale;
1195
1196 if (!OidIsValid(collid))
1197 elog(ERROR, "cache lookup failed for collation %u", collid);
1198
1200
1203
1204 if (CollationCache == NULL)
1205 {
1207 "collation cache",
1209 CollationCache = collation_cache_create(CollationCacheContext,
1210 16, NULL);
1211 }
1212
1213 cache_entry = collation_cache_insert(CollationCache, collid, &found);
1214 if (!found)
1215 {
1216 /*
1217 * Make sure cache entry is marked invalid, in case we fail before
1218 * setting things.
1219 */
1220 cache_entry->locale = 0;
1221 }
1222
1223 if (cache_entry->locale == 0)
1224 {
1226 }
1227
1229 last_collation_cache_locale = cache_entry->locale;
1230
1231 return cache_entry->locale;
1232}
#define OidIsValid(objectId)
Definition: c.h:746
#define AllocSetContextCreate
Definition: memutils.h:149
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:180
static pg_locale_t last_collation_cache_locale
Definition: pg_locale.c:169
static pg_locale_t create_pg_locale(Oid collid, MemoryContext context)
Definition: pg_locale.c:1067
static MemoryContext CollationCacheContext
Definition: pg_locale.c:161
static collation_cache_hash * CollationCache
Definition: pg_locale.c:162
static Oid last_collation_cache_oid
Definition: pg_locale.c:168
static void AssertCouldGetRelation(void)
Definition: relcache.h:44
Definition: pg_locale.c:139
pg_locale_t locale
Definition: pg_locale.c:141

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, AssertCouldGetRelation(), CollationCache, CollationCacheContext, collid, create_pg_locale(), default_locale, elog, ERROR, last_collation_cache_locale, last_collation_cache_oid, collation_cache_entry::locale, OidIsValid, and TopMemoryContext.

Referenced by bpchareq(), bpcharne(), btvarstrequalimage(), convert_string_datum(), DefineCollation(), Generic_Text_IC_like(), GenericMatchText(), hashbpchar(), hashbpcharextended(), hashtext(), hashtextextended(), like_fixed_prefix(), make_greater_string(), match_pattern_prefix(), pg_set_regex_collation(), spg_text_inner_consistent(), str_casefold(), str_initcap(), str_tolower(), str_toupper(), text_position(), text_position_setup(), text_starts_with(), texteq(), textne(), varstr_cmp(), and varstr_sortsupport().

◆ pg_perm_setlocale()

char * pg_perm_setlocale ( int  category,
const char *  locale 
)

Definition at line 190 of file pg_locale.c.

191{
192 char *result;
193 const char *envvar;
194
195#ifndef WIN32
196 result = setlocale(category, locale);
197#else
198
199 /*
200 * On Windows, setlocale(LC_MESSAGES) does not work, so just assume that
201 * the given value is good and set it in the environment variables. We
202 * must ignore attempts to set to "", which means "keep using the old
203 * environment value".
204 */
205#ifdef LC_MESSAGES
206 if (category == LC_MESSAGES)
207 {
208 result = (char *) locale;
209 if (locale == NULL || locale[0] == '\0')
210 return result;
211 }
212 else
213#endif
214 result = setlocale(category, locale);
215#endif /* WIN32 */
216
217 if (result == NULL)
218 return result; /* fall out immediately on failure */
219
220 /*
221 * Use the right encoding in translated messages. Under ENABLE_NLS, let
222 * pg_bind_textdomain_codeset() figure it out. Under !ENABLE_NLS, message
223 * format strings are ASCII, but database-encoding strings may enter the
224 * message via %s. This makes the overall message encoding equal to the
225 * database encoding.
226 */
227 if (category == LC_CTYPE)
228 {
229 static char save_lc_ctype[LOCALE_NAME_BUFLEN];
230
231 /* copy setlocale() return value before callee invokes it again */
232 strlcpy(save_lc_ctype, result, sizeof(save_lc_ctype));
233 result = save_lc_ctype;
234
235#ifdef ENABLE_NLS
236 SetMessageEncoding(pg_bind_textdomain_codeset(textdomain(NULL)));
237#else
239#endif
240 }
241
242 switch (category)
243 {
244 case LC_COLLATE:
245 envvar = "LC_COLLATE";
246 break;
247 case LC_CTYPE:
248 envvar = "LC_CTYPE";
249 break;
250#ifdef LC_MESSAGES
251 case LC_MESSAGES:
252 envvar = "LC_MESSAGES";
253#ifdef WIN32
254 result = IsoLocaleName(locale);
255 if (result == NULL)
256 result = (char *) locale;
257 elog(DEBUG3, "IsoLocaleName() executed; locale: \"%s\"", result);
258#endif /* WIN32 */
259 break;
260#endif /* LC_MESSAGES */
261 case LC_MONETARY:
262 envvar = "LC_MONETARY";
263 break;
264 case LC_NUMERIC:
265 envvar = "LC_NUMERIC";
266 break;
267 case LC_TIME:
268 envvar = "LC_TIME";
269 break;
270 default:
271 elog(FATAL, "unrecognized LC category: %d", category);
272 return NULL; /* keep compiler quiet */
273 }
274
275 if (setenv(envvar, result, 1) != 0)
276 return NULL;
277
278 return result;
279}
#define FATAL
Definition: elog.h:41
void SetMessageEncoding(int encoding)
Definition: mbutils.c:1171
#define LOCALE_NAME_BUFLEN
Definition: pg_locale.h:20
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define setenv(x, y, z)
Definition: win32_port.h:545

References DEBUG3, elog, FATAL, GetDatabaseEncoding(), locale, LOCALE_NAME_BUFLEN, setenv, setlocale, SetMessageEncoding(), and strlcpy().

Referenced by assign_locale_messages(), CheckMyDatabase(), and init_locale().

◆ pg_strcoll()

int pg_strcoll ( const char *  arg1,
const char *  arg2,
pg_locale_t  locale 
)

Definition at line 1338 of file pg_locale.c.

1339{
1340 return locale->collate->strncoll(arg1, -1, arg2, -1, locale);
1341}

References locale.

Referenced by varstrfastcmp_locale().

◆ pg_strfold()

size_t pg_strfold ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 1313 of file pg_locale.c.

1315{
1316 if (locale->provider == COLLPROVIDER_BUILTIN)
1317 return strfold_builtin(dst, dstsize, src, srclen, locale);
1318#ifdef USE_ICU
1319 else if (locale->provider == COLLPROVIDER_ICU)
1320 return strfold_icu(dst, dstsize, src, srclen, locale);
1321#endif
1322 /* for libc, just use strlower */
1323 else if (locale->provider == COLLPROVIDER_LIBC)
1324 return strlower_libc(dst, dstsize, src, srclen, locale);
1325 else
1326 /* shouldn't happen */
1327 PGLOCALE_SUPPORT_ERROR(locale->provider);
1328
1329 return 0; /* keep compiler quiet */
1330}
size_t strfold_icu(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strlower_libc(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strfold_builtin(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)

References locale, PGLOCALE_SUPPORT_ERROR, strfold_builtin(), strfold_icu(), and strlower_libc().

Referenced by str_casefold().

◆ pg_strlower()

size_t pg_strlower ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 1256 of file pg_locale.c.

1258{
1259 if (locale->provider == COLLPROVIDER_BUILTIN)
1260 return strlower_builtin(dst, dstsize, src, srclen, locale);
1261#ifdef USE_ICU
1262 else if (locale->provider == COLLPROVIDER_ICU)
1263 return strlower_icu(dst, dstsize, src, srclen, locale);
1264#endif
1265 else if (locale->provider == COLLPROVIDER_LIBC)
1266 return strlower_libc(dst, dstsize, src, srclen, locale);
1267 else
1268 /* shouldn't happen */
1269 PGLOCALE_SUPPORT_ERROR(locale->provider);
1270
1271 return 0; /* keep compiler quiet */
1272}
size_t strlower_icu(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strlower_builtin(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)

References locale, PGLOCALE_SUPPORT_ERROR, strlower_builtin(), strlower_icu(), and strlower_libc().

Referenced by str_tolower().

◆ pg_strncoll()

int pg_strncoll ( const char *  arg1,
ssize_t  len1,
const char *  arg2,
ssize_t  len2,
pg_locale_t  locale 
)

Definition at line 1358 of file pg_locale.c.

1360{
1361 return locale->collate->strncoll(arg1, len1, arg2, len2, locale);
1362}

References locale.

Referenced by MatchText(), text_position_next_internal(), and varstr_cmp().

◆ pg_strnxfrm()

size_t pg_strnxfrm ( char *  dest,
size_t  destsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 1413 of file pg_locale.c.

1415{
1416 return locale->collate->strnxfrm(dest, destsize, src, srclen, locale);
1417}

References generate_unaccent_rules::dest, and locale.

Referenced by hashbpchar(), hashbpcharextended(), hashtext(), and hashtextextended().

◆ pg_strnxfrm_prefix()

size_t pg_strnxfrm_prefix ( char *  dest,
size_t  destsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 1460 of file pg_locale.c.

1462{
1463 return locale->collate->strnxfrm_prefix(dest, destsize, src, srclen, locale);
1464}

References generate_unaccent_rules::dest, and locale.

◆ pg_strtitle()

size_t pg_strtitle ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 1275 of file pg_locale.c.

1277{
1278 if (locale->provider == COLLPROVIDER_BUILTIN)
1279 return strtitle_builtin(dst, dstsize, src, srclen, locale);
1280#ifdef USE_ICU
1281 else if (locale->provider == COLLPROVIDER_ICU)
1282 return strtitle_icu(dst, dstsize, src, srclen, locale);
1283#endif
1284 else if (locale->provider == COLLPROVIDER_LIBC)
1285 return strtitle_libc(dst, dstsize, src, srclen, locale);
1286 else
1287 /* shouldn't happen */
1288 PGLOCALE_SUPPORT_ERROR(locale->provider);
1289
1290 return 0; /* keep compiler quiet */
1291}
size_t strtitle_libc(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strtitle_icu(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strtitle_builtin(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)

References locale, PGLOCALE_SUPPORT_ERROR, strtitle_builtin(), strtitle_icu(), and strtitle_libc().

Referenced by str_initcap().

◆ pg_strupper()

size_t pg_strupper ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 1294 of file pg_locale.c.

1296{
1297 if (locale->provider == COLLPROVIDER_BUILTIN)
1298 return strupper_builtin(dst, dstsize, src, srclen, locale);
1299#ifdef USE_ICU
1300 else if (locale->provider == COLLPROVIDER_ICU)
1301 return strupper_icu(dst, dstsize, src, srclen, locale);
1302#endif
1303 else if (locale->provider == COLLPROVIDER_LIBC)
1304 return strupper_libc(dst, dstsize, src, srclen, locale);
1305 else
1306 /* shouldn't happen */
1307 PGLOCALE_SUPPORT_ERROR(locale->provider);
1308
1309 return 0; /* keep compiler quiet */
1310}
size_t strupper_icu(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strupper_libc(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strupper_builtin(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)

References locale, PGLOCALE_SUPPORT_ERROR, strupper_builtin(), strupper_icu(), and strupper_libc().

Referenced by str_toupper().

◆ pg_strxfrm()

size_t pg_strxfrm ( char *  dest,
const char *  src,
size_t  destsize,
pg_locale_t  locale 
)

Definition at line 1388 of file pg_locale.c.

1389{
1390 return locale->collate->strnxfrm(dest, destsize, src, -1, locale);
1391}

References generate_unaccent_rules::dest, and locale.

Referenced by convert_string_datum(), and varstr_abbrev_convert().

◆ pg_strxfrm_enabled()

bool pg_strxfrm_enabled ( pg_locale_t  locale)

Definition at line 1372 of file pg_locale.c.

1373{
1374 /*
1375 * locale->collate->strnxfrm is still a required method, even if it may
1376 * have the wrong behavior, because the planner uses it for estimates in
1377 * some cases.
1378 */
1379 return locale->collate->strxfrm_is_safe;
1380}

References locale.

Referenced by varstr_sortsupport().

◆ pg_strxfrm_prefix()

size_t pg_strxfrm_prefix ( char *  dest,
const char *  src,
size_t  destsize,
pg_locale_t  locale 
)

Definition at line 1435 of file pg_locale.c.

1437{
1438 return locale->collate->strnxfrm_prefix(dest, destsize, src, -1, locale);
1439}

References generate_unaccent_rules::dest, and locale.

Referenced by varstr_abbrev_convert().

◆ pg_strxfrm_prefix_enabled()

bool pg_strxfrm_prefix_enabled ( pg_locale_t  locale)

Definition at line 1424 of file pg_locale.c.

1425{
1426 return (locale->collate->strnxfrm_prefix != NULL);
1427}

References locale.

Referenced by varstr_abbrev_convert().

◆ PGLC_localeconv()

struct lconv * PGLC_localeconv ( void  )

Definition at line 524 of file pg_locale.c.

525{
526 static struct lconv CurrentLocaleConv;
527 static bool CurrentLocaleConvAllocated = false;
528 struct lconv *extlconv;
529 struct lconv tmp;
530 struct lconv worklconv = {0};
531
532 /* Did we do it already? */
534 return &CurrentLocaleConv;
535
536 /* Free any already-allocated storage */
537 if (CurrentLocaleConvAllocated)
538 {
539 free_struct_lconv(&CurrentLocaleConv);
540 CurrentLocaleConvAllocated = false;
541 }
542
543 /*
544 * Use thread-safe method of obtaining a copy of lconv from the operating
545 * system.
546 */
549 &tmp) != 0)
550 elog(ERROR,
551 "could not get lconv for LC_MONETARY = \"%s\", LC_NUMERIC = \"%s\": %m",
553
554 /* Must copy data now now so we can re-encode it. */
555 extlconv = &tmp;
556 worklconv.decimal_point = strdup(extlconv->decimal_point);
557 worklconv.thousands_sep = strdup(extlconv->thousands_sep);
558 worklconv.grouping = strdup(extlconv->grouping);
559 worklconv.int_curr_symbol = strdup(extlconv->int_curr_symbol);
560 worklconv.currency_symbol = strdup(extlconv->currency_symbol);
561 worklconv.mon_decimal_point = strdup(extlconv->mon_decimal_point);
562 worklconv.mon_thousands_sep = strdup(extlconv->mon_thousands_sep);
563 worklconv.mon_grouping = strdup(extlconv->mon_grouping);
564 worklconv.positive_sign = strdup(extlconv->positive_sign);
565 worklconv.negative_sign = strdup(extlconv->negative_sign);
566 /* Copy scalar fields as well */
567 worklconv.int_frac_digits = extlconv->int_frac_digits;
568 worklconv.frac_digits = extlconv->frac_digits;
569 worklconv.p_cs_precedes = extlconv->p_cs_precedes;
570 worklconv.p_sep_by_space = extlconv->p_sep_by_space;
571 worklconv.n_cs_precedes = extlconv->n_cs_precedes;
572 worklconv.n_sep_by_space = extlconv->n_sep_by_space;
573 worklconv.p_sign_posn = extlconv->p_sign_posn;
574 worklconv.n_sign_posn = extlconv->n_sign_posn;
575
576 /* Free the contents of the object populated by pg_localeconv_r(). */
577 pg_localeconv_free(&tmp);
578
579 /* If any of the preceding strdup calls failed, complain now. */
580 if (!struct_lconv_is_valid(&worklconv))
582 (errcode(ERRCODE_OUT_OF_MEMORY),
583 errmsg("out of memory")));
584
585 PG_TRY();
586 {
587 int encoding;
588
589 /*
590 * Now we must perform encoding conversion from whatever's associated
591 * with the locales into the database encoding. If we can't identify
592 * the encoding implied by LC_NUMERIC or LC_MONETARY (ie we get -1),
593 * use PG_SQL_ASCII, which will result in just validating that the
594 * strings are OK in the database encoding.
595 */
597 if (encoding < 0)
599
600 db_encoding_convert(encoding, &worklconv.decimal_point);
601 db_encoding_convert(encoding, &worklconv.thousands_sep);
602 /* grouping is not text and does not require conversion */
603
605 if (encoding < 0)
607
608 db_encoding_convert(encoding, &worklconv.int_curr_symbol);
609 db_encoding_convert(encoding, &worklconv.currency_symbol);
610 db_encoding_convert(encoding, &worklconv.mon_decimal_point);
611 db_encoding_convert(encoding, &worklconv.mon_thousands_sep);
612 /* mon_grouping is not text and does not require conversion */
613 db_encoding_convert(encoding, &worklconv.positive_sign);
614 db_encoding_convert(encoding, &worklconv.negative_sign);
615 }
616 PG_CATCH();
617 {
618 free_struct_lconv(&worklconv);
619 PG_RE_THROW();
620 }
621 PG_END_TRY();
622
623 /*
624 * Everything is good, so save the results.
625 */
626 CurrentLocaleConv = worklconv;
627 CurrentLocaleConvAllocated = true;
629 return &CurrentLocaleConv;
630}
#define PG_RE_THROW()
Definition: elog.h:405
#define PG_TRY(...)
Definition: elog.h:372
#define PG_END_TRY(...)
Definition: elog.h:397
#define PG_CATCH(...)
Definition: elog.h:382
char * locale_numeric
Definition: pg_locale.c:110
static void db_encoding_convert(int encoding, char **str)
Definition: pg_locale.c:494
static void free_struct_lconv(struct lconv *s)
Definition: pg_locale.c:444
static bool struct_lconv_is_valid(struct lconv *s)
Definition: pg_locale.c:463
char * locale_monetary
Definition: pg_locale.c:109
int pg_localeconv_r(const char *lc_monetary, const char *lc_numeric, struct lconv *output)
void pg_localeconv_free(struct lconv *lconv)

References CurrentLocaleConvValid, db_encoding_convert(), elog, encoding, ereport, errcode(), errmsg(), ERROR, free_struct_lconv(), locale_monetary, locale_numeric, PG_CATCH, PG_END_TRY, pg_get_encoding_from_locale(), pg_localeconv_free(), pg_localeconv_r(), PG_RE_THROW, PG_SQL_ASCII, PG_TRY, and struct_lconv_is_valid().

Referenced by cash_in(), cash_numeric(), cash_out(), int4_cash(), int8_cash(), NUM_prepare_locale(), and numeric_cash().

◆ strfold_builtin()

size_t strfold_builtin ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 113 of file pg_locale_builtin.c.

115{
116 return unicode_strfold(dest, destsize, src, srclen,
117 locale->info.builtin.casemap_full);
118}
size_t unicode_strfold(char *dst, size_t dstsize, const char *src, ssize_t srclen, bool full)
Definition: unicode_case.c:189

References generate_unaccent_rules::dest, locale, and unicode_strfold().

Referenced by pg_strfold().

◆ strfold_icu()

size_t strfold_icu ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Referenced by pg_strfold().

◆ strlower_builtin()

size_t strlower_builtin ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 80 of file pg_locale_builtin.c.

82{
83 return unicode_strlower(dest, destsize, src, srclen,
84 locale->info.builtin.casemap_full);
85}
size_t unicode_strlower(char *dst, size_t dstsize, const char *src, ssize_t srclen, bool full)
Definition: unicode_case.c:101

References generate_unaccent_rules::dest, locale, and unicode_strlower().

Referenced by pg_strlower().

◆ strlower_icu()

size_t strlower_icu ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Referenced by pg_strlower().

◆ strlower_libc()

size_t strlower_libc ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 123 of file pg_locale_libc.c.

125{
127 return strlower_libc_mb(dst, dstsize, src, srclen, locale);
128 else
129 return strlower_libc_sb(dst, dstsize, src, srclen, locale);
130}
int pg_database_encoding_max_length(void)
Definition: mbutils.c:1546
static size_t strlower_libc_sb(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
static size_t strlower_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)

References locale, pg_database_encoding_max_length(), strlower_libc_mb(), and strlower_libc_sb().

Referenced by pg_strfold(), and pg_strlower().

◆ strtitle_builtin()

size_t strtitle_builtin ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 88 of file pg_locale_builtin.c.

90{
91 struct WordBoundaryState wbstate = {
92 .str = src,
93 .len = srclen,
94 .offset = 0,
95 .init = false,
96 .prev_alnum = false,
97 };
98
99 return unicode_strtitle(dest, destsize, src, srclen,
100 locale->info.builtin.casemap_full,
101 initcap_wbnext, &wbstate);
102}
static size_t initcap_wbnext(void *state)
size_t unicode_strtitle(char *dst, size_t dstsize, const char *src, ssize_t srclen, bool full, WordBoundaryNext wbnext, void *wbstate)
Definition: unicode_case.c:138

References generate_unaccent_rules::dest, initcap_wbnext(), locale, WordBoundaryState::str, and unicode_strtitle().

Referenced by pg_strtitle().

◆ strtitle_icu()

size_t strtitle_icu ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Referenced by pg_strtitle().

◆ strtitle_libc()

size_t strtitle_libc ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 133 of file pg_locale_libc.c.

135{
137 return strtitle_libc_mb(dst, dstsize, src, srclen, locale);
138 else
139 return strtitle_libc_sb(dst, dstsize, src, srclen, locale);
140}
static size_t strtitle_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
static size_t strtitle_libc_sb(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)

References locale, pg_database_encoding_max_length(), strtitle_libc_mb(), and strtitle_libc_sb().

Referenced by pg_strtitle().

◆ struct_lconv_is_valid()

static bool struct_lconv_is_valid ( struct lconv *  s)
static

Definition at line 463 of file pg_locale.c.

464{
465 if (s->decimal_point == NULL)
466 return false;
467 if (s->thousands_sep == NULL)
468 return false;
469 if (s->grouping == NULL)
470 return false;
471 if (s->int_curr_symbol == NULL)
472 return false;
473 if (s->currency_symbol == NULL)
474 return false;
475 if (s->mon_decimal_point == NULL)
476 return false;
477 if (s->mon_thousands_sep == NULL)
478 return false;
479 if (s->mon_grouping == NULL)
480 return false;
481 if (s->positive_sign == NULL)
482 return false;
483 if (s->negative_sign == NULL)
484 return false;
485 return true;
486}

Referenced by PGLC_localeconv().

◆ strupper_builtin()

size_t strupper_builtin ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 105 of file pg_locale_builtin.c.

107{
108 return unicode_strupper(dest, destsize, src, srclen,
109 locale->info.builtin.casemap_full);
110}
size_t unicode_strupper(char *dst, size_t dstsize, const char *src, ssize_t srclen, bool full)
Definition: unicode_case.c:165

References generate_unaccent_rules::dest, locale, and unicode_strupper().

Referenced by pg_strupper().

◆ strupper_icu()

size_t strupper_icu ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Referenced by pg_strupper().

◆ strupper_libc()

size_t strupper_libc ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 143 of file pg_locale_libc.c.

145{
147 return strupper_libc_mb(dst, dstsize, src, srclen, locale);
148 else
149 return strupper_libc_sb(dst, dstsize, src, srclen, locale);
150}
static size_t strupper_libc_sb(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
static size_t strupper_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)

References locale, pg_database_encoding_max_length(), strupper_libc_mb(), and strupper_libc_sb().

Referenced by pg_strupper().

Variable Documentation

◆ CollationCache

collation_cache_hash* CollationCache = NULL
static

Definition at line 162 of file pg_locale.c.

Referenced by pg_newlocale_from_collation().

◆ CollationCacheContext

MemoryContext CollationCacheContext = NULL
static

Definition at line 161 of file pg_locale.c.

Referenced by pg_newlocale_from_collation().

◆ CurrentLCTimeValid

bool CurrentLCTimeValid = false
static

Definition at line 134 of file pg_locale.c.

Referenced by assign_locale_time(), and cache_locale_time().

◆ CurrentLocaleConvValid

bool CurrentLocaleConvValid = false
static

Definition at line 133 of file pg_locale.c.

Referenced by assign_locale_monetary(), assign_locale_numeric(), and PGLC_localeconv().

◆ database_ctype_is_c

bool database_ctype_is_c = false

Definition at line 128 of file pg_locale.c.

Referenced by CheckMyDatabase(), t_isalnum(), t_isalpha(), and TParserInit().

◆ default_locale

pg_locale_t default_locale = NULL
static

Definition at line 130 of file pg_locale.c.

Referenced by init_database_collation(), and pg_newlocale_from_collation().

◆ icu_validation_level

int icu_validation_level = WARNING

Definition at line 113 of file pg_locale.c.

Referenced by createdb(), DefineCollation(), and icu_validate_locale().

◆ last_collation_cache_locale

pg_locale_t last_collation_cache_locale = NULL
static

Definition at line 169 of file pg_locale.c.

Referenced by pg_newlocale_from_collation().

◆ last_collation_cache_oid

Oid last_collation_cache_oid = InvalidOid
static

Definition at line 168 of file pg_locale.c.

Referenced by pg_newlocale_from_collation().

◆ locale_messages

char* locale_messages

Definition at line 108 of file pg_locale.c.

◆ locale_monetary

char* locale_monetary

Definition at line 109 of file pg_locale.c.

Referenced by PGLC_localeconv().

◆ locale_numeric

char* locale_numeric

Definition at line 110 of file pg_locale.c.

Referenced by PGLC_localeconv().

◆ locale_time

char* locale_time

Definition at line 111 of file pg_locale.c.

Referenced by cache_locale_time().

◆ localized_abbrev_days

char* localized_abbrev_days[7+1]

Definition at line 122 of file pg_locale.c.

Referenced by cache_locale_time(), DCH_from_char(), and DCH_to_char().

◆ localized_abbrev_months

char* localized_abbrev_months[12+1]

Definition at line 124 of file pg_locale.c.

Referenced by cache_locale_time(), DCH_from_char(), and DCH_to_char().

◆ localized_full_days

char* localized_full_days[7+1]

Definition at line 123 of file pg_locale.c.

Referenced by cache_locale_time(), DCH_from_char(), and DCH_to_char().

◆ localized_full_months

char* localized_full_months[12+1]

Definition at line 125 of file pg_locale.c.

Referenced by cache_locale_time(), DCH_from_char(), and DCH_to_char().