Question
· Aug 24, 2022

Accessing databases in other Namespaces

Hi Guys

I have a table data in one namespace that I want to access from another Namespace  - is that possible?

Cheers

Product version: IRIS 2022.1
$ZV: IRIS for Windows (x86-64) 2021.2.1 (Build 654U) Fri Mar 18 2022 06:09:35 EDT
Discussion (3)2
Log in or sign up to continue

Sure. There are two ways:

1. Switch to another namespace to execute your query:

/// Get a list of all mirrored databases as a $lb()
ClassMethod GetMirroredDBs() As %List
{
    new $namespace
    set $namespace = "%SYS"
    set sql = "SELECT LIST(Name) dbs FROM Config.Databases_MirrorDatabaseList()"
    set rs = ##class(%SQL.Statement).%ExecDirect(,sql)
    do rs.%Next()
    set dbs = $lfs(rs.dbs)
    kill rs
    quit dbs
}

Now you can have this method in USER namespace and it would automatically swith into %SYS, execute query, iterate over the results, write results into a local variable, switch back into USER namespace and return the value back to you.

The main thing you need to remember is that result set iteration MUST happen in a target namespace.

2. Map classes and globals to your namespace. Docs. Table would be available as if it was created in your original namespace.

If you work with ObjectScript, you can use the bracketed notation to access directly to a global in another namespace.

Something like:

zwrite ^["myOtherNamespace"]person(13)

Another example in the docs:

https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...

Sorry, I didn't find the main page where this is explained.

Edit: I found it: https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...