mirror of
https://github.com/postgres/postgres.git
synced 2025-12-10 14:22:35 +03:00
ICU support
Add a column collprovider to pg_collation that determines which library provides the collation data. The existing choices are default and libc, and this adds an icu choice, which uses the ICU4C library. The pg_locale_t type is changed to a union that contains the provider-specific locale handles. Users of locale information are changed to look into that struct for the appropriate handle to use. Also add a collversion column that records the version of the collation when it is created, and check at run time whether it is still the same. This detects potentially incompatible library upgrades that can corrupt indexes and other structures. This is currently only supported by ICU-provided collations. initdb initializes the default collation set as before from the `locale -a` output but also adds all available ICU locales with a "-x-icu" appended. Currently, ICU-provided collations can only be explicitly named collations. The global database locales are still always libc-provided. ICU support is enabled by configure --with-icu. Reviewed-by: Thomas Munro <thomas.munro@enterprisedb.com> Reviewed-by: Andreas Karlsson <andreas@proxel.se>
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
#if defined(LOCALE_T_IN_XLOCALE) || defined(WCSTOMBS_L_IN_XLOCALE)
|
||||
#include <xlocale.h>
|
||||
#endif
|
||||
#ifdef USE_ICU
|
||||
#include <unicode/ucol.h>
|
||||
#endif
|
||||
|
||||
#include "utils/guc.h"
|
||||
|
||||
@@ -61,17 +64,36 @@ extern void cache_locale_time(void);
|
||||
* We define our own wrapper around locale_t so we can keep the same
|
||||
* function signatures for all builds, while not having to create a
|
||||
* fake version of the standard type locale_t in the global namespace.
|
||||
* The fake version of pg_locale_t can be checked for truth; that's
|
||||
* about all it will be needed for.
|
||||
* pg_locale_t is occasionally checked for truth, so make it a pointer.
|
||||
*/
|
||||
struct pg_locale_t
|
||||
{
|
||||
char provider;
|
||||
union
|
||||
{
|
||||
#ifdef HAVE_LOCALE_T
|
||||
typedef locale_t pg_locale_t;
|
||||
#else
|
||||
typedef int pg_locale_t;
|
||||
locale_t lt;
|
||||
#endif
|
||||
#ifdef USE_ICU
|
||||
struct {
|
||||
const char *locale;
|
||||
UCollator *ucol;
|
||||
} icu;
|
||||
#endif
|
||||
} info;
|
||||
};
|
||||
|
||||
typedef struct pg_locale_t *pg_locale_t;
|
||||
|
||||
extern pg_locale_t pg_newlocale_from_collation(Oid collid);
|
||||
|
||||
extern char *get_collation_actual_version(char collprovider, const char *collcollate);
|
||||
|
||||
#ifdef USE_ICU
|
||||
extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes);
|
||||
extern int32_t icu_from_uchar(char **result, UChar *buff_uchar, int32_t len_uchar);
|
||||
#endif
|
||||
|
||||
/* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */
|
||||
#ifdef USE_WIDE_UPPER_LOWER
|
||||
extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen,
|
||||
|
||||
Reference in New Issue
Block a user