* \encoding -- set/show client side encoding */
| 1258 | * \encoding -- set/show client side encoding |
| 1259 | */ |
| 1260 | static backslashResult |
| 1261 | exec_command_encoding(PsqlScanState scan_state, bool active_branch) |
| 1262 | { |
| 1263 | if (active_branch) |
| 1264 | { |
| 1265 | char *encoding = psql_scan_slash_option(scan_state, |
| 1266 | OT_NORMAL, NULL, false); |
| 1267 | |
| 1268 | if (!encoding) |
| 1269 | { |
| 1270 | /* show encoding */ |
| 1271 | puts(pg_encoding_to_char(pset.encoding)); |
| 1272 | } |
| 1273 | else |
| 1274 | { |
| 1275 | /* set encoding */ |
| 1276 | if (PQsetClientEncoding(pset.db, encoding) == -1) |
| 1277 | pg_log_error("%s: invalid encoding name or conversion procedure not found", encoding); |
| 1278 | else |
| 1279 | { |
| 1280 | /* save encoding info into psql internal data */ |
| 1281 | pset.encoding = PQclientEncoding(pset.db); |
| 1282 | pset.popt.topt.encoding = pset.encoding; |
| 1283 | setFmtEncoding(pset.encoding); |
| 1284 | SetVariable(pset.vars, "ENCODING", |
| 1285 | pg_encoding_to_char(pset.encoding)); |
| 1286 | } |
| 1287 | free(encoding); |
| 1288 | } |
| 1289 | } |
| 1290 | else |
| 1291 | ignore_slash_options(scan_state); |
| 1292 | |
| 1293 | return PSQL_CMD_SKIP_LINE; |
| 1294 | } |
| 1295 | |
| 1296 | /* |
| 1297 | * \errverbose -- display verbose message from last failed query |
no test coverage detected