Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
32.11. Control Functions
Prev UpChapter 32. libpq — C LibraryHome Next

32.11. Control Functions#

These functions control miscellaneous details oflibpq's behavior.

PQclientEncoding#

Returns the client encoding.

int PQclientEncoding(const PGconn *conn);

Note that it returns the encoding ID, not a symbolic string such asEUC_JP. If unsuccessful, it returns -1. To convert an encoding ID to an encoding name, you can use:

char *pg_encoding_to_char(intencoding_id);

PQsetClientEncoding#

Sets the client encoding.

int PQsetClientEncoding(PGconn *conn, const char *encoding);

conn is a connection to the server, andencoding 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 usingPQclientEncoding.

PQsetErrorVerbosity#

Determines the verbosity of messages returned byPQerrorMessage andPQresultErrorMessage.

typedef enum{    PQERRORS_TERSE,    PQERRORS_DEFAULT,    PQERRORS_VERBOSE,    PQERRORS_SQLSTATE} PGVerbosity;PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);

PQsetErrorVerbosity sets the verbosity mode, returning the connection's previous setting. InTERSE mode, returned messages include severity, primary text, and position only; this will normally fit on a single line. TheDEFAULT mode produces messages that include the above plus any detail, hint, or context fields (these might span multiple lines). TheVERBOSE mode includes all available fields. TheSQLSTATE mode includes only the error severity and theSQLSTATE error code, if one is available (if not, the output is likeTERSE mode).

Changing the verbosity setting does not affect the messages available from already-existingPGresult objects, only subsequently-created ones. (But seePQresultVerboseErrorMessage if you want to print a previous error with a different verbosity.)

PQsetErrorContextVisibility#

Determines the handling ofCONTEXT fields in messages returned byPQerrorMessage andPQresultErrorMessage.

typedef enum{    PQSHOW_CONTEXT_NEVER,    PQSHOW_CONTEXT_ERRORS,    PQSHOW_CONTEXT_ALWAYS} PGContextVisibility;PGContextVisibility PQsetErrorContextVisibility(PGconn *conn, PGContextVisibility show_context);

PQsetErrorContextVisibility sets the context display mode, returning the connection's previous setting. This mode controls whether theCONTEXT field is included in messages. TheNEVER mode never includesCONTEXT, whileALWAYS always includes it if available. InERRORS mode (the default),CONTEXT fields are included only in error messages, not in notices and warnings. (However, if the verbosity setting isTERSE orSQLSTATE,CONTEXT fields are omitted regardless of the context display mode.)

Changing this mode does not affect the messages available from already-existingPGresult objects, only subsequently-created ones. (But seePQresultVerboseErrorMessage if you want to print a previous error with a different display mode.)

PQtrace#

Enables tracing of the client/server communication to a debugging file stream.

void PQtrace(PGconn *conn, FILE *stream);

Each line consists of: an optional timestamp, a direction indicator (F for messages from client to server orB for messages from server to client), message length, message type, and message contents. Non-message contents fields (timestamp, direction, length and message type) are separated by a tab. Message contents are separated by a space. Protocol strings are enclosed in double quotes, while strings used as data values are enclosed in single quotes. Non-printable chars are printed as hexadecimal escapes. Further message-type-specific detail can be found inSection 53.7.

Note

On Windows, if thelibpq library and an application are compiled with different flags, this function call will crash the application because the internal representation of theFILE 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.

PQsetTraceFlags#

Controls the tracing behavior of client/server communication.

void PQsetTraceFlags(PGconn *conn, int flags);

flags contains flag bits describing the operating mode of tracing. Ifflags containsPQTRACE_SUPPRESS_TIMESTAMPS, then the timestamp is not included when printing each message. Ifflags containsPQTRACE_REGRESS_MODE, then some fields are redacted when printing each message, such as object OIDs, to make the output more convenient to use in testing frameworks. This function must be called after callingPQtrace.

PQuntrace#

Disables tracing started byPQtrace.

void PQuntrace(PGconn *conn);


Prev Up Next
32.10. Functions Associated with theCOPY Command Home 32.12. Miscellaneous Functions
pdfepub
Go to PostgreSQL 17
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp