MCPcopy Create free account
hub / github.com/apache/cloudberry / InitializeClientEncoding

Function InitializeClientEncoding

src/backend/utils/mb/mbutils.c:282–332  ·  view source on GitHub ↗

* Initialize client encoding conversions. * Called from InitPostgres() once during backend startup. */

Source from the content-addressed store, hash-verified

280 * Called from InitPostgres() once during backend startup.
281 */
282void
283InitializeClientEncoding(void)
284{
285 int current_server_encoding;
286
287 Assert(!backend_startup_complete);
288 backend_startup_complete = true;
289
290 if (PrepareClientEncoding(pending_client_encoding) < 0 ||
291 SetClientEncoding(pending_client_encoding) < 0)
292 {
293 /*
294 * Oops, the requested conversion is not available. We couldn't fail
295 * before, but we can now.
296 */
297 ereport(FATAL,
298 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
299 errmsg("conversion between %s and %s is not supported",
300 pg_enc2name_tbl[pending_client_encoding].name,
301 GetDatabaseEncodingName())));
302 }
303
304 /*
305 * Also look up the UTF8-to-server conversion function if needed. Since
306 * the server encoding is fixed within any one backend process, we don't
307 * have to do this more than once.
308 */
309 current_server_encoding = GetDatabaseEncoding();
310 if (current_server_encoding != PG_UTF8 &&
311 current_server_encoding != PG_SQL_ASCII)
312 {
313 Oid utf8_to_server_proc;
314
315 Assert(IsTransactionState());
316 utf8_to_server_proc =
317 FindDefaultConversionProc(PG_UTF8,
318 current_server_encoding);
319 /* If there's no such conversion, just leave the pointer as NULL */
320 if (OidIsValid(utf8_to_server_proc))
321 {
322 FmgrInfo *finfo;
323
324 finfo = (FmgrInfo *) MemoryContextAlloc(TopMemoryContext,
325 sizeof(FmgrInfo));
326 fmgr_info_cxt(utf8_to_server_proc, finfo,
327 TopMemoryContext);
328 /* Set Utf8ToServerConvProc only after data is fully valid */
329 Utf8ToServerConvProc = finfo;
330 }
331 }
332}
333
334/*
335 * returns the current client encoding

Callers 1

InitPostgresFunction · 0.85

Calls 10

PrepareClientEncodingFunction · 0.85
SetClientEncodingFunction · 0.85
GetDatabaseEncodingNameFunction · 0.85
GetDatabaseEncodingFunction · 0.85
IsTransactionStateFunction · 0.85
MemoryContextAllocFunction · 0.85
fmgr_info_cxtFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected