Question
Kevin McGinn · Mar 1, 2022

Syntax issues with intersys.pythonbind3 query.prepare()

I am writing a Python tool to query our cache instances for various information. I have set up the connection without issue:

import intersys.pythonbind3 as pyb  

conn     = pyb.connection()
conn.connect_now(.....)
    
db      = pyb.database(conn)
qry     = pyb.query(db)
obj     = pyb.object(db)

I wanted to make the call:

execRes = qry.prepare_class("SYS.Database",'FreeSpace')

But fetching fails because of data mismatches ( as I understand from other posts) and my testing bears out this type of failure.

Instead I opted to attempt a query:

execRes = qry.prepare("select DatabaseName, Directory, MaxSize, Size, < list shorted for brevity> from SYS.Database_FreeSpace('*')")

But that fails with a message that I don't understand; not sure of the issue:

intersys.pythonbind3.cache_exception: file=intersys/pythonbind3.c line=3355 err=-1 message=cbind_prepare_gen_query()

Any help or guidance on this issue would be much appreciated.

0
0 111
Discussion (6)1
Log in or sign up to continue

This is cache 17.3 that I am using

Consider updating to InterSystems IRIS and using Native API for Python (2022.1 preview provides db-api connections, previous versions are pyODBC/JayDeBeAPI compatible).

you should check a few things upfront
- is your Caché a 64 bits installation and is the   pythonbind3.c  also compiled for 64 bit   (or both 32bit)
  this might be one possible reason for the "data mismatch" you mention
- pythonbind3.c seems to be a C code using the Callin Interface.
  this requires Service %Service_CallIn to be enabled with user, passwd, ...
- next check the SuperServer Port (default = 1972)
- connect to a USER namespace. Since %SYS requires rather high privileges.
- then check if the connection really works.
  once established it should be possible to identify the related process from
  System Management Portal / Operations / Processes showing the client_exe, namespace, ...
- then you may start composing queries.
 

Thank-you for your reply. I know cache is 64bit; I believe intersys.pythonbind3 is also 64bit though I am not entirely clear about how to validate that. The connection to the database works correctly. The following method calls with the connection work correctly:

db.run_class_method("%SYSTEM.INetInfo","LocalHostName",[])
db.run_class_method("%SYSTEM.Version","SystemMode",[])
db.run_class_method("%SYSTEM.Util","InstallDirectory",[])
db.run_class_method("%SYSTEM.Util","ManagerDirectory",[])
db.run_class_method("%SYSTEM.Util","NumberOfCPUs",[])

This is what makes the issue confusing. This intersys lib. appears to have the tools I need but perhaps I should revisit ODBC. I see the cache query builder is also based upon ODBC so perhaps that is the actual fix.

I have resolved this issue. I used:

execRes = qry.prepare_class("SYS.Database",'CompactLocalList')

to get basic information on each of the databases.  I then used object getters to get the other property values I needed. To get a object handle to each database I used:

_db = db.openid('SYS.Database', <database dir>,-1,-1)

Then

<prop value = _db.get(<property name>)