mirror of https://github.com/postgres/postgres
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.9 KiB
70 lines
1.9 KiB
/*-----------------------------------------------------------------------
|
|
*
|
|
* PostgreSQL locale utilities for builtin provider
|
|
*
|
|
* Portions Copyright (c) 2002-2024, PostgreSQL Global Development Group
|
|
*
|
|
* src/backend/utils/adt/pg_locale_builtin.c
|
|
*
|
|
*-----------------------------------------------------------------------
|
|
*/
|
|
|
|
#include "postgres.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/memutils.h"
|
|
#include "utils/pg_locale.h"
|
|
#include "utils/syscache.h"
|
|
|
|
extern pg_locale_t create_pg_locale_builtin(Oid collid,
|
|
MemoryContext context);
|
|
|
|
pg_locale_t
|
|
create_pg_locale_builtin(Oid collid, MemoryContext context)
|
|
{
|
|
const char *locstr;
|
|
pg_locale_t result;
|
|
|
|
if (collid == DEFAULT_COLLATION_OID)
|
|
{
|
|
HeapTuple tp;
|
|
Datum datum;
|
|
|
|
tp = SearchSysCache1(DATABASEOID, ObjectIdGetDatum(MyDatabaseId));
|
|
if (!HeapTupleIsValid(tp))
|
|
elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
|
|
datum = SysCacheGetAttrNotNull(DATABASEOID, tp,
|
|
Anum_pg_database_datlocale);
|
|
locstr = TextDatumGetCString(datum);
|
|
ReleaseSysCache(tp);
|
|
}
|
|
else
|
|
{
|
|
HeapTuple tp;
|
|
Datum datum;
|
|
|
|
tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
|
|
if (!HeapTupleIsValid(tp))
|
|
elog(ERROR, "cache lookup failed for collation %u", collid);
|
|
datum = SysCacheGetAttrNotNull(COLLOID, tp,
|
|
Anum_pg_collation_colllocale);
|
|
locstr = TextDatumGetCString(datum);
|
|
ReleaseSysCache(tp);
|
|
}
|
|
|
|
builtin_validate_locale(GetDatabaseEncoding(), locstr);
|
|
|
|
result = MemoryContextAllocZero(context, sizeof(struct pg_locale_struct));
|
|
|
|
result->info.builtin.locale = MemoryContextStrdup(context, locstr);
|
|
result->provider = COLLPROVIDER_BUILTIN;
|
|
result->deterministic = true;
|
|
result->collate_is_c = true;
|
|
result->ctype_is_c = (strcmp(locstr, "C") == 0);
|
|
|
|
return result;
|
|
}
|
|
|