int
main(int argc, char *argv[])
{
+ static int if_exists = 0;
+
static struct option long_options[] = {
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"password", no_argument, NULL, 'W'},
{"echo", no_argument, NULL, 'e'},
{"interactive", no_argument, NULL, 'i'},
+ {"if-exists", no_argument, &if_exists, 1},
{NULL, 0, NULL, 0}
};
case 'i':
interactive = true;
break;
+ case 0:
+ /* this covers the long options */
+ break;
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
initPQExpBuffer(&sql);
- appendPQExpBuffer(&sql, "DROP DATABASE %s;\n",
- fmtId(dbname));
+ appendPQExpBuffer(&sql, "DROP DATABASE %s%s;\n",
+ (if_exists ? "IF EXISTS " : ""), fmtId(dbname));
/*
* Connect to the 'postgres' database by default, except have the
printf(_("\nOptions:\n"));
printf(_(" -e, --echo show the commands being sent to the server\n"));
printf(_(" -i, --interactive prompt before deleting anything\n"));
+ printf(_(" --if-exists don't report error if database doesn't exist\n"));
printf(_(" --help show this help, then exit\n"));
printf(_(" --version output version information, then exit\n"));
printf(_("\nConnection options:\n"));
int
main(int argc, char *argv[])
{
+ static int if_exists = 0;
+
static struct option long_options[] = {
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"password", no_argument, NULL, 'W'},
{"echo", no_argument, NULL, 'e'},
{"interactive", no_argument, NULL, 'i'},
+ {"if-exists", no_argument, &if_exists, 1},
{NULL, 0, NULL, 0}
};
case 'i':
interactive = true;
break;
+ case 0:
+ /* this covers the long options */
+ break;
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
initPQExpBuffer(&sql);
- appendPQExpBuffer(&sql, "DROP ROLE %s;\n", fmtId(dropuser));
+ appendPQExpBuffer(&sql, "DROP ROLE %s%s;\n",
+ (if_exists ? "IF EXISTS " : ""), fmtId(dropuser));
conn = connectDatabase("postgres", host, port, username, prompt_password, progname);
printf(_("\nOptions:\n"));
printf(_(" -e, --echo show the commands being sent to the server\n"));
printf(_(" -i, --interactive prompt before deleting anything\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(_("\nConnection options:\n"));