| Документация по PostgreSQL 9.4.1 | |||
|---|---|---|---|
| Пред. | Уровень выше | Глава 31. libpq — библиотека для языка C | След. |
31.10. Функции управления
Эти функции управляют различными аспектами поведения libpq.
PQclientEncodingВозвращает кодировку клиента.
int PQclientEncoding(const PGconn *conn);
Заметьте, что она возвращает идентификатор кодировки, а не символьную строку вида EUC_JP. В случае ошибки она возвращает -1. Преобразовать идентификатор кодировки в имя можно, воспользовавшись следующей функцией:
char *pg_encoding_to_char(int encoding_id);
PQsetClientEncodingУстанавливает кодировку клиента.
int PQsetClientEncoding(PGconn *conn, const char *encoding);
В conn передаётся соединение с сервером, а в encoding — имя требуемой кодировки. Если функция устанавливает кодировку успешно, она возвращает 0, или -1 в противном случае. Определить текущую кодировку для соединения можно, воспользовавшись функцией
PQclientEncoding.PQsetErrorVerbosityОпределяет уровень детализации сообщений, возвращаемых функциями
PQerrorMessageиPQresultErrorMessage.typedef enum { PQERRORS_TERSE, PQERRORS_DEFAULT, PQERRORS_VERBOSE } PGVerbosity; PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);PQsetErrorVerbosityустанавливает уровень детализации и возвращает предыдущее значение для соединения. В «лаконичном» режиме (TERSE) возвращаемые сообщения содержат только уровень серьёзности, основной текст и позицию; всё это обычно умещается в одной строке. В режиме по умолчанию выдаваемые сообщения дополнительно содержат поля подробного описания, подсказки или контекста (они могут занимать несколько строк). В «многословном» режиме (VERBOSE) передаются все доступные поля сообщения. Изменение уровня детализации не влияет на сообщения, уже сформированные в существующих объектах PGresult, а затрагивает только последующие сообщения.PQtraceВключает трассировку клиент-серверного взаимодействия с выводом в поток отладочных сообщений.
void PQtrace(PGconn *conn, FILE *stream);
Замечание: В Windows, если библиотека libpq и приложение скомпилированы с разными флагами, эта функция может вызвать крах приложения из-за различий внутреннего представления указателей FILE. В частности, флаги многопоточной/однопоточной, выпускаемой/отладочной или статической/динамической сборки должны быть одинаковыми для библиотеки и всех использующих её приложений.
PQuntraceВыключает трассировку, запущенную функцией
PQtrace.void PQuntrace(PGconn *conn);
| Пред. | Начало | След. |
| Функции, связанные с командой COPY | Уровень выше | Функции разного назначения |
| PostgreSQL 9.4.1 Documentation | |||
|---|---|---|---|
| Prev | Up | Chapter 31. libpq - C Library | Next |
31.10. Control Functions
These functions control miscellaneous details of libpq's behavior.
PQclientEncodingReturns the client encoding.
int PQclientEncoding(const PGconn *conn);
Note that it returns the encoding ID, not a symbolic string such as EUC_JP. If unsuccessful, it returns -1. To convert an encoding ID to an encoding name, you can use:
char *pg_encoding_to_char(int encoding_id);
PQsetClientEncodingSets the client encoding.
int PQsetClientEncoding(PGconn *conn, const char *encoding);
conn is a connection to the server, and encoding is the encoding you want to use. If the function successfully sets the encoding, it returns 0, otherwise -1. The current encoding for this connection can be determined by using
PQclientEncoding.PQsetErrorVerbosityDetermines the verbosity of messages returned by
PQerrorMessageandPQresultErrorMessage.typedef enum { PQERRORS_TERSE, PQERRORS_DEFAULT, PQERRORS_VERBOSE } PGVerbosity; PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);PQsetErrorVerbositysets the verbosity mode, returning the connection's previous setting. In TERSE mode, returned messages include severity, primary text, and position only; this will normally fit on a single line. The default mode produces messages that include the above plus any detail, hint, or context fields (these might span multiple lines). The VERBOSE mode includes all available fields. Changing the verbosity does not affect the messages available from already-existing PGresult objects, only subsequently-created ones.PQtraceEnables tracing of the client/server communication to a debugging file stream.
void PQtrace(PGconn *conn, FILE *stream);
Note: On Windows, if the libpq library and an application are compiled with different flags, this function call will crash the application because the internal representation of the FILE pointers differ. Specifically, multithreaded/single-threaded, release/debug, and static/dynamic flags should be the same for the library and all applications using that library.
PQuntraceDisables tracing started by
PQtrace.void PQuntrace(PGconn *conn);