Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb884f62

Browse files
committed
Sync listDbRoleSettings() with the rest of the world.
listDbRoleSettings() handled its server version check randomly differentlyfrom every other comparable function in describe.c, not only as to codelayout but also message wording. It also leaked memory, because itsPQExpBuffer 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 indescribe.c --- we usually put "/*" alone on a line.Daniel Gustafsson, memory leak fixes by meDiscussion:https://postgr.es/m/3641F19B-336A-431A-86CE-A80562505C5E@yesql.se
1 parentdc4da3d commitb884f62

File tree

1 file changed

+44
-33
lines changed

1 file changed

+44
-33
lines changed

‎src/bin/psql/describe.c

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ static bool listOneExtensionContents(const char *extname, const char *oid);
5454
*/
5555

5656

57-
/* \da
57+
/*
58+
* \da
5859
* Takes an optional regexp to select particular aggregates
5960
*/
6061
bool
@@ -131,7 +132,8 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem)
131132
return true;
132133
}
133134

134-
/* \dA
135+
/*
136+
* \dA
135137
* Takes an optional regexp to select particular access methods
136138
*/
137139
bool
@@ -198,7 +200,8 @@ describeAccessMethods(const char *pattern, bool verbose)
198200
return true;
199201
}
200202

201-
/* \db
203+
/*
204+
* \db
202205
* Takes an optional regexp to select particular tablespaces
203206
*/
204207
bool
@@ -283,7 +286,8 @@ describeTablespaces(const char *pattern, bool verbose)
283286
}
284287

285288

286-
/* \df
289+
/*
290+
* \df
287291
* Takes an optional regexp to select particular functions.
288292
*
289293
* As with \d, you can specify the kinds of functions you want:
@@ -696,7 +700,8 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
696700
}
697701

698702

699-
/* \do
703+
/*
704+
* \do
700705
* Describe operators
701706
*/
702707
bool
@@ -2997,7 +3002,10 @@ add_tablespace_footer(printTableContent *const cont, char relkind,
29973002
"WHERE oid = '%u';",tablespace);
29983003
result=PSQLexec(buf.data);
29993004
if (!result)
3005+
{
3006+
termPQExpBuffer(&buf);
30003007
return;
3008+
}
30013009
/* Should always be the case, but.... */
30023010
if (PQntuples(result)>0)
30033011
{
@@ -3209,35 +3217,36 @@ listDbRoleSettings(const char *pattern, const char *pattern2)
32093217
PQExpBufferDatabuf;
32103218
PGresult*res;
32113219
printQueryOptmyopt=pset.popt;
3220+
boolhavewhere;
32123221

3213-
initPQExpBuffer(&buf);
3214-
3215-
if (pset.sversion >=90000)
3216-
{
3217-
boolhavewhere;
3218-
3219-
printfPQExpBuffer(&buf,"SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3220-
"pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3221-
"FROM pg_catalog.pg_db_role_setting s\n"
3222-
"LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3223-
"LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3224-
gettext_noop("Role"),
3225-
gettext_noop("Database"),
3226-
gettext_noop("Settings"));
3227-
havewhere=processSQLNamePattern(pset.db,&buf,pattern, false, false,
3228-
NULL,"r.rolname",NULL,NULL);
3229-
processSQLNamePattern(pset.db,&buf,pattern2,havewhere, false,
3230-
NULL,"d.datname",NULL,NULL);
3231-
appendPQExpBufferStr(&buf,"ORDER BY 1, 2;");
3232-
}
3233-
else
3222+
if (pset.sversion<90000)
32343223
{
3235-
fprintf(pset.queryFout,
3236-
_("No per-database role settings support in this server version.\n"));
3237-
return false;
3224+
charsverbuf[32];
3225+
3226+
psql_error("The server (version %s) does not support per-database role settings.\n",
3227+
formatPGVersionNumber(pset.sversion, false,
3228+
sverbuf,sizeof(sverbuf)));
3229+
return true;
32383230
}
32393231

3232+
initPQExpBuffer(&buf);
3233+
3234+
printfPQExpBuffer(&buf,"SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3235+
"pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3236+
"FROM pg_catalog.pg_db_role_setting s\n"
3237+
"LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3238+
"LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3239+
gettext_noop("Role"),
3240+
gettext_noop("Database"),
3241+
gettext_noop("Settings"));
3242+
havewhere=processSQLNamePattern(pset.db,&buf,pattern, false, false,
3243+
NULL,"r.rolname",NULL,NULL);
3244+
processSQLNamePattern(pset.db,&buf,pattern2,havewhere, false,
3245+
NULL,"d.datname",NULL,NULL);
3246+
appendPQExpBufferStr(&buf,"ORDER BY 1, 2;");
3247+
32403248
res=PSQLexec(buf.data);
3249+
termPQExpBuffer(&buf);
32413250
if (!res)
32423251
return false;
32433252

@@ -3258,7 +3267,6 @@ listDbRoleSettings(const char *pattern, const char *pattern2)
32583267
}
32593268

32603269
PQclear(res);
3261-
resetPQExpBuffer(&buf);
32623270
return true;
32633271
}
32643272

@@ -5024,7 +5032,8 @@ listOneExtensionContents(const char *extname, const char *oid)
50245032
return true;
50255033
}
50265034

5027-
/* \dRp
5035+
/*
5036+
* \dRp
50285037
* Lists publications.
50295038
*
50305039
* Takes an optional regexp to select particular publications
@@ -5090,7 +5099,8 @@ listPublications(const char *pattern)
50905099
return true;
50915100
}
50925101

5093-
/* \dRp+
5102+
/*
5103+
* \dRp+
50945104
* Describes publications including the contents.
50955105
*
50965106
* Takes an optional regexp to select particular publications
@@ -5211,7 +5221,8 @@ describePublications(const char *pattern)
52115221
return true;
52125222
}
52135223

5214-
/* \dRs
5224+
/*
5225+
* \dRs
52155226
* Describes subscriptions.
52165227
*
52175228
* Takes an optional regexp to select particular subscriptions

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp