How can I get the name of the data database in the current namespace?
Hi folks!
Is there a way (function) to know the name of the database for data of the current namespace?
I take the case where we have one database for data and another database for code in a namespace.
Thanks!
Comments
This is not so simple because parts of a namespace could be mapped in more then one database.
But take a look at the %SYS.Namespace class:
do ##class(%SYS.Namespace).GetAllNSInfo("Namespace", .info)
write ##class(%SYS.Namespace).GetGlobalDest(,"aGlobalname") // gives you the global database for a specific global
write ##class(%SYS.Namespace).GetRoutineDest(,"aRoutinename") // gives you the global database specific routineThanks, Julius!
You can use (inside %SYS) Config.Namespaces:Get().
For example -
%SYS > set status = ##class(Config.Namespaces).Get("USER",.properties)
%SYS > zwrite properties
properties("Globals")="USER"
properties("Library")="CACHELIB"
properties("Routines")="USER"
properties("SysGlobals")="CACHESYS"
properties("SysRoutines")="CACHESYS"
properties("TempGlobals")="CACHETEMP"
%SYS > set dataDatabaseName = properties("Globals")
%SYS > write dataDatabaseName
USER
%SYS > set codeDatabaseName = properties("Routines")
%SYS > write codeDatabaseName
USEROf course assuming you are coming from other namespace into %SYS, you can have the name of that namespace in a variable, and use that variable instead of "USER" in my example above.
If you want the actual directory/folder of the database you can also then use Config.Databases:Get(), for example:
%SYS > set status = ##class(Config.Databases).Get("USER",.properties)
%SYS > zwrite properties
properties("ClusterMountMode")=0
properties("Directory")="C:\InterSystems\IRIS\mgr\user\"
properties("MountAtStartup")=0
properties("MountRequired")=0
properties("Server")=""
properties("StreamLocation")=""And if you want directly just the locations of the databases, and not their names, you could use %SYS.Namespace:GetAllNSInfo() (without having to move into %SYS first) as @Julius Kavay mentioned.
For example:
USER > do ##class(%SYS.Namespace).GetAllNSInfo("USER",.info)
USER > zwrite info
info("GlobalDB","Directory")="c:\intersystems\IRIS\mgr\user\"
info("GlobalDB","Mounted")=1
info("GlobalDB","ReadOnly")=0
info("GlobalDB","Resource")="%DB_USER"
info("GlobalDB","Status")=1
info("GlobalDB","System")=""
info("RoutineDB","Directory")="c:\intersystems\IRIS\mgr\user\"
info("RoutineDB","Mounted")=1
info("RoutineDB","ReadOnly")=0
info("RoutineDB","Resource")="%DB_USER"
info("RoutineDB","Status")=1
info("RoutineDB","System")=""Thank you, Tani! This is what I was looking for!