Question Anna Golitsyna · Feb 27, 2024

How to find Routine Mappings programmatically?

The goal is to identify programmatically all SOURCE namespaces on a server to which the routines are mapped. In the example below from the Namespaces page in Management Portal the answer would be USER. But some other namespaces on the same server could be mapped to a different namespace or even mapped to itself.

This code snippet prints all namespaces and source namespaces for their routines.
zn "%SYS"
set statement=##class(%SQL.Statement).%New()
set status=statement.%PrepareClassQuery("Config.Namespaces","List")
set resultset=statement.%Execute()
while resultset.%Next() {
    w %objcsd(1,13), $C(9),%objcsd(1,18),!
}

 

Product version: Caché 2017.1

Comments

Enrico Parisi · Feb 27, 2024

Form the %SYS namespace you can use the List class query in the Config.MapRoutines class.

For example:

%SYS>Set ResultSet=##class(Config.MapRoutines).ListFunc("USER")
 
%SYS>d ResultSet.%Display()
Name    Routine Type    Database
MyTestRoutine   MyTestRoutine           TRAINING
 
1 Rows(s) Affected
%SYS>Write ResultSet.%ClassName(1)
%SQL.ClassQueryResultSet
%SYS>
0
Enrico Parisi · Feb 27, 2024

Maybe (likely!) I misunderstood your question.

What do you mean with "But some other namespaces on the same server could be mapped to a different namespace or even mapped to itself." ?

A namespace cannot be mapped to another namespace.

A namespace definition consists of default database for globals, default database for "routines" (all code) and optionally global/package/routine mappings to different databases. (Plus some default system mapping)

0
Anna Golitsyna  Feb 28, 2024 to Enrico Parisi

Enrico, I meant how to programmatically reproduce information on the System > Configuration > Namespaces page in Management Portal. In other words, how to extract default databases listed under Routines on this page.

0
Enrico Parisi  Feb 28, 2024 to Anna Golitsyna

You already answered your question....in the question! 😊

From %SYS namespace, use the List class query in the Config.Namespaces class:

%SYS>Set ResultSet=##class(Config.Namespaces).ListFunc()
 
%SYS>Do ResultSet.%Display()
Namespace       Globals Routines        System Globals  System Routines LibraryTemp Storage
%ALL    %DEFAULTDB      %DEFAULTDB      IRISSYS IRISSYS IRISLIB IRISTEMP
%SYS    IRISSYS IRISSYS IRISSYS IRISSYS IRISLIB IRISTEMP
USER    USER    USER    IRISSYS IRISSYS IRISLIB IRISTEMP
 
5 Rows(s) Affected
%SYS>

 Or, if you prefer:

%SYS>Set statement=##class(%SQL.Statement).%New()
 
%SYS>Set status=statement.%PrepareClassQuery("Config.Namespaces","List")
 
%SYS>Set resultset=statement.%Execute()
 
%SYS>While resultset.%Next() {  Write resultset.%Get("Namespace"),$c(9),resultset.%Get("Globals"),$c(9),resultset.%Get("Routines"),!}
%ALL    %DEFAULTDB      %DEFAULTDB
%SYS    IRISSYS IRISSYS
USER    USER    USER
 
%SYS>
0
Enrico Parisi · Feb 28, 2024

New variant that I like it better 😀

%SYS>Set ResultSet=##class(Config.Namespaces).ListFunc()
 
%SYS>While ResultSet.%Next() {  Write ResultSet.%Get("Namespace"),$c(9),ResultSet.%Get("Globals"),$c(9),ResultSet.%Get("Routines"),!}
%ALL    %DEFAULTDB      %DEFAULTDB
%SYS    IRISSYS IRISSYS
USER    USER    USER
 
%SYS>
0
Anna Golitsyna  Feb 28, 2024 to Enrico Parisi

Less verbose and more elegant

0