PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_locale_icu.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "catalog/pg_database.h"
#include "catalog/pg_collation.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/formatting.h"
#include "utils/memutils.h"
#include "utils/pg_locale.h"
#include "utils/syscache.h"
Include dependency graph for pg_locale_icu.c:

Go to the source code of this file.

Macros

#define TEXTBUFLEN   1024
 

Functions

pg_locale_t create_pg_locale_icu (Oid collid, MemoryContext context)
 

Macro Definition Documentation

◆ TEXTBUFLEN

#define TEXTBUFLEN   1024

Definition at line 48 of file pg_locale_icu.c.

Function Documentation

◆ create_pg_locale_icu()

pg_locale_t create_pg_locale_icu ( Oid  collid,
MemoryContext  context 
)
extern

Definition at line 313 of file pg_locale_icu.c.

314{
315#ifdef USE_ICU
316 bool deterministic;
317 const char *iculocstr;
318 const char *icurules = NULL;
320 locale_t loc = (locale_t) 0;
322
324 {
325 HeapTuple tp;
326 Datum datum;
327 bool isnull;
328
330 if (!HeapTupleIsValid(tp))
331 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
332
333 /* default database collation is always deterministic */
334 deterministic = true;
338 datum = SysCacheGetAttr(DATABASEOID, tp,
340 if (!isnull)
342
343 /* libc only needed for default locale and single-byte encoding */
345 {
346 const char *ctype;
347
350 ctype = TextDatumGetCString(datum);
351
352 loc = make_libc_ctype_locale(ctype);
353 }
354
355 ReleaseSysCache(tp);
356 }
357 else
358 {
360 HeapTuple tp;
361 Datum datum;
362 bool isnull;
363
365 if (!HeapTupleIsValid(tp))
366 elog(ERROR, "cache lookup failed for collation %u", collid);
368 deterministic = collform->collisdeterministic;
372 datum = SysCacheGetAttr(COLLOID, tp,
374 if (!isnull)
376
377 ReleaseSysCache(tp);
378 }
379
381
382 result = MemoryContextAllocZero(context, sizeof(struct pg_locale_struct));
383 result->icu.locale = MemoryContextStrdup(context, iculocstr);
384 result->icu.ucol = collator;
385 result->icu.lt = loc;
386 result->deterministic = deterministic;
387 result->collate_is_c = false;
388 result->ctype_is_c = false;
390 {
391 result->icu.ucasemap = pg_ucasemap_open(iculocstr);
394 }
395 else
396 {
397 result->collate = &collate_methods_icu;
398 result->ctype = &ctype_methods_icu;
399 }
400
401 return result;
402#else /* not USE_ICU */
403 /* could get here if a collation was created by a build with ICU */
406 errmsg("ICU is not supported in this build")));
407
408 return NULL;
409#endif /* not USE_ICU */
410}
#define TextDatumGetCString(d)
Definition builtins.h:99
uint32 result
Oid collid
int errcode(int sqlerrcode)
Definition elog.c:875
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define ereport(elevel,...)
Definition elog.h:152
Oid MyDatabaseId
Definition globals.c:96
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
#define PG_UTF8
Definition mbprint.c:43
int GetDatabaseEncoding(void)
Definition mbutils.c:1389
int pg_database_encoding_max_length(void)
Definition mbutils.c:1673
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition mcxt.c:1897
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1269
static char * errmsg
END_CATALOG_STRUCT typedef FormData_pg_collation * Form_pg_collation
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:626
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221
Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:596
#define locale_t
Definition win32_port.h:446

References collid, elog, ereport, errcode(), errmsg, ERROR, fb(), Form_pg_collation, GetDatabaseEncoding(), GETSTRUCT(), HeapTupleIsValid, locale_t, MemoryContextAllocZero(), MemoryContextStrdup(), MyDatabaseId, ObjectIdGetDatum(), pg_database_encoding_max_length(), PG_UTF8, ReleaseSysCache(), result, SearchSysCache1(), SysCacheGetAttr(), SysCacheGetAttrNotNull(), and TextDatumGetCString.

Referenced by create_pg_locale(), and init_database_collation().