* Initialize client encoding conversions. * Called from InitPostgres() once during backend startup. */
| 280 | * Called from InitPostgres() once during backend startup. |
| 281 | */ |
| 282 | void |
| 283 | InitializeClientEncoding(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 |
no test coverage detected