Skip to content

Commit

Permalink
Implemented #7411: Unify display of system procedures & packages with…
Browse files Browse the repository at this point in the history
… other system objects
  • Loading branch information
AlexPeshkoff committed Dec 5, 2022
1 parent 2c6349d commit a2233b3
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 57 deletions.
1 change: 1 addition & 0 deletions src/include/firebird/impl/msg/isql.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,4 @@ FB_IMPL_MSG_SYMBOL(ISQL, 196, NO_TIMEOUTS, "Timeouts are not supported by server
FB_IMPL_MSG_SYMBOL(ISQL, 197, HLP_SETKEEPTRAN, " SET KEEP_TRAN_params -- toggle to keep or not to keep text of following successful SET TRANSACTION statement")
FB_IMPL_MSG_SYMBOL(ISQL, 198, HLP_SETPERTAB, " SET PER_TABle_stats -- toggle display of detailed per-table statistics")
FB_IMPL_MSG_SYMBOL(ISQL, 199, BAD_STMT_TYPE, "Statement type is not recognized")
FB_IMPL_MSG_SYMBOL(ISQL, 200, MSG_PACKAGES, "Packages:")
140 changes: 83 additions & 57 deletions src/isql/show.epp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ static processing_state show_func(const SCHAR*);
static processing_state show_generators(const SCHAR*);
static void show_index(SCHAR*, SCHAR*, const SSHORT, const SSHORT, const SSHORT);
static processing_state show_indices(const SCHAR* const*);
static processing_state show_proc(const SCHAR*);
static processing_state show_packages(const SCHAR* package_name);
static processing_state show_proc(const SCHAR*, bool);
static processing_state show_packages(const SCHAR* package_name, bool, const SCHAR* = NULL);
static processing_state show_role(const SCHAR*, bool, const char* msg = NULL);
static processing_state show_secclass(const char* object, const char* opt);
static processing_state show_table(const SCHAR*, bool);
Expand Down Expand Up @@ -2245,6 +2245,14 @@ processing_state SHOW_metadata(const SCHAR* const* cmd, SCHAR** lcmd)
show_role(NULL, true);
break;

case ShowOptions::procedure:
show_proc(NULL, true);
break;

case ShowOptions::package:
show_packages(NULL, true);
break;

default:
return ps_ERR;
}
Expand All @@ -2257,6 +2265,9 @@ processing_state SHOW_metadata(const SCHAR* const* cmd, SCHAR** lcmd)
show_all_tables(1);
IUTILS_msg_get(MSG_FUNCTIONS, msg);
show_sys_functions(msg);
show_proc(NULL, true);
IUTILS_msg_get(MSG_PACKAGES, msg);
show_packages(NULL, true, msg);
IUTILS_msg_get(MSG_COLLATIONS, msg);
show_collations("", 1, msg, true);
IUTILS_msg_get(MSG_ROLES, msg);
Expand Down Expand Up @@ -2531,10 +2542,10 @@ processing_state SHOW_metadata(const SCHAR* const* cmd, SCHAR** lcmd)
if (*cmd[2] == '"')
{
remove_delimited_double_quotes(lcmd[2]);
ret = show_proc(lcmd[2]);
ret = show_proc(lcmd[2], false);
}
else
ret = show_proc(cmd[2]);
ret = show_proc(cmd[2], false);

