5353#include "../jrd/constants.h"
5454#include "../jrd/ods_proto.h"
5555#include "../common/classes/MsgPrint.h"
56+ #include "../common/classes/QualifiedMetaString.h"
5657#include "../common/classes/UserBlob.h"
5758#include "../common/os/os_utils.h"
5859#include "../common/StatusHolder.h"
@@ -177,6 +178,7 @@ struct dba_rel
177178 USHORT rel_used_formats;
178179 SSHORT rel_id;
179180 SCHAR rel_name[MAX_SQL_IDENTIFIER_SIZE];
181+ SCHAR rel_schema[MAX_SQL_IDENTIFIER_SIZE];
180182};
181183
182184// kidnapped from jrd/pio.h and abused
@@ -813,10 +815,11 @@ int gstat(Firebird::UtilSvc* uSvc)
813815 isc_req_handle request4 = 0;
814816
815817 FOR(TRANSACTION_HANDLE transact1 REQUEST_HANDLE request1)
816- X IN RDB$RELATIONS SORTED BY DESC X.RDB$RELATION_NAME
818+ X IN RDB$RELATIONS
819+ SORTED BY DESC X.RDB$SCHEMA_NAME, X.RDB$RELATION_NAME
817820 {
818821 if (!sw_system && X.RDB$SYSTEM_FLAG) {
819- continue;
822+ continue;
820823 }
821824 if (!X.RDB$VIEW_BLR.NULL || !X.RDB$EXTERNAL_FILE.NULL) {
822825 continue;
@@ -828,38 +831,48 @@ int gstat(Firebird::UtilSvc* uSvc)
828831 continue;
829832 }
830833
834+ fb_utils::exact_name(X.RDB$SCHEMA_NAME);
835+
831836 if (sw_schema)
832837 {
833- fb_utils::exact_name(X.RDB$SCHEMA_NAME);
834-
835838 dba_schema* schema = nullptr;
836839
837840 for (schema = tddba->schemas; schema; schema = schema->next)
838841 {
839- if (!( strcmp(schema->name, X.RDB$SCHEMA_NAME)) )
842+ if (strcmp(schema->name, X.RDB$SCHEMA_NAME) == 0 )
840843 break;
841844 }
842845
843846 if (!schema)
844847 continue;
845848 }
846849
847- dba_rel* relation;
850+ dba_rel* relation = nullptr;
851+ bool shouldIncludeRelation = !sw_relation;
852+
848853 if (sw_relation)
849854 {
850855 fb_utils::exact_name(X.RDB$RELATION_NAME);
856+
851857 for (relation = tddba->relations; relation; relation = relation->rel_next)
852858 {
853- if (!(strcmp(relation->rel_name, X.RDB$RELATION_NAME)))
854- {
855- relation->rel_id = X.RDB$RELATION_ID;
856- break;
857- }
859+ if (strcmp(relation->rel_name, X.RDB$RELATION_NAME) == 0)
860+ {
861+ shouldIncludeRelation = true;
862+
863+ if (relation->rel_id == -1)
864+ {
865+ relation->rel_id = X.RDB$RELATION_ID;
866+ break;
867+ }
868+ }
858869 }
859- if (!relation)
870+
871+ if (!shouldIncludeRelation)
860872 continue;
861873 }
862- else
874+
875+ if (!relation)
863876 {
864877 relation = (dba_rel*) alloc(sizeof(struct dba_rel));
865878 relation->rel_next = tddba->relations;
@@ -869,6 +882,8 @@ int gstat(Firebird::UtilSvc* uSvc)
869882 fb_utils::exact_name(relation->rel_name);
870883 }
871884
885+ strcpy(relation->rel_schema, X.RDB$SCHEMA_NAME);
886+
872887 FOR(TRANSACTION_HANDLE transact1 REQUEST_HANDLE request2)
873888 Y IN RDB$PAGES WITH Y.RDB$RELATION_ID EQ relation->rel_id AND
874889 Y.RDB$PAGE_SEQUENCE EQ 0
@@ -888,8 +903,10 @@ int gstat(Firebird::UtilSvc* uSvc)
888903 if (sw_index)
889904 {
890905 FOR(TRANSACTION_HANDLE transact1 REQUEST_HANDLE request3)
891- Y IN RDB$INDICES WITH Y.RDB$RELATION_NAME EQ relation->rel_name
892- SORTED BY DESC Y.RDB$INDEX_NAME
906+ Y IN RDB$INDICES
907+ WITH Y.RDB$RELATION_NAME EQ X.RDB$RELATION_NAME AND
908+ Y.RDB$SCHEMA_NAME EQUIV NULLIF(X.RDB$SCHEMA_NAME, '')
909+ SORTED BY DESC Y.RDB$INDEX_NAME
893910 {
894911 if (Y.RDB$INDEX_INACTIVE)
895912 continue;
@@ -975,8 +992,9 @@ int gstat(Firebird::UtilSvc* uSvc)
975992 checkForShutdown(tddba);
976993 if (relation->rel_id == -1)
977994 {
978- dba_error(44, SafeArg() << relation->rel_name);
979- // msg 44: table "@1" not found
995+ dba_error(44, SafeArg() <<
996+ QualifiedMetaString(relation->rel_name, relation->rel_schema).toQuotedString().c_str());
997+ // msg 44: table @1 not found
980998 }
981999 }
9821000 }
@@ -1013,7 +1031,9 @@ int gstat(Firebird::UtilSvc* uSvc)
10131031 continue;
10141032 }
10151033
1016- uSvc->printf(false, "%s (%d)\n", relation->rel_name, relation->rel_id);
1034+ uSvc->printf(false, "%s (%d)\n",
1035+ QualifiedMetaString(relation->rel_name, relation->rel_schema).toQuotedString().c_str(),
1036+ relation->rel_id);
10171037
10181038 if (sw_data)
10191039 {
@@ -1120,7 +1140,9 @@ int gstat(Firebird::UtilSvc* uSvc)
11201140
11211141 for (const dba_idx* index = relation->rel_indexes; index; index = index->idx_next)
11221142 {
1123- dba_print(false, 14, SafeArg() << index->idx_name << index->idx_id);
1143+ dba_print(false, 14, SafeArg() <<
1144+ QualifiedMetaString(index->idx_name, relation->rel_schema).toQuotedString().c_str() <<
1145+ index->idx_id);
11241146 // msg 14: " Index %s (%d)"
11251147
11261148 uSvc->printf(false, "\tRoot page: %d, depth: %d, leaf buckets: %ld, nodes: %" UQUADFORMAT "\n",
0 commit comments