mirror of
https://github.com/postgres/postgres.git
synced 2025-09-05 02:22:28 +03:00
Perform provider-specific initialization in new functions.
Reviewed-by: Andreas Karlsson Discussion: https://postgr.es/m/4548a168-62cd-457b-8d06-9ba7b985c477@proxel.se
This commit is contained in:
70
src/backend/utils/adt/pg_locale_builtin.c
Normal file
70
src/backend/utils/adt/pg_locale_builtin.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/*-----------------------------------------------------------------------
|
||||
*
|
||||
* 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;
|
||||
}
|
Reference in New Issue
Block a user