mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Add psql \prompt capability.
Chad Wagner
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.177 2007/01/05 22:19:49 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.178 2007/02/23 18:20:58 momjian Exp $
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
#include "command.h"
|
||||
@ -712,6 +712,57 @@ exec_command(const char *cmd,
|
||||
free(pw2);
|
||||
}
|
||||
|
||||
/* \prompt -- prompt and set variable */
|
||||
else if (strcmp(cmd, "prompt") == 0)
|
||||
{
|
||||
char *opt, *prompt_text = NULL;
|
||||
char *arg1, *arg2;
|
||||
|
||||
arg1 = psql_scan_slash_option(scan_state, OT_NORMAL, NULL, false);
|
||||
arg2 = psql_scan_slash_option(scan_state, OT_NORMAL, NULL, false);
|
||||
|
||||
if (!arg1)
|
||||
{
|
||||
psql_error("\\%s: missing required argument\n", cmd);
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *result;
|
||||
|
||||
if (arg2)
|
||||
{
|
||||
prompt_text = arg1;
|
||||
opt = arg2;
|
||||
}
|
||||
else
|
||||
opt = arg1;
|
||||
|
||||
if (!pset.inputfile)
|
||||
result = simple_prompt(prompt_text, 4096, true);
|
||||
else
|
||||
{
|
||||
if (prompt_text)
|
||||
{
|
||||
fputs(prompt_text, stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
result = gets_fromFile(stdin);
|
||||
}
|
||||
|
||||
if (!SetVariable(pset.vars, opt, result))
|
||||
{
|
||||
psql_error("\\%s: error\n", cmd);
|
||||
success = false;
|
||||
}
|
||||
|
||||
free(result);
|
||||
if (prompt_text)
|
||||
free(prompt_text);
|
||||
free(opt);
|
||||
}
|
||||
}
|
||||
|
||||
/* \pset -- set printing parameters */
|
||||
else if (strcmp(cmd, "pset") == 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user