Commit 7ff77119 authored by Bruce Momjian's avatar Bruce Momjian

For create/dropdb, only connect once to the server since we now have a

shared description table for pg_database comments.

Also update comments about database name selection.
parent 87631ac9
...@@ -192,6 +192,11 @@ main(int argc, char *argv[]) ...@@ -192,6 +192,11 @@ main(int argc, char *argv[])
appendPQExpBuffer(&sql, ";\n"); appendPQExpBuffer(&sql, ";\n");
/*
* Connect to the 'postgres' database by default, except have
* the 'postgres' user use 'template1' so he can create the
* 'postgres' database.
*/
conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres", conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres",
host, port, username, prompt_password, progname); host, port, username, prompt_password, progname);
...@@ -208,12 +213,9 @@ main(int argc, char *argv[]) ...@@ -208,12 +213,9 @@ main(int argc, char *argv[])
} }
PQclear(result); PQclear(result);
PQfinish(conn);
if (comment) if (comment)
{ {
conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
printfPQExpBuffer(&sql, "COMMENT ON DATABASE %s IS ", fmtId(dbname)); printfPQExpBuffer(&sql, "COMMENT ON DATABASE %s IS ", fmtId(dbname));
appendStringLiteralConn(&sql, comment, conn); appendStringLiteralConn(&sql, comment, conn);
appendPQExpBuffer(&sql, ";\n"); appendPQExpBuffer(&sql, ";\n");
...@@ -231,9 +233,10 @@ main(int argc, char *argv[]) ...@@ -231,9 +233,10 @@ main(int argc, char *argv[])
} }
PQclear(result); PQclear(result);
PQfinish(conn);
} }
PQfinish(conn);
exit(0); exit(0);
} }
......
...@@ -113,6 +113,11 @@ main(int argc, char *argv[]) ...@@ -113,6 +113,11 @@ main(int argc, char *argv[])
appendPQExpBuffer(&sql, "DROP DATABASE %s;\n", appendPQExpBuffer(&sql, "DROP DATABASE %s;\n",
fmtId(dbname)); fmtId(dbname));
/*
* Connect to the 'postgres' database by default, except have
* the 'postgres' user use 'template1' so he can drop the
* 'postgres' database.
*/
conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres", conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres",
host, port, username, prompt_password, progname); host, port, username, prompt_password, progname);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment