]> granicus.if.org Git - postgresql/commitdiff
Avoid emitting empty role names in the GRANTED BY clause of GRANT ROLE
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 15 May 2007 20:20:29 +0000 (20:20 +0000)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 15 May 2007 20:20:29 +0000 (20:20 +0000)
when the grantor has been dropped.  This is a workaround for the fact
that we don't track the grantor as a shared dependency.

src/bin/pg_dump/pg_dumpall.c

index bd94e19cd1f5b62445e8b1fe4e38d4647c952154..e1d5a7755725d3bda7ab5aa94c42e145ccfbd735 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.69.2.1 2006/04/07 21:26:42 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.69.2.2 2007/05/15 20:20:29 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -555,8 +555,8 @@ dumpRoleMembership(PGconn *conn)
 
        res = executeQuery(conn, "SELECT ur.rolname AS roleid, "
                                           "um.rolname AS member, "
-                                          "ug.rolname AS grantor, "
-                                          "a.admin_option "
+                                          "a.admin_option, "
+                                          "ug.rolname AS grantor "
                                           "FROM pg_auth_members a "
                                           "LEFT JOIN pg_authid ur on ur.oid = a.roleid "
                                           "LEFT JOIN pg_authid um on um.oid = a.member "
@@ -570,14 +570,24 @@ dumpRoleMembership(PGconn *conn)
        {
                char       *roleid = PQgetvalue(res, i, 0);
                char       *member = PQgetvalue(res, i, 1);
-               char       *grantor = PQgetvalue(res, i, 2);
-               char       *option = PQgetvalue(res, i, 3);
+               char       *option = PQgetvalue(res, i, 2);
 
                printf("GRANT %s", fmtId(roleid));
                printf(" TO %s", fmtId(member));
                if (*option == 't')
                        printf(" WITH ADMIN OPTION");
-               printf(" GRANTED BY %s;\n", fmtId(grantor));
+
+               /*
+                * We don't track the grantor very carefully in the backend, so cope
+                * with the possibility that it has been dropped.
+                */
+               if (!PQgetisnull(res, i, 3))
+               {
+                       char    *grantor = PQgetvalue(res, i, 3);
+
+                       printf(" GRANTED BY %s", fmtId(grantor));
+               }
+               printf(";\n");
        }
 
        PQclear(res);