Written by

Question CJ Q · Dec 5, 2022

How to use python connect cache2016 database?

I need connect to cache2016 database by python to get some data, but   I don' t know how to connect by python, did anyone know how to create connection?

If you can provide any python code, that will be better! 

Product version: Caché 2016.1

Comments

CJ Q  Dec 13, 2022 to Cristiano Silva

well, I tryed python buinding, but the intersys.pythonbind package did not find the connection method, my python version is Anaconda (python 3.9.13 and conda 22.9.0) .If you have some reference document  or website that will be fine. 

0
Robert Cemper · Dec 13, 2022

Any ODBC connection may do it for data and procedures.

0
José Pereira · Dec 14, 2022

Hi!

I grabbed some pieces of code from a previous project. In this project I could connect to Cache 2018.

PS: I didn't test this mashup.

import irisnative
import jaydebeapi
import pandas as pd

defcreate_conn(type, host, port, namespace, user, password):if type == "cache":
        url = f"jdbc:Cache://{host}:{port}/{namespace}"
        driver = "com.intersys.jdbc.CacheDriver"
        jarfile = "C:/InterSystems/Cache2018/dev/java/lib/JDK18/cache-jdbc-2.0.0.jar"
        conn = jaydebeapi.connect(driver, url, [user, password], jarfile)
    else:
        conn = irisnative.createConnection(host, port, namespace, user, password, sharedmemory = True)
    return conn

conn = create_conn("cache", "x.x.x.x", "56772", "namespace", "user", "password")
sql = "select ..."
df = pd.read_sql(sql, conn)
display(df)

HTH,

José

0
Kevin McGinn · Dec 22, 2022

I found the best approach was with pythonbind:

import intersys.pythonbind3 as pyb

url = "localhost"
userName= "???"
password="???"
port=1972

def main():
        conn     = pyb.connection()
        version = conn.get_implementation_version()
        conn.connect_now(f'[{url}][{port}]:%SYS', userName, password,None)

        # Create objects used to access cache/iris
        db  = pyb.database(conn)
        qry    = pyb.query (db)
        obj    = pyb.object(db)

......

With the connection handle and the db, qry, obj objects you can use the methods and classes to access any database item in the cache database

0