if (ret == OBJECT_NOT_FOUND)
{
Expand Down Expand Up @@ -2673,10 +2684,10 @@ processing_state SHOW_metadata(const SCHAR* const* cmd, SCHAR** lcmd)
if (*cmd[2] == '"')
{
remove_delimited_double_quotes(lcmd[2]);
ret = show_packages(lcmd[2]);
ret = show_packages(lcmd[2], false);
}
else
ret = show_packages(cmd[2]);
ret = show_packages(cmd[2], false);

if (ret == OBJECT_NOT_FOUND)
{
Expand Down Expand Up @@ -4865,7 +4876,7 @@ static processing_state show_indices(const SCHAR* const* cmd)
}


static processing_state show_packages(const SCHAR* package_name)
static processing_state show_packages(const SCHAR* package_name, bool sys, const SCHAR* msg)
{
/*************************************
*
Expand All @@ -4881,15 +4892,22 @@ static processing_state show_packages(const SCHAR* package_name)

bool first = true;

if (!*package_name)
if (!(package_name && *package_name))
{
// List all package names in columns
FOR PACK IN RDB$PACKAGES WITH
(PACK.RDB$SYSTEM_FLAG NE 1 OR PACK.RDB$SYSTEM_FLAG MISSING)
FOR PACK IN RDB$PACKAGES
SORTED BY PACK.RDB$PACKAGE_NAME
{
first = false;
isqlGlob.printf("%s%s", fb_utils::exact_name(PACK.RDB$PACKAGE_NAME), NEWLINE);
bool system_flag = !PACK.RDB$SYSTEM_FLAG.NULL && PACK.RDB$SYSTEM_FLAG > 0;

if (system_flag == sys)
{
if (first && msg)
isqlGlob.printf("%s%s", msg, NEWLINE);
first = false;

isqlGlob.printf("%s%s", fb_utils::exact_name(PACK.RDB$PACKAGE_NAME), NEWLINE);
}
}
END_FOR
ON_ERROR
Expand Down Expand Up @@ -5095,7 +5113,7 @@ processing_state SHOW_maps(bool extract, const SCHAR* map_name)
}


static processing_state show_proc(const SCHAR* procname)
static processing_state show_proc(const SCHAR* procname, bool sys)
{
/**************************************
*
Expand Down Expand Up @@ -5124,68 +5142,74 @@ static processing_state show_proc(const SCHAR* procname)
FOR PRC IN RDB$PROCEDURES
SORTED BY PRC.RDB$PACKAGE_NAME, PRC.RDB$PROCEDURE_NAME
{
string package;
bool system_flag = !PRC.RDB$SYSTEM_FLAG.NULL && PRC.RDB$SYSTEM_FLAG > 0;

if (!PRC.RDB$PACKAGE_NAME.NULL)
if (system_flag == sys)
{
fb_utils::exact_name(PRC.RDB$PACKAGE_NAME);
package = PRC.RDB$PACKAGE_NAME;
}
string package;

if (first_proc || package != prevPackage)
{
if (package.isEmpty())
isqlGlob.printf("Global procedures%s%s", NEWLINE, NEWLINE);
else
if (!PRC.RDB$PACKAGE_NAME.NULL)
{
if (!first_proc)
isqlGlob.printf("%s", NEWLINE);
fb_utils::exact_name(PRC.RDB$PACKAGE_NAME);
package = PRC.RDB$PACKAGE_NAME;
}

isqlGlob.printf("Package: %s%s%s", package.c_str(), NEWLINE, NEWLINE);
if (first_proc || package != prevPackage)
{
if (package.isEmpty())
isqlGlob.printf("Global procedures%s%s", NEWLINE, NEWLINE);
else
{
if (!first_proc)
isqlGlob.printf("%s", NEWLINE);

isqlGlob.printf("Package: %s%s%s", package.c_str(), NEWLINE, NEWLINE);
}

first_proc = false;
}

first_proc = false;
}

prevPackage = package;
prevPackage = package;

// Strip trailing blanks
// Strip trailing blanks

fb_utils::exact_name(PRC.RDB$PROCEDURE_NAME);
isqlGlob.printf("%s", PRC.RDB$PROCEDURE_NAME);
fb_utils::exact_name(PRC.RDB$PROCEDURE_NAME);
isqlGlob.printf("%s", PRC.RDB$PROCEDURE_NAME);

if (!(PRC.RDB$VALID_BLR.NULL || PRC.RDB$VALID_BLR))
isqlGlob.printf("; Invalid");
if (!(PRC.RDB$VALID_BLR.NULL || PRC.RDB$VALID_BLR))
isqlGlob.printf("; Invalid");

if (PRC.RDB$PACKAGE_NAME.NULL)
{
bool first_dep = true;
FOR DEP IN RDB$DEPENDENCIES WITH
PRC.RDB$PROCEDURE_NAME EQ DEP.RDB$DEPENDENT_NAME
REDUCED TO DEP.RDB$DEPENDED_ON_TYPE, DEP.RDB$DEPENDED_ON_NAME
SORTED BY DEP.RDB$DEPENDED_ON_TYPE, DEP.RDB$DEPENDED_ON_NAME
if (PRC.RDB$PACKAGE_NAME.NULL)
{
fb_utils::exact_name(DEP.RDB$DEPENDED_ON_NAME);

if (first_dep)
bool first_dep = true;
FOR DEP IN RDB$DEPENDENCIES WITH
PRC.RDB$PROCEDURE_NAME EQ DEP.RDB$DEPENDENT_NAME
REDUCED TO DEP.RDB$DEPENDED_ON_TYPE, DEP.RDB$DEPENDED_ON_NAME
SORTED BY DEP.RDB$DEPENDED_ON_TYPE, DEP.RDB$DEPENDED_ON_NAME
{
isqlGlob.printf("; Dependencies: ");
first_dep = false;
}
else
isqlGlob.printf(", ");
fb_utils::exact_name(DEP.RDB$DEPENDED_ON_NAME);

isqlGlob.printf("%s (%s)", fb_utils::exact_name(DEP.RDB$DEPENDED_ON_NAME),
if (first_dep)
{
isqlGlob.printf("; Dependencies: ");
first_dep = false;
}
else
isqlGlob.printf(", ");

isqlGlob.printf("%s (%s)", fb_utils::exact_name(DEP.RDB$DEPENDED_ON_NAME),
Object_types[DEP.RDB$DEPENDED_ON_TYPE]);
}
END_FOR
ON_ERROR
ISQL_errmsg (fbStatus);
return ps_ERR;
END_ERROR;
}
END_FOR
ON_ERROR
ISQL_errmsg (fbStatus);
return ps_ERR;
END_ERROR;
}

isqlGlob.printf(NEWLINE);
isqlGlob.printf(NEWLINE);
}
}
END_FOR
ON_ERROR
Expand All @@ -5195,6 +5219,8 @@ static processing_state show_proc(const SCHAR* procname)

if (first_proc)
return OBJECT_NOT_FOUND;

isqlGlob.printf(NEWLINE);
return (SKIP);
}

Expand Down

2 comments on commit a2233b3

@aafemt
Copy link
Contributor

@aafemt aafemt commented on a2233b3 Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is client-side filtration a good idea?

@AlexPeshkoff
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it works fine for some other objects (like roles if I'm not mistaken). I doubt it has any visible effect on ISQL performance. But if you wish please provide PR - I'll be glad to commit it. Just rework it for other objects too.

Please sign in to comment.