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

Commitc03aa1f

Browse files
committed
> 1) I'm proposing a patch to do the DROP FUNCTION argument tab completion.
> Now, the arguments of the drop function can be tab completed. for example>> drop function strpos (> <press tab>> drop FUNCTION strpos (text, text)>> or:>> wsdb=# drop FUNCTION length (> bit) bytea) character) lseg) path) text)> <press c>> wsdb# DROP FUNCTION length ( character)>> I think that this patch should be rather useful. At it least I hate> always to type all the arguments of the dropped functions.>> 2) Also some fixes applied for the> CREATE INDEX syntax>> now the parenthesises are inserted by tab pressing.> suppose I have the table q3c:Sergey E. Koposov
1 parent2986f42 commitc03aa1f

File tree

1 file changed

+70
-6
lines changed

1 file changed

+70
-6
lines changed

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

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.141 2005/11/18 16:31:11 alvherre Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.142 2005/12/08 21:33:58 momjian Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -476,6 +476,8 @@ static PGresult *exec_query(const char *query);
476476

477477
staticchar*previous_word(intpoint,intskip);
478478

479+
staticintfind_open_parenthesis(intend);
480+
479481
#if0
480482
staticchar*quote_file_name(char*text,intmatch_type,char*quote_pointer);
481483
staticchar*dequote_file_name(char*text,charquote_char);
@@ -1016,7 +1018,16 @@ psql_completion(char *text, int start, int end)
10161018
*/
10171019
elseif (pg_strcasecmp(prev4_wd,"INDEX")==0&&
10181020
pg_strcasecmp(prev2_wd,"ON")==0)
1019-
COMPLETE_WITH_ATTR(prev_wd);
1021+
{
1022+
if (find_open_parenthesis(end))
1023+
COMPLETE_WITH_ATTR(prev_wd);
1024+
else
1025+
COMPLETE_WITH_CONST("(");
1026+
}
1027+
elseif (pg_strcasecmp(prev5_wd,"INDEX")==0&&
1028+
pg_strcasecmp(prev3_wd,"ON")==0&&
1029+
pg_strcasecmp(prev_wd,"(")==0)
1030+
COMPLETE_WITH_ATTR(prev2_wd);
10201031
/* same if you put in USING */
10211032
elseif (pg_strcasecmp(prev4_wd,"ON")==0&&
10221033
pg_strcasecmp(prev2_wd,"USING")==0)
@@ -1222,11 +1233,42 @@ psql_completion(char *text, int start, int end)
12221233
pg_strcasecmp(prev3_wd,"AGGREGATE")==0&&
12231234
prev_wd[strlen(prev_wd)-1]==')'))
12241235
{
1225-
staticconstchar*constlist_DROPCR[]=
1226-
{"CASCADE","RESTRICT",NULL};
1227-
1228-
COMPLETE_WITH_LIST(list_DROPCR);
1236+
1237+
if ((pg_strcasecmp(prev3_wd,"DROP")==0)&& (pg_strcasecmp(prev2_wd,"FUNCTION")==0))
1238+
{
1239+
if (find_open_parenthesis(end))
1240+
{
1241+
staticconstcharfunc_args_query[]="select pg_catalog.oidvectortypes(proargtypes)||')' from pg_proc where proname='%s'";
1242+
char*tmp_buf=malloc(strlen(func_args_query)+strlen(prev_wd));
1243+
sprintf(tmp_buf,func_args_query,prev_wd);
1244+
COMPLETE_WITH_QUERY(tmp_buf);
1245+
free(tmp_buf);
1246+
}
1247+
else
1248+
{
1249+
COMPLETE_WITH_CONST("(");
1250+
}
1251+
}
1252+
else
1253+
{
1254+
staticconstchar*constlist_DROPCR[]=
1255+
{"CASCADE","RESTRICT",NULL};
1256+
1257+
COMPLETE_WITH_LIST(list_DROPCR);
1258+
}
12291259
}
1260+
elseif (pg_strcasecmp(prev4_wd,"DROP")==0&&
1261+
pg_strcasecmp(prev3_wd,"FUNCTION")==0&&
1262+
pg_strcasecmp(prev_wd,"(")==0 )
1263+
{
1264+
staticconstcharfunc_args_query[]="select pg_catalog.oidvectortypes(proargtypes)||')' from pg_proc where proname='%s'";
1265+
char*tmp_buf=malloc(strlen(func_args_query)+strlen(prev2_wd));
1266+
sprintf(tmp_buf,func_args_query,prev2_wd);
1267+
COMPLETE_WITH_QUERY(tmp_buf);
1268+
free(tmp_buf);
1269+
}
1270+
1271+
12301272

12311273
/* EXPLAIN */
12321274

@@ -2247,7 +2289,29 @@ previous_word(int point, int skip)
22472289
returns;
22482290
}
22492291

2292+
/* Find the parenthesis after the last word */
2293+
22502294

2295+
staticintfind_open_parenthesis(intend)
2296+
{
2297+
inti=end-1;
2298+
2299+
while((rl_line_buffer[i]!=' ')&&(i>=0))
2300+
{
2301+
if (rl_line_buffer[i]=='(')return1;
2302+
i--;
2303+
}
2304+
while((rl_line_buffer[i]==' ')&&(i>=0))
2305+
{
2306+
i--;
2307+
}
2308+
if (rl_line_buffer[i]=='(')
2309+
{
2310+
return1;
2311+
}
2312+
return0;
2313+
2314+
}
22512315

22522316
#if0
22532317

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp