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

Function PQsetClientEncoding

src/interfaces/libpq/fe-connect.c:7070–7110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7068}
7069
7070int
7071PQsetClientEncoding(PGconn *conn, const char *encoding)
7072{
7073 char qbuf[128];
7074 static const char query[] = "set client_encoding to '%s'";
7075 PGresult *res;
7076 int status;
7077
7078 if (!conn || conn->status != CONNECTION_OK)
7079 return -1;
7080
7081 if (!encoding)
7082 return -1;
7083
7084 /* Resolve special "auto" value from the locale */
7085 if (strcmp(encoding, "auto") == 0)
7086 encoding = pg_encoding_to_char(pg_get_encoding_from_locale(NULL, true));
7087
7088 /* check query buffer overflow */
7089 if (sizeof(qbuf) < (sizeof(query) + strlen(encoding)))
7090 return -1;
7091
7092 /* ok, now send a query */
7093 sprintf(qbuf, query, encoding);
7094 res = PQexec(conn, qbuf);
7095
7096 if (res == NULL)
7097 return -1;
7098 if (res->resultStatus != PGRES_COMMAND_OK)
7099 status = -1;
7100 else
7101 {
7102 /*
7103 * We rely on the backend to report the parameter value, and we'll
7104 * change state at that time.
7105 */
7106 status = 0; /* everything is ok */
7107 }
7108 PQclear(res);
7109 return status;
7110}
7111
7112PGVerbosity
7113PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity)

Callers 6

dblink_get_connFunction · 0.85
dblink_connectFunction · 0.85
test_one_vectorFunction · 0.85
exec_command_encodingFunction · 0.85
mainFunction · 0.85
setup_connectionFunction · 0.85

Calls 4

pg_encoding_to_charFunction · 0.85
PQexecFunction · 0.85
PQclearFunction · 0.85

Tested by 1

test_one_vectorFunction · 0.68