*
* dropuser
*
- * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/bin/scripts/dropuser.c
#include "postgres_fe.h"
#include "common.h"
-#include "dumputils.h"
+#include "fe_utils/string_utils.h"
static void help(const char *progname);
enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
bool interactive = false;
+ char dropuser_buf[128];
PQExpBufferData sql;
switch (c)
{
case 'h':
- host = optarg;
+ host = pg_strdup(optarg);
break;
case 'p':
- port = optarg;
+ port = pg_strdup(optarg);
break;
case 'U':
- username = optarg;
+ username = pg_strdup(optarg);
break;
case 'w':
prompt_password = TRI_NO;
if (dropuser == NULL)
{
if (interactive)
- dropuser = simple_prompt("Enter name of role to drop: ", 128, true);
+ {
+ simple_prompt("Enter name of role to drop: ",
+ dropuser_buf, sizeof(dropuser_buf), true);
+ dropuser = dropuser_buf;
+ }
else
{
fprintf(stderr, _("%s: missing required argument role name\n"), progname);
}
initPQExpBuffer(&sql);
- appendPQExpBuffer(&sql, "DROP ROLE %s%s;\n",
+ appendPQExpBuffer(&sql, "DROP ROLE %s%s;",
(if_exists ? "IF EXISTS " : ""), fmtId(dropuser));
conn = connectDatabase("postgres", host, port, username, prompt_password,
- progname, false);
+ progname, echo, false, false);
if (echo)
- printf("%s", sql.data);
+ printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
printf(_(" -e, --echo show the commands being sent to the server\n"));
printf(_(" -i, --interactive prompt before deleting anything, and prompt for\n"
" role name if not specified\n"));
+ printf(_(" -V, --version output version information, then exit\n"));
printf(_(" --if-exists don't report error if user doesn't exist\n"));
- printf(_(" --help show this help, then exit\n"));
- printf(_(" --version output version information, then exit\n"));
+ printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nConnection options:\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port\n"));