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 50 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 307 of file pg_locale_icu.c.

308{
309#ifdef USE_ICU
310 bool deterministic;
311 const char *iculocstr;
312 const char *icurules = NULL;
314 locale_t loc = (locale_t) 0;
315 pg_locale_t result;
316
318 {
319 HeapTuple tp;
320 Datum datum;
321 bool isnull;
322
324 if (!HeapTupleIsValid(tp))
325 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
326
327 /* default database collation is always deterministic */
328 deterministic = true;
332 datum = SysCacheGetAttr(DATABASEOID, tp,
334 if (!isnull)
336
337 /* libc only needed for default locale and single-byte encoding */
339 {
340 const char *ctype;
341
344 ctype = TextDatumGetCString(datum);
345
346 loc = make_libc_ctype_locale(ctype);
347 }
348
349 ReleaseSysCache(tp);
350 }
351 else
352 {
354 HeapTuple tp;
355 Datum datum;
356 bool isnull;
357
359 if (!HeapTupleIsValid(tp))
360 elog(ERROR, "cache lookup failed for collation %u", collid);
362 deterministic = collform->collisdeterministic;
366 datum = SysCacheGetAttr(COLLOID, tp,
368 if (!isnull)
370
371 ReleaseSysCache(tp);
372 }
373
375
376 result = MemoryContextAllocZero(context, sizeof(struct pg_locale_struct));
377 result->icu.locale = MemoryContextStrdup(context, iculocstr);
378 result->icu.ucol = collator;
379 result->icu.lt = loc;
380 result->deterministic = deterministic;
381 result->collate_is_c = false;
382 result->ctype_is_c = false;
384 {
385 result->icu.ucasemap = pg_ucasemap_open(iculocstr);
387 result->ctype = &ctype_methods_icu_utf8;
388 }
389 else
390 {
391 result->collate = &collate_methods_icu;
392 result->ctype = &ctype_methods_icu;
393 }
394
395 return result;
396#else
397 /* could get here if a collation was created by a build with ICU */
400 errmsg("ICU is not supported in this build")));
401
402 return NULL;
403#endif
404}
#define TextDatumGetCString(d)
Definition builtins.h:98
Oid collid
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
Oid MyDatabaseId
Definition globals.c:94
#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:1264
int pg_database_encoding_max_length(void)
Definition mbutils.c:1549
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition mcxt.c:1768
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1266
FormData_pg_collation * Form_pg_collation
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
const struct ctype_methods * ctype
Definition pg_locale.h:146
const struct collate_methods * collate
Definition pg_locale.h:145
const char * locale
Definition pg_locale.h:152
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition syscache.c:220
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:595
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:625
#define locale_t
Definition win32_port.h:429

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

Referenced by create_pg_locale(), and init_database_collation().