diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index a27be4d916..a9f4d8afca 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -167,6 +167,18 @@ static void checkWin32Codepage(void); #endif +typedef struct descCommand +{ + const char *command; + bool (*func)(const char *, bool); +} descCommand; + +static const descCommand desc_commands[] = { + {"describe-tablespace", describeTablespaces}, + {"describe-access-methods", describeAccessMethods}, + {NULL, NULL} +}; + /*---------- * HandleSlashCmds: @@ -691,6 +703,23 @@ bool cmd_match(const char* str, const char* pattern) return (strncmp(str, pattern, strlen(pattern)) == 0); } + +static +bool descibeCmd(const char* str, const char *pattern, bool show_verbose) +{ + const descCommand *cmd; + + for (cmd = desc_commands; cmd->command; cmd++) + { + if (cmd_match(cmd->command, str)) + { + cmd->func(pattern, show_verbose); + return true; + } + } + return false; +} + /* * \d* commands */ @@ -878,112 +907,8 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd) /* Allow -system suffix but keep 'S' */ if (strstr(cmd, "-system") != NULL) show_system = true; - - if (cmd_match(cmd,"describe-aggregate-function")) - success = describeAggregates(pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-access-method")) - success = describeAccessMethods(pattern, show_verbose); - else if (cmd_match(cmd, "describe-tablespace")) - success = describeTablespaces(pattern, show_verbose); - else if (cmd_match(cmd, "describe-conversion")) - success = listConversions(pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-cast")) - success = listCasts(pattern, show_verbose); - else if (cmd_match(cmd, "describe-constraint") || - cmd_match(cmd, "describe-operator-class") || - cmd_match(cmd, "describe-operator-family") || - cmd_match(cmd, "describe-rule") || - cmd_match(cmd, "describe-trigger")) - success = objectDescription(pattern, show_system); - else if (cmd_match(cmd, "describe-domain")) - success = listDomains(pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-default-access-privelege ")) - success = listDefaultACLs(pattern); - else if (cmd_match(cmd, "describe-foreign-server")) - success = listForeignServers(pattern, show_verbose); - else if (cmd_match(cmd, "describe-foreign-table")) - success = listForeignTables(pattern, show_verbose); - else if (cmd_match(cmd, "describe-index")) - success = listTables("i", pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-materialized-view")) - success = listTables("m", pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-sequence")) - success = listTables("s", pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-table")) - success = listTables("t", pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-view")) - success = listTables("v", pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-user-mapping")) - success = listUserMappings(pattern, show_verbose); - else if (cmd_match(cmd, "describe-foreign-data-wrapper")) - success = listForeignDataWrappers(pattern, show_verbose); - else if (cmd_match(cmd, "describe-function")) - success = describeFunctions("\0", pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-procedure")) - success = describeFunctions("p", pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-trigger-function")) - success = describeFunctions("t", pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-window-function")) - success = describeFunctions("w", pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-normal-function")) - success = describeFunctions("n", pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-text-search-configuration")) - success = listTSConfigs(pattern, show_verbose); - else if (cmd_match(cmd, "describe-text-search-dictionary")) - success = listTSDictionaries(pattern, show_verbose); - else if (cmd_match(cmd, "describe-text-search-parser")) - success = listTSParsers(pattern, show_verbose); - else if (cmd_match(cmd, "describe-text-search-templates")) - success = listTSTemplates(pattern, show_verbose); - else if (cmd_match(cmd, "describe-role")) - success = describeRoles(pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-procedural-language")) - success = listLanguages(pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-schema") || - cmd_match(cmd, "describe-namespace")) - success = listSchemas(pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-operator")) - success = describeOperators(pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-collation")) - success = listCollations(pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-privilege ")) - success = permissionsList(pattern); - else if (cmd_match(cmd, "describe-defined-configuration-setting ")) - { - char *pattern2 = NULL; - - if (pattern) - pattern2 = psql_scan_slash_option(scan_state, - OT_NORMAL, NULL, true); - success = listDbRoleSettings(pattern, pattern2); - - if (pattern2) - free(pattern2); - } - else if (cmd_match(cmd, "describe-replication-publication")) - if (show_verbose) - success = describePublications(pattern); - else - success = listPublications(pattern); - else if (cmd_match(cmd, "describe-replication-subscription")) - success = describeSubscriptions(pattern, show_verbose); - else if (cmd_match(cmd, "describe-type")) - success = describeTypes(pattern, show_verbose, show_system); - else if (cmd_match(cmd, "describe-extension")) - if (show_verbose) - success = listExtensionContents(pattern); - else - success = listExtensions(pattern); - else if (cmd_match(cmd, "describe-event-trigger")) - success = listEventTriggers(pattern, show_verbose); - else if (pattern) - /* generic describe on a specific pattern */ - success = describeTableDetails(pattern, show_verbose, show_system); - else - /* standard listing of interesting things */ - success = listTables("tvmsE", NULL, show_verbose, show_system); + descibeCmd(cmd, pattern, show_verbose); } - status = PSQL_CMD_UNKNOWN; break; case 'u': success = listUserMappings(pattern, show_verbose);