Skip to content

Commit c03aa1f

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 parent 2986f42 commit c03aa1f

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
static char *previous_word(int point, int skip);
478478

479+
static int find_open_parenthesis(int end);
480+
479481
#if 0
480482
static char *quote_file_name(char *text, int match_type, char *quote_pointer);
481483
static char *dequote_file_name(char *text, char quote_char);
@@ -1016,7 +1018,16 @@ psql_completion(char *text, int start, int end)
10161018
*/
10171019
else if (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+
else if (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
else if (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-
static const char *const list_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+
static const char func_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+
static const char *const list_DROPCR[] =
1255+
{"CASCADE", "RESTRICT", NULL};
1256+
1257+
COMPLETE_WITH_LIST(list_DROPCR);
1258+
}
12291259
}
1260+
else if (pg_strcasecmp(prev4_wd, "DROP") == 0 &&
1261+
pg_strcasecmp(prev3_wd, "FUNCTION") == 0 &&
1262+
pg_strcasecmp(prev_wd, "(") == 0 )
1263+
{
1264+
static const char func_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
return s;
22482290
}
22492291

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

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

22522316
#if 0
22532317

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy