Kevin McGinn
Kevin McGinn

Reputation: 11

Converting Intersystems cache objectscript into a python function

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).

Upvotes: 0

Views: 561

Answers (3)

robtweed
robtweed

Reputation: 21

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

Upvotes: 0

Kevin McGinn
Kevin McGinn

Reputation: 11

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.

Upvotes: 0

adaptun
adaptun

Reputation: 509

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

Upvotes: 0

Related Questions