diff --git a/uppsrc/Sql/IntroSch.cpp b/uppsrc/Sql/IntroSch.cpp index 533ac5392..4ad39ea7e 100644 --- a/uppsrc/Sql/IntroSch.cpp +++ b/uppsrc/Sql/IntroSch.cpp @@ -102,6 +102,24 @@ int sChrf(int c) StaticMutex sM; +ArrayMap> GetSchAll() +{ + ArrayMap> r; + Mutex::Lock __(sM); + for(int i = 0; i < sSchTableInfo().GetCount(); i++) + if(sSchTableInfo()[i].is_table) { + Array& cf = r.Add(sSchTableInfo().GetKey(i)); + const SchTableInfo& h = sSchTableInfo()[i]; + for(int j = 0; j < h.column.GetCount(); j++) { + SchColumnInfo& f = cf.Add(); + f.name = h.column[j]; + f.references = h.ref_table[j]; + f.foreign_key = Nvl(h.ref_column[j], f.name); + } + } + return r; +} + Vector GetSchTables() { Mutex::Lock __(sM); @@ -115,7 +133,7 @@ Vector GetSchTables() Vector GetSchColumns(const String& table) { Mutex::Lock __(sM); - return Vector(GetSchTableInfo(table).column, 0); + return clone(GetSchTableInfo(table).column); } SqlBool FindSchJoin(const String& tables) diff --git a/uppsrc/Sql/SqlSchema.h b/uppsrc/Sql/SqlSchema.h index 8e6156184..1e8c61c6d 100644 --- a/uppsrc/Sql/SqlSchema.h +++ b/uppsrc/Sql/SqlSchema.h @@ -120,8 +120,16 @@ void SchDbInfoReferences(const char *table, const char *column); SqlBool FindSchJoin(const String& tables); -Vector GetSchTables(); -Vector GetSchColumns(const String& table); +Vector GetSchTables(); +Vector GetSchColumns(const String& table); + +struct SchColumnInfo { + String name; + String references; + String foreign_key; +}; + +ArrayMap< String, Array > GetSchAll(); String ExportSch(SqlSession& session, const String& database); String ExportIds(SqlSession& session, const String& database); diff --git a/uppsrc/Sql/src.tpp/SqlSchema_en-us.tpp b/uppsrc/Sql/src.tpp/SqlSchema_en-us.tpp index ce4e8bc60..9ec9df25b 100644 --- a/uppsrc/Sql/src.tpp/SqlSchema_en-us.tpp +++ b/uppsrc/Sql/src.tpp/SqlSchema_en-us.tpp @@ -1,5 +1,4 @@ topic "Schema introspection"; -[2 $$0,0#00000000000000000000000000000000:Default] [i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class] [l288;2 $$2,2#27521748481378242620020725143825:desc] [0 $$3,0#96390100711032703541132217272105:end] @@ -9,6 +8,7 @@ topic "Schema introspection"; [l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param] [i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] [b42;2 $$9,9#13035079074754324216151401829390:normal] +[2 $$0,0#00000000000000000000000000000000:Default] [{_} [ {{10000@(113.42.0) [s0;%% [*@7;4 Schema introspection]]}}&] [s3; &] @@ -27,11 +27,17 @@ column in .sch definition is used.&] [s4; &] [s5;:GetSchTables`(`): [_^Vector^ Vector]<[_^String^ String]>_[* GetSchTables]()&] [s2;%% Returns a list of all tables defined by .sch schema files.&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:GetSchAll`(`): [_^Upp`:`:ArrayMap^ ArrayMap]<_[_^Upp`:`:String^ String], +[_^Upp`:`:Array^ Array]<[_^Upp`:`:SchColumnInfo^ SchColumnInfo]>_>_[* GetSchAll]()&] +[s2;%% Returns the information of all .sch defined tables. Table +names are map keys. SchColumnInfo contains name of column, the +table it REFERENCES (if any) and the name of foreign key.&] [s3; &] [s4; &] [s5;:GetSchColumns`(const String`&`): [_^Vector^ Vector]<[_^String^ String]>_[* GetSchColum ns]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 table])&] [s2;%% Returns all columns for [%-*@3 table] defined by .sch schema files.&] -[s3;%% &] [s0;%% ]] \ No newline at end of file