| 7068 | } |
| 7069 | |
| 7070 | int |
| 7071 | PQsetClientEncoding(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 | |
| 7112 | PGVerbosity |
| 7113 | PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity) |