0

I am accessing an Intersystems cache 2017.1.xx instance through a python process to get various attributes about the database in able to monitor the database.

One of the items I want to monitor is license usage. I wrote a objectscript script in a Terminal window to access license usage by user:

   s Rset=##class(%ResultSet).%New("%SYSTEM.License.UserListAll")
   s r=Rset.Execute()
   s ncol=Rset.GetColumnCount()
   While (Rset.Next()) {f i=1:1:ncol w !,Rset.GetData(i)}

But, I have been unable to determine how to convert this script into a Python equivalent. I am using the intersys.pythonbind3 import for connecting and accessing the cache instance. I have been able to create python functions that accessing most everything else in the instance but this one piece of data I can not figure out how to translate it to Python (3.7).

3 Answers3

0

Following should work (based on the documentation):

query = intersys.pythonbind.query(database)
query.prepare_class("%SYSTEM.License","UserListAll")
query.execute();

# Fetch each row in the result set, and print the
# name and value of each column in a row: 
while 1:
   cols = query.fetch([None])
   if len(cols) == 0: break
   print str(cols[0])

Also, notice that InterSystems IRIS -- successor to the Caché now has Python as an embedded language. See more in the docs

adaptun
  • 494
  • 4
  • 11
  • Thank-you for the response. Unfortunately, that is the approach that I thought was the correct translation into Python. However, using that syntax produces this error: [SQLCODE: <-428>:] [Location: ] [%msg: ] – Kevin McGinn Mar 23 '22 at 13:11
  • Then it's not possible. It looks likes a pythonbind tries to call this class query as a stored procedure, but this class query is not projected as one. – adaptun Mar 23 '22 at 14:25
  • That makes sense. I am attempting another approach which does not work yet though is hopeful
    hdl = self.db.run_class_method("%SQL.Statement","%New",[]) resState = None pasState = "call %SYSTEM.License_UserListAll" list=[resState, pasState] pStat = hdl.run_obj_method("%ExecDirect",list) print(f'pStat = {pStat}') print(pStat.run_obj_method("%Display",[]))
    I am sure this still is not correct but thought it was worth a try
    – Kevin McGinn Mar 23 '22 at 18:21
0

Since the noted query "UserListAll" is not defined correctly in the library; not SqlProc. So to resolve this issue would require a ObjectScript with the query and the use of @Result set or similar in Python to get the results. So I am marking this as resolved.

0

Not sure which Python interface you're using for Cache/IRIS, but this Open Source 3rd party one is worth investigating for the kind of things you're trying to do:

https://github.com/chrisemunt/mg_python

robtweed
  • 21
  • 2
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/33255086) – chrslg Nov 29 '22 at 00:52