void ReaderDumpParams(Reader *self) { char *str; StringInfoData buf; initStringInfo(&buf); str = QuoteString(self->infile); appendStringInfo(&buf, "INPUT = %s\n", str); pfree(str); str = QuoteString(self->parse_badfile); appendStringInfo(&buf, "PARSE_BADFILE = %s\n", str); pfree(str); str = QuoteString(self->logfile); appendStringInfo(&buf, "LOGFILE = %s\n", str); pfree(str); if (self->limit == INT64_MAX) appendStringInfo(&buf, "LIMIT = INFINITE\n"); else appendStringInfo(&buf, "LIMIT = " int64_FMT "\n", self->limit); if (self->max_parse_errors == INT64_MAX) appendStringInfo(&buf, "PARSE_ERRORS = INFINITE\n"); else appendStringInfo(&buf, "PARSE_ERRORS = " int64_FMT "\n", self->max_parse_errors); if (PG_VALID_FE_ENCODING(self->checker.encoding)) appendStringInfo(&buf, "ENCODING = %s\n", pg_encoding_to_char(self->checker.encoding)); appendStringInfo(&buf, "CHECK_CONSTRAINTS = %s\n", self->checker.check_constraints ? "YES" : "NO"); LoggerLog(INFO, buf.data); pfree(buf.data); ParserDumpParams(self->parser); }
/* * Set the client encoding and save fmgrinfo for the conversion * function if necessary. Returns 0 if okay, -1 if not (bad encoding * or can't support conversion) */ int SetClientEncoding(int encoding, bool doit) { int current_server_encoding; Oid to_server_proc, to_client_proc; FmgrInfo *to_server; FmgrInfo *to_client; MemoryContext oldcontext; if (!PG_VALID_FE_ENCODING(encoding)) return -1; /* Can't do anything during startup, per notes above */ if (!backend_startup_complete) { if (doit) pending_client_encoding = encoding; return 0; } current_server_encoding = GetDatabaseEncoding(); /* * Check for cases that require no conversion function. */ if (current_server_encoding == encoding || current_server_encoding == PG_SQL_ASCII || encoding == PG_SQL_ASCII) { if (doit) { ClientEncoding = &pg_enc2name_tbl[encoding]; ToServerConvProc = NULL; ToClientConvProc = NULL; if (MbProcContext) MemoryContextReset(MbProcContext); } return 0; } /* * If we're not inside a transaction then we can't do catalog lookups, so * fail. After backend startup, this could only happen if we are * re-reading postgresql.conf due to SIGHUP --- so basically this just * constrains the ability to change client_encoding on the fly from * postgresql.conf. Which would probably be a stupid thing to do anyway. */ if (!IsTransactionState()) return -1; /* * Look up the conversion functions. */ to_server_proc = FindDefaultConversionProc(encoding, current_server_encoding); if (!OidIsValid(to_server_proc)) return -1; to_client_proc = FindDefaultConversionProc(current_server_encoding, encoding); if (!OidIsValid(to_client_proc)) return -1; /* * Done if not wanting to actually apply setting. */ if (!doit) return 0; /* Before loading the new fmgr info, remove the old info, if any */ ToServerConvProc = NULL; ToClientConvProc = NULL; if (MbProcContext != NULL) { MemoryContextReset(MbProcContext); } else { /* * This is the first time through, so create the context. Make it a * child of TopMemoryContext so that these values survive across * transactions. */ MbProcContext = AllocSetContextCreate(TopMemoryContext, "MbProcContext", ALLOCSET_SMALL_MINSIZE, ALLOCSET_SMALL_INITSIZE, ALLOCSET_SMALL_MAXSIZE); } /* Load the fmgr info into MbProcContext */ oldcontext = MemoryContextSwitchTo(MbProcContext); to_server = palloc(sizeof(FmgrInfo)); to_client = palloc(sizeof(FmgrInfo)); fmgr_info(to_server_proc, to_server); fmgr_info(to_client_proc, to_client); MemoryContextSwitchTo(oldcontext); ClientEncoding = &pg_enc2name_tbl[encoding]; ToServerConvProc = to_server; ToClientConvProc = to_client; return 0; }
/* * Set the client encoding and save fmgrinfo for the conversion * function if necessary. Returns 0 if okay, -1 if not (bad encoding * or can't support conversion) */ int SetClientEncoding(int encoding, bool doit) { int current_server_encoding; Oid to_server_proc, to_client_proc; FmgrInfo *to_server; FmgrInfo *to_client; MemoryContext oldcontext; if (!PG_VALID_FE_ENCODING(encoding)) return (-1); /* Can't do anything during startup, per notes above */ if (!backend_startup_complete) { if (doit) pending_client_encoding = encoding; return 0; } current_server_encoding = GetDatabaseEncoding(); /* * Check for cases that require no conversion function. */ if (current_server_encoding == encoding || (current_server_encoding == PG_SQL_ASCII || encoding == PG_SQL_ASCII)) { if (doit) { ClientEncoding = &pg_enc2name_tbl[encoding]; if (ToServerConvProc != NULL) { if (ToServerConvProc->fn_extra) pfree(ToServerConvProc->fn_extra); pfree(ToServerConvProc); } ToServerConvProc = NULL; if (ToClientConvProc != NULL) { if (ToClientConvProc->fn_extra) pfree(ToClientConvProc->fn_extra); pfree(ToClientConvProc); } ToClientConvProc = NULL; } return 0; } /* * If we're not inside a transaction then we can't do catalog lookups, * so fail. After backend startup, this could only happen if we are * re-reading postgresql.conf due to SIGHUP --- so basically this just * constrains the ability to change client_encoding on the fly from * postgresql.conf. Which would probably be a stupid thing to do * anyway. */ if (!IsTransactionState()) return -1; /* * Look up the conversion functions. */ to_server_proc = FindDefaultConversionProc(encoding, current_server_encoding); if (!OidIsValid(to_server_proc)) return -1; to_client_proc = FindDefaultConversionProc(current_server_encoding, encoding); if (!OidIsValid(to_client_proc)) return -1; /* * Done if not wanting to actually apply setting. */ if (!doit) return 0; /* * load the fmgr info into TopMemoryContext so that it survives * outside transaction. */ oldcontext = MemoryContextSwitchTo(TopMemoryContext); to_server = palloc(sizeof(FmgrInfo)); to_client = palloc(sizeof(FmgrInfo)); fmgr_info(to_server_proc, to_server); fmgr_info(to_client_proc, to_client); MemoryContextSwitchTo(oldcontext); ClientEncoding = &pg_enc2name_tbl[encoding]; if (ToServerConvProc != NULL) { if (ToServerConvProc->fn_extra) pfree(ToServerConvProc->fn_extra); pfree(ToServerConvProc); } ToServerConvProc = to_server; if (ToClientConvProc != NULL) { if (ToClientConvProc->fn_extra) pfree(ToClientConvProc->fn_extra); pfree(ToClientConvProc); } ToClientConvProc = to_client; return 0; }