George Hodder · Feb 19, 2021

Help with class query in SYS.Database


I am wanting to get the results of SYS.Database class's List query into a result set.

I have code that does it, but I get a cursor error at the end.... should I just to a try/catch and ignore this error below?  Or can I call this in a different way to avoid the error?  

My code, in the %SYS namespace

Set Statement=##class(%SQL.Statement).%New()
Set status=Statement.%PrepareClassQuery("SYS.Database","List")

Set rset=Statement.%Execute()
while (rset.%Next())
        W !,rset.%Get("Directory"),?30,rset.%Get("Size"),?40,rset.%Get("MaxSize")

when I call it... it displays

c:\intersystems\cache\mgr\   96        Unlimited
c:\intersystems\cache\mgr\cache\11      Unlimited
c:\intersystems\cache\mgr\cacheaudit\1  Unlimited
c:\intersystems\cache\mgr\cachelib\506  Unlimited
c:\intersystems\cache\mgr\cachetemp\11  Unlimited
c:\intersystems\cache\mgr\docbook\200   Unlimited
c:\intersystems\cache\mgr\ffl\10        Unlimited
c:\intersystems\cache\mgr\samples\91    Unlimited
c:\intersystems\cache\mgr\user\31       Unlimited

<CLASS DOES NOT EXIST>%CloseCursor+3^%SQL.ClassQueryResultSet.1 *SYS.Database

Product version: Ensemble 2016.1
$ZV: Cache for Windows (x86-64) 2016.1.1 (Build 108U_SU) Thu Jul 7 2016 09:32:36 EDT
0 184
Discussion (2)1
Log in or sign up to continue

is typical if try to access resultset or just delete rset  after leaving namespace %SYS.
Just reproduced it.

%SYS>w !,rset.%Next(),?5,rset.%Get("Directory"),!?30,rset.%Get("Size"),?40,rset.%Get("MaxSize")
 1    c:\intersystems\iris\mgr\enslib\
                              163       Unbegrenzt
USER>k rset
<CLASS DOES NOT EXIST>%CloseCursor+3^%SQL.ClassQueryResultSet.1 *SYS.Database