diff options
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r-- | src/bin/psql/command.c | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index a12d311b2e0..1441fbc0bcc 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -1,9 +1,9 @@ /* * psql - the PostgreSQL interactive terminal * - * Copyright 2000 by PostgreSQL Global Development Team + * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.15 2000/01/23 01:27:37 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.16 2000/01/29 16:58:48 petere Exp $ */ #include <c.h> #include "command.h" @@ -361,7 +361,7 @@ exec_command(const char *cmd, switch (cmd[1]) { case '\0': - case '?': + case '+': if (options[0]) success = describeTableDetails(options[0], show_verbose); else @@ -992,12 +992,42 @@ do_connect(const char *new_dbname, const char *new_user) SetVariable(pset.vars, "HOST", PQhost(pset.db)); SetVariable(pset.vars, "PORT", PQport(pset.db)); + pset.issuper = test_superuser(PQuser(pset.db)); + return success; } /* + * Test if the given user is a database superuser. + * (Used to set up the prompt right.) + */ +bool +test_superuser(const char * username) +{ + PGresult *res; + char buf[64 + NAMEDATALEN]; + bool answer; + + if (!username) + return false; + + sprintf(buf, "SELECT usesuper FROM pg_user WHERE usename = '%.*s'", NAMEDATALEN, username); + res = PSQLexec(buf); + + answer = + (PQntuples(res)>0 && PQnfields(res)>0 + && !PQgetisnull(res,0,0) + && PQgetvalue(res,0,0) + && strcmp(PQgetvalue(res,0,0), "t")==0); + PQclear(res); + return answer; +} + + + +/* * do_edit -- handler for \e * * If you do not specify a filename, the current query buffer will be copied |