Commit b884f629 authored by Tom Lane's avatar Tom Lane

Sync listDbRoleSettings() with the rest of the world.

listDbRoleSettings() handled its server version check randomly differently
from every other comparable function in describe.c, not only as to code
layout but also message wording.  It also leaked memory, because its
PQExpBuffer management was also unlike everyplace else (and wrong).

Also fix an error-case leak in add_tablespace_footer().

In passing, standardize the format of function header comments in
describe.c --- we usually put "/*" alone on a line.

Daniel Gustafsson, memory leak fixes by me

Discussion: https://postgr.es/m/3641F19B-336A-431A-86CE-A80562505C5E@yesql.se
parent dc4da3dc
...@@ -54,7 +54,8 @@ static bool listOneExtensionContents(const char *extname, const char *oid); ...@@ -54,7 +54,8 @@ static bool listOneExtensionContents(const char *extname, const char *oid);
*/ */
/* \da /*
* \da
* Takes an optional regexp to select particular aggregates * Takes an optional regexp to select particular aggregates
*/ */
bool bool
...@@ -131,7 +132,8 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem) ...@@ -131,7 +132,8 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem)
return true; return true;
} }
/* \dA /*
* \dA
* Takes an optional regexp to select particular access methods * Takes an optional regexp to select particular access methods
*/ */
bool bool
...@@ -198,7 +200,8 @@ describeAccessMethods(const char *pattern, bool verbose) ...@@ -198,7 +200,8 @@ describeAccessMethods(const char *pattern, bool verbose)
return true; return true;
} }
/* \db /*
* \db
* Takes an optional regexp to select particular tablespaces * Takes an optional regexp to select particular tablespaces
*/ */
bool bool
...@@ -283,7 +286,8 @@ describeTablespaces(const char *pattern, bool verbose) ...@@ -283,7 +286,8 @@ describeTablespaces(const char *pattern, bool verbose)
} }
/* \df /*
* \df
* Takes an optional regexp to select particular functions. * Takes an optional regexp to select particular functions.
* *
* As with \d, you can specify the kinds of functions you want: * As with \d, you can specify the kinds of functions you want:
...@@ -696,7 +700,8 @@ describeTypes(const char *pattern, bool verbose, bool showSystem) ...@@ -696,7 +700,8 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
} }
/* \do /*
* \do
* Describe operators * Describe operators
*/ */
bool bool
...@@ -2997,7 +3002,10 @@ add_tablespace_footer(printTableContent *const cont, char relkind, ...@@ -2997,7 +3002,10 @@ add_tablespace_footer(printTableContent *const cont, char relkind,
"WHERE oid = '%u';", tablespace); "WHERE oid = '%u';", tablespace);
result = PSQLexec(buf.data); result = PSQLexec(buf.data);
if (!result) if (!result)
{
termPQExpBuffer(&buf);
return; return;
}
/* Should always be the case, but.... */ /* Should always be the case, but.... */
if (PQntuples(result) > 0) if (PQntuples(result) > 0)
{ {
...@@ -3209,12 +3217,19 @@ listDbRoleSettings(const char *pattern, const char *pattern2) ...@@ -3209,12 +3217,19 @@ listDbRoleSettings(const char *pattern, const char *pattern2)
PQExpBufferData buf; PQExpBufferData buf;
PGresult *res; PGresult *res;
printQueryOpt myopt = pset.popt; printQueryOpt myopt = pset.popt;
bool havewhere;
initPQExpBuffer(&buf); if (pset.sversion < 90000)
if (pset.sversion >= 90000)
{ {
bool havewhere; char sverbuf[32];
psql_error("The server (version %s) does not support per-database role settings.\n",
formatPGVersionNumber(pset.sversion, false,
sverbuf, sizeof(sverbuf)));
return true;
}
initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n" printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
"pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n" "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
...@@ -3229,15 +3244,9 @@ listDbRoleSettings(const char *pattern, const char *pattern2) ...@@ -3229,15 +3244,9 @@ listDbRoleSettings(const char *pattern, const char *pattern2)
processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false, processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
NULL, "d.datname", NULL, NULL); NULL, "d.datname", NULL, NULL);
appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
}
else
{
fprintf(pset.queryFout,
_("No per-database role settings support in this server version.\n"));
return false;
}
res = PSQLexec(buf.data); res = PSQLexec(buf.data);
termPQExpBuffer(&buf);
if (!res) if (!res)
return false; return false;
...@@ -3258,7 +3267,6 @@ listDbRoleSettings(const char *pattern, const char *pattern2) ...@@ -3258,7 +3267,6 @@ listDbRoleSettings(const char *pattern, const char *pattern2)
} }
PQclear(res); PQclear(res);
resetPQExpBuffer(&buf);
return true; return true;
} }
...@@ -5024,7 +5032,8 @@ listOneExtensionContents(const char *extname, const char *oid) ...@@ -5024,7 +5032,8 @@ listOneExtensionContents(const char *extname, const char *oid)
return true; return true;
} }
/* \dRp /*
* \dRp
* Lists publications. * Lists publications.
* *
* Takes an optional regexp to select particular publications * Takes an optional regexp to select particular publications
...@@ -5090,7 +5099,8 @@ listPublications(const char *pattern) ...@@ -5090,7 +5099,8 @@ listPublications(const char *pattern)
return true; return true;
} }
/* \dRp+ /*
* \dRp+
* Describes publications including the contents. * Describes publications including the contents.
* *
* Takes an optional regexp to select particular publications * Takes an optional regexp to select particular publications
...@@ -5211,7 +5221,8 @@ describePublications(const char *pattern) ...@@ -5211,7 +5221,8 @@ describePublications(const char *pattern)
return true; return true;
} }
/* \dRs /*
* \dRs
* Describes subscriptions. * Describes subscriptions.
* *
* Takes an optional regexp to select particular subscriptions * Takes an optional regexp to select particular subscriptions
......
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