Skip to content

Commit 6dfcefe

Browse files
nathan-bossarthackorum
authored andcommitted
remove VersionedQuery support from psql tab completion
1 parent 44056f6 commit 6dfcefe

1 file changed

Lines changed: 45 additions & 105 deletions

File tree

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

Lines changed: 45 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,6 @@
9292
*/
9393
PQExpBuffer tab_completion_query_buf = NULL;
9494

95-
/*
96-
* In some situations, the query to find out what names are available to
97-
* complete with must vary depending on server version. We handle this by
98-
* storing a list of queries, each tagged with the minimum server version
99-
* it will work for. Each list must be stored in descending server version
100-
* order, so that the first satisfactory query is the one to use.
101-
*
102-
* When the query string is otherwise constant, an array of VersionedQuery
103-
* suffices. Terminate the array with an entry having min_server_version = 0.
104-
* That entry's query string can be a query that works in all supported older
105-
* server versions, or NULL to give up and do no completion.
106-
*/
107-
typedef struct VersionedQuery
108-
{
109-
int min_server_version;
110-
const char *query;
111-
} VersionedQuery;
112-
11395
/*
11496
* This struct is used to define "schema queries", which are custom-built
11597
* to obtain possibly-schema-qualified names of database objects. There is
@@ -123,8 +105,7 @@ typedef struct VersionedQuery
123105
* objects we're completing might not have a schema of their own, but the
124106
* reference object almost always does (passed in completion_ref_schema).
125107
*
126-
* As with VersionedQuery, we can use an array of these if the query details
127-
* must vary across versions.
108+
* We can use an array of these if the query details must vary across versions.
128109
*/
129110
typedef struct SchemaQuery
130111
{
@@ -225,7 +206,6 @@ static int completion_max_records;
225206
static char completion_last_char; /* last char of input word */
226207
static const char *completion_charp; /* to pass a string */
227208
static const char *const *completion_charpp; /* to pass a list of strings */
228-
static const VersionedQuery *completion_vquery; /* to pass a VersionedQuery */
229209
static const SchemaQuery *completion_squery; /* to pass a SchemaQuery */
230210
static char *completion_ref_object; /* name of reference object */
231211
static char *completion_ref_schema; /* schema name of reference object */
@@ -237,7 +217,6 @@ static bool completion_force_quote; /* true to force-quote filenames */
237217
* A few macros to ease typing. You can use these to complete the given
238218
* string with
239219
* 1) The result from a query you pass it. (Perhaps one of those below?)
240-
* We support both simple and versioned queries.
241220
* 2) The result from a schema query you pass it.
242221
* We support both simple and versioned schema queries.
243222
* 3) The items from a null-pointer-terminated list (with or without
@@ -288,23 +267,6 @@ do { \
288267
COMPLETE_WITH_QUERY_VERBATIM_LIST(query, list); \
289268
} while (0)
290269

291-
#define COMPLETE_WITH_VERSIONED_QUERY(query) \
292-
COMPLETE_WITH_VERSIONED_QUERY_LIST(query, NULL)
293-
294-
#define COMPLETE_WITH_VERSIONED_QUERY_LIST(query, list) \
295-
do { \
296-
completion_vquery = query; \
297-
completion_charpp = list; \
298-
completion_verbatim = false; \
299-
matches = rl_completion_matches(text, complete_from_versioned_query); \
300-
} while (0)
301-
302-
#define COMPLETE_WITH_VERSIONED_QUERY_PLUS(query, ...) \
303-
do { \
304-
static const char *const list[] = { __VA_ARGS__, NULL }; \
305-
COMPLETE_WITH_VERSIONED_QUERY_LIST(query, list); \
306-
} while (0)
307-
308270
#define COMPLETE_WITH_SCHEMA_QUERY(query) \
309271
COMPLETE_WITH_SCHEMA_QUERY_LIST(query, NULL)
310272

@@ -1278,9 +1240,8 @@ static const char *const sql_commands[] = {
12781240
typedef struct
12791241
{
12801242
const char *name;
1281-
/* Provide at most one of these three types of query: */
1243+
/* Provide at most one of these two types of query: */
12821244
const char *query; /* simple query, or NULL */
1283-
const VersionedQuery *vquery; /* versioned query, or NULL */
12841245
const SchemaQuery *squery; /* schema query, or NULL */
12851246
const char *const *keywords; /* keywords to be offered as well */
12861247
const uint32 flags; /* visibility flags, see below */
@@ -1298,68 +1259,68 @@ static const char *const Keywords_for_user_thing[] = {
12981259
};
12991260

13001261
static const pgsql_thing_t words_after_create[] = {
1301-
{"ACCESS METHOD", NULL, NULL, NULL, NULL, THING_NO_ALTER},
1302-
{"AGGREGATE", NULL, NULL, Query_for_list_of_aggregates},
1303-
{"CAST", NULL, NULL, NULL}, /* Casts have complex structures for names, so
1262+
{"ACCESS METHOD", NULL, NULL, NULL, THING_NO_ALTER},
1263+
{"AGGREGATE", NULL, Query_for_list_of_aggregates},
1264+
{"CAST", NULL, NULL}, /* Casts have complex structures for names, so
13041265
* skip it */
1305-
{"COLLATION", NULL, NULL, &Query_for_list_of_collations},
1266+
{"COLLATION", NULL, &Query_for_list_of_collations},
13061267

13071268
/*
13081269
* CREATE CONSTRAINT TRIGGER is not supported here because it is designed
13091270
* to be used only by pg_dump.
13101271
*/
1311-
{"CONFIGURATION", NULL, NULL, &Query_for_list_of_ts_configurations, NULL, THING_NO_SHOW},
1272+
{"CONFIGURATION", NULL, &Query_for_list_of_ts_configurations, NULL, THING_NO_SHOW},
13121273
{"CONVERSION", "SELECT conname FROM pg_catalog.pg_conversion WHERE conname LIKE '%s'"},
13131274
{"DATABASE", Query_for_list_of_databases},
1314-
{"DEFAULT PRIVILEGES", NULL, NULL, NULL, NULL, THING_NO_CREATE | THING_NO_DROP},
1315-
{"DICTIONARY", NULL, NULL, &Query_for_list_of_ts_dictionaries, NULL, THING_NO_SHOW},
1316-
{"DOMAIN", NULL, NULL, &Query_for_list_of_domains},
1317-
{"EVENT TRIGGER", NULL, NULL, NULL},
1275+
{"DEFAULT PRIVILEGES", NULL, NULL, NULL, THING_NO_CREATE | THING_NO_DROP},
1276+
{"DICTIONARY", NULL, &Query_for_list_of_ts_dictionaries, NULL, THING_NO_SHOW},
1277+
{"DOMAIN", NULL, &Query_for_list_of_domains},
1278+
{"EVENT TRIGGER", NULL, NULL},
13181279
{"EXTENSION", Query_for_list_of_extensions},
1319-
{"FOREIGN DATA WRAPPER", NULL, NULL, NULL},
1320-
{"FOREIGN TABLE", NULL, NULL, NULL},
1321-
{"FUNCTION", NULL, NULL, Query_for_list_of_functions},
1280+
{"FOREIGN DATA WRAPPER", NULL, NULL},
1281+
{"FOREIGN TABLE", NULL, NULL},
1282+
{"FUNCTION", NULL, Query_for_list_of_functions},
13221283
{"GROUP", Query_for_list_of_roles},
1323-
{"INDEX", NULL, NULL, &Query_for_list_of_indexes},
1284+
{"INDEX", NULL, &Query_for_list_of_indexes},
13241285
{"LANGUAGE", Query_for_list_of_languages},
1325-
{"LARGE OBJECT", NULL, NULL, NULL, NULL, THING_NO_CREATE | THING_NO_DROP},
1326-
{"MATERIALIZED VIEW", NULL, NULL, &Query_for_list_of_matviews},
1327-
{"OPERATOR", NULL, NULL, NULL}, /* Querying for this is probably not such
1328-
* a good idea. */
1329-
{"OR REPLACE", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER},
1330-
{"OWNED", NULL, NULL, NULL, NULL, THING_NO_CREATE | THING_NO_ALTER}, /* for DROP OWNED BY ... */
1331-
{"PARSER", NULL, NULL, &Query_for_list_of_ts_parsers, NULL, THING_NO_SHOW},
1332-
{"POLICY", NULL, NULL, NULL},
1333-
{"PROCEDURE", NULL, NULL, Query_for_list_of_procedures},
1334-
{"PROPERTY GRAPH", NULL, NULL, &Query_for_list_of_propgraphs},
1286+
{"LARGE OBJECT", NULL, NULL, NULL, THING_NO_CREATE | THING_NO_DROP},
1287+
{"MATERIALIZED VIEW", NULL, &Query_for_list_of_matviews},
1288+
{"OPERATOR", NULL, NULL}, /* Querying for this is probably not such a
1289+
* good idea. */
1290+
{"OR REPLACE", NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER},
1291+
{"OWNED", NULL, NULL, NULL, THING_NO_CREATE | THING_NO_ALTER}, /* for DROP OWNED BY ... */
1292+
{"PARSER", NULL, &Query_for_list_of_ts_parsers, NULL, THING_NO_SHOW},
1293+
{"POLICY", NULL, NULL},
1294+
{"PROCEDURE", NULL, Query_for_list_of_procedures},
1295+
{"PROPERTY GRAPH", NULL, &Query_for_list_of_propgraphs},
13351296
{"PUBLICATION", Query_for_list_of_publications},
13361297
{"ROLE", Query_for_list_of_roles},
1337-
{"ROUTINE", NULL, NULL, &Query_for_list_of_routines, NULL, THING_NO_CREATE},
1298+
{"ROUTINE", NULL, &Query_for_list_of_routines, NULL, THING_NO_CREATE},
13381299
{"RULE", "SELECT rulename FROM pg_catalog.pg_rules WHERE rulename LIKE '%s'"},
13391300
{"SCHEMA", Query_for_list_of_schemas},
1340-
{"SEQUENCE", NULL, NULL, &Query_for_list_of_sequences},
1301+
{"SEQUENCE", NULL, &Query_for_list_of_sequences},
13411302
{"SERVER", Query_for_list_of_servers},
1342-
{"STATISTICS", NULL, NULL, &Query_for_list_of_statistics},
1303+
{"STATISTICS", NULL, &Query_for_list_of_statistics},
13431304
{"SUBSCRIPTION", Query_for_list_of_subscriptions},
1344-
{"SYSTEM", NULL, NULL, NULL, NULL, THING_NO_CREATE | THING_NO_DROP},
1345-
{"TABLE", NULL, NULL, &Query_for_list_of_tables},
1305+
{"SYSTEM", NULL, NULL, NULL, THING_NO_CREATE | THING_NO_DROP},
1306+
{"TABLE", NULL, &Query_for_list_of_tables},
13461307
{"TABLESPACE", Query_for_list_of_tablespaces},
1347-
{"TEMP", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE TEMP TABLE
1348-
* ... */
1349-
{"TEMPLATE", NULL, NULL, &Query_for_list_of_ts_templates, NULL, THING_NO_SHOW},
1350-
{"TEMPORARY", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE TEMPORARY
1351-
* TABLE ... */
1352-
{"TEXT SEARCH", NULL, NULL, NULL},
1353-
{"TRANSFORM", NULL, NULL, NULL, NULL, THING_NO_ALTER},
1308+
{"TEMP", NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE TEMP TABLE
1309+
* ... */
1310+
{"TEMPLATE", NULL, &Query_for_list_of_ts_templates, NULL, THING_NO_SHOW},
1311+
{"TEMPORARY", NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE TEMPORARY
1312+
* TABLE ... */
1313+
{"TEXT SEARCH", NULL, NULL},
1314+
{"TRANSFORM", NULL, NULL, NULL, THING_NO_ALTER},
13541315
{"TRIGGER", "SELECT tgname FROM pg_catalog.pg_trigger WHERE tgname LIKE '%s' AND NOT tgisinternal"},
1355-
{"TYPE", NULL, NULL, &Query_for_list_of_datatypes},
1356-
{"UNIQUE", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE UNIQUE
1357-
* INDEX ... */
1358-
{"UNLOGGED", NULL, NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE UNLOGGED
1359-
* TABLE ... */
1360-
{"USER", Query_for_list_of_roles, NULL, NULL, Keywords_for_user_thing},
1361-
{"USER MAPPING FOR", NULL, NULL, NULL},
1362-
{"VIEW", NULL, NULL, &Query_for_list_of_views},
1316+
{"TYPE", NULL, &Query_for_list_of_datatypes},
1317+
{"UNIQUE", NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE UNIQUE
1318+
* INDEX ... */
1319+
{"UNLOGGED", NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE UNLOGGED
1320+
* TABLE ... */
1321+
{"USER", Query_for_list_of_roles, NULL, Keywords_for_user_thing},
1322+
{"USER MAPPING FOR", NULL, NULL},
1323+
{"VIEW", NULL, &Query_for_list_of_views},
13631324
{NULL} /* end of list */
13641325
};
13651326

@@ -1475,7 +1436,6 @@ static char *create_command_generator(const char *text, int state);
14751436
static char *drop_command_generator(const char *text, int state);
14761437
static char *alter_command_generator(const char *text, int state);
14771438
static char *complete_from_query(const char *text, int state);
1478-
static char *complete_from_versioned_query(const char *text, int state);
14791439
static char *complete_from_schema_query(const char *text, int state);
14801440
static char *complete_from_versioned_schema_query(const char *text, int state);
14811441
static char *_complete_from_query(const char *simple_query,
@@ -1967,7 +1927,6 @@ psql_completion(const char *text, int start, int end)
19671927
/* Clear a few things. */
19681928
completion_charp = NULL;
19691929
completion_charpp = NULL;
1970-
completion_vquery = NULL;
19711930
completion_squery = NULL;
19721931
completion_ref_object = NULL;
19731932
completion_ref_schema = NULL;
@@ -2098,9 +2057,6 @@ psql_completion(const char *text, int start, int end)
20982057
if (wac->query)
20992058
COMPLETE_WITH_QUERY_LIST(wac->query,
21002059
wac->keywords);
2101-
else if (wac->vquery)
2102-
COMPLETE_WITH_VERSIONED_QUERY_LIST(wac->vquery,
2103-
wac->keywords);
21042060
else if (wac->squery)
21052061
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY_LIST(wac->squery,
21062062
wac->keywords);
@@ -5931,22 +5887,6 @@ complete_from_query(const char *text, int state)
59315887
completion_verbatim, text, state);
59325888
}
59335889

5934-
static char *
5935-
complete_from_versioned_query(const char *text, int state)
5936-
{
5937-
const VersionedQuery *vquery = completion_vquery;
5938-
5939-
/* Find appropriate array element */
5940-
while (pset.sversion < vquery->min_server_version)
5941-
vquery++;
5942-
/* Fail completion if server is too old */
5943-
if (vquery->query == NULL)
5944-
return NULL;
5945-
5946-
return _complete_from_query(vquery->query, NULL, completion_charpp,
5947-
completion_verbatim, text, state);
5948-
}
5949-
59505890
static char *
59515891
complete_from_schema_query(const char *text, int state)
59525892
{

0 commit comments

Comments
 (0)