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

Commit2022d59

Browse files
committed
Fix tab completion in psql for ALTER DEFAULT PRIVILEGES
When providing tab completion for ALTER DEFAULT PRIVILEGES, we areincluding the list of roles as possible options for completion after theGRANT or REVOKE. Further, we accept FOR ROLE/IN SCHEMA at the same timeand in either order, but the tab completion was only working for one orthe other. Lastly, we weren't using the actual list of allowed kinds ofobjects for default privileges for completion after the 'GRANT X ON' butinstead were completeing to what 'GRANT X ON' supports, which isn't thessame at all.Address these issues by improving the forward tab-completion for ALTERDEFAULT PRIVILEGES and then constrain and correct how the tailcompletion is done when it is for ALTER DEFAULT PRIVILEGES.Back-patch the forward/tail tab-completion to 9.6, where we made it easyto handle such cases.For 9.5 and earlier, correct the initial tab-completion to at least becorrect as far as it goes and then add a check for GRANT/REVOKE to onlytab-complete when the GRANT/REVOKE is the start of the command, so wedon't try to do tab-completion after we get to the GRANT/REVOKE part ofthe ALTER DEFAULT PRIVILEGES command, which is better than providingincorrect completions.Initial patch for master and 9.6 by Gilles Darold, though I cleaned itup and added a few comments. All bugs in the 9.5 and earlier patch aremine.Discussion:https://www.postgresql.org/message-id/1614593c-e356-5b27-6dba-66320a9bc68b@dalibo.com
1 parent0e3aadb commit2022d59

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

‎src/bin/psql/tab-complete.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ psql_completion(char *text, int start, int end)
11871187
pg_strcasecmp(prev_wd,"PRIVILEGES")==0)
11881188
{
11891189
staticconstchar*constlist_ALTER_DEFAULT_PRIVILEGES[]=
1190-
{"FOR ROLE","FOR USER","IN SCHEMA",NULL};
1190+
{"FOR ROLE","IN SCHEMA",NULL};
11911191

11921192
COMPLETE_WITH_LIST(list_ALTER_DEFAULT_PRIVILEGES);
11931193
}
@@ -1197,19 +1197,26 @@ psql_completion(char *text, int start, int end)
11971197
pg_strcasecmp(prev2_wd,"PRIVILEGES")==0&&
11981198
pg_strcasecmp(prev_wd,"FOR")==0)
11991199
{
1200-
staticconstchar*constlist_ALTER_DEFAULT_PRIVILEGES_FOR[]=
1201-
{"ROLE","USER",NULL};
1200+
COMPLETE_WITH_CONST("ROLE");
1201+
}
1202+
/* ALTER DEFAULT PRIVILEGES FOR ROLE ... } */
1203+
elseif (pg_strcasecmp(prev5_wd,"DEFAULT")==0&&
1204+
pg_strcasecmp(prev4_wd,"PRIVILEGES")==0&&
1205+
pg_strcasecmp(prev3_wd,"FOR")==0)
1206+
{
1207+
staticconstchar*constlist_ALTER_DEFAULT_PRIVILEGES_REST[]=
1208+
{"GRANT","REVOKE","IN SCHEMA",NULL};
12021209

1203-
COMPLETE_WITH_LIST(list_ALTER_DEFAULT_PRIVILEGES_FOR);
1210+
COMPLETE_WITH_LIST(list_ALTER_DEFAULT_PRIVILEGES_REST);
12041211
}
1205-
/* ALTER DEFAULT PRIVILEGES{ FOR ROLE ... |IN SCHEMA ... } */
1212+
/* ALTER DEFAULT PRIVILEGES IN SCHEMA ... } */
12061213
elseif (pg_strcasecmp(prev5_wd,"DEFAULT")==0&&
12071214
pg_strcasecmp(prev4_wd,"PRIVILEGES")==0&&
1208-
(pg_strcasecmp(prev3_wd,"FOR")==0||
1209-
pg_strcasecmp(prev3_wd,"IN")==0))
1215+
pg_strcasecmp(prev3_wd,"IN")==0&&
1216+
pg_strcasecmp(prev2_wd,"SCHEMA")==0)
12101217
{
12111218
staticconstchar*constlist_ALTER_DEFAULT_PRIVILEGES_REST[]=
1212-
{"GRANT","REVOKE",NULL};
1219+
{"GRANT","REVOKE","FOR ROLE",NULL};
12131220

12141221
COMPLETE_WITH_LIST(list_ALTER_DEFAULT_PRIVILEGES_REST);
12151222
}
@@ -2579,8 +2586,9 @@ psql_completion(char *text, int start, int end)
25792586

25802587
/* GRANT && REVOKE */
25812588
/* Complete GRANT/REVOKE with a list of roles and privileges */
2582-
elseif (pg_strcasecmp(prev_wd,"GRANT")==0||
2583-
pg_strcasecmp(prev_wd,"REVOKE")==0)
2589+
elseif (prev2_wd[0]=='\0'&&
2590+
(pg_strcasecmp(prev_wd,"GRANT")==0||
2591+
pg_strcasecmp(prev_wd,"REVOKE")==0))
25842592
{
25852593
COMPLETE_WITH_QUERY(Query_for_list_of_roles
25862594
" UNION SELECT 'SELECT'"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp