python access to TimesTen

后端 未结 5 1726
旧时难觅i
旧时难觅i 2021-01-14 20:17

I googled a lot to find any python module to access TimesTen (in memory database). I am writing a automated testing framework (more like for System Test and not Unit Test).

相关标签:
5条回答
  • 2021-01-14 20:48

    I didn't find native one, but TimesTen has ODBC interface that you could use.

    http://www.compwisdom.com/topics/ODBC

    0 讨论(0)
  • 2021-01-14 20:49

    To use Python with TimesTen (11.2 or 18.1), you should use cx_Oracle

    cx_Oracle works the same for both TimesTen and the Oracle RDBMS

    cx_Oracle uses ODPI-C which is a C library wrapper to OCI

    For both TimesTen and the Oracle RDBMS, cx_Oracle can either use the Easy connect method or tnsnames.ora in the connect string.

    The following cx_Oracle example uses tnsnames.ora [ie doug/doug@sampledb]

    # myscript.py
    
    from __future__ import print_function
    
    import cx_Oracle
    
    connection = cx_Oracle.connect("doug", "doug", "sampledb")
    cursor = connection.cursor()
    cursor.execute("insert into t values (42)")
    connection.commit()
    connection.close()
    

    The direct linked and client server tnsnames.ora entries for TimesTen 18.1.2.3 sampledb is:

    sampledb =(DESCRIPTION=(CONNECT_DATA = (SERVICE_NAME = sampledb)(SERVER = timesten_direct)))

    sampledbCS =(DESCRIPTION=(CONNECT_DATA = (SERVICE_NAME = sampledbCS)(SERVER = timesten_client)))

    As always, you need to source bin/ttenv.sh to configure the environment!

    On my Ubuntu 16.04 machine, my PATH and LD_LIBRARY_PATH were:

    echo $PATH /home/ubuntu/tt18123/bin:/home/ubuntu/tt18123/install/bin:/home/ubuntu/tt18123/install/ttoracle_home/instantclient_11_2:/home/ubuntu/tt18123/install/ttoracle_home/instantclient_11_2/sdk:/home/ubuntu/.cargo/bin:/home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

    echo $LD_LIBRARY_PATH /home/ubuntu/tt18123/ttclasses/lib:/home/ubuntu/tt18123/install/lib:/home/ubuntu/tt18123/install/ttoracle_home/instantclient_11_2

    echo $TNS_ADMIN /home/ubuntu/tt18123/install/network/admin/samples

    Oracle TimesTen will officially support ODPI-C and cx_Oracle in TimesTen 18.1.3

    Please avoid using any ODBC based python libraries with TimesTen as cx_Oracle is what Oracle Development tests and develops against.

    0 讨论(0)
  • 2021-01-14 20:52

    @ScalableDBDoug, would you mind providing the python code snippet? I tried using cx_Oracle in python script but was getting error message:

    cx_Oracle.DatabaseError: ORA-12547: TNS:lost contact
    

    Here is my code snippet:

    
    import cx_Oracle
    
    dsn_tns = cx_Oracle.makedsn('TTSERVER',TTPORT,service_name='TTSERVICE');
    print(dsn_tns)
    connection = cx_Oracle.connect('USER', 'PASS', dsn_tns)
    
    cursor = connection.cursor()
    cursor.execute("""SELECT * FROM MYTABLE""")
    for record in cursor:
        print("Values:", record)
    

    As a workaround I'm using UnixODBC and pyodbc to query the timesten database for now, But would like to use the native cx_Oracle module to access timesten.

    Thanks,

    0 讨论(0)
  • 2021-01-14 20:55

    There is pyodbc which is supposed to work on odbc databases. I'm not sure if it'll actually work. I think pyodbc requires odbc 3, and timesten might not support that (haven't checked), but it is worth checking out.

    There is also mxODBC, which I have not tried. That might work as well.

    Right, so here's an update since I tried it out: (Assuming you're on some sort of unix) It actually works with pyodbc together with unixodbc. pyodbc requires ODBC3.x and TimesTen don't support that. But, unixodbc will "translate" between the two for you. That means you can't use the timesten libodbc.so from pyodbc, since that is missing a bunch of functions from ODBC3.

    0 讨论(0)
  • 2021-01-14 20:58

    The best way to access TimesTen via a Python module is using cx_Oracle.

    cx_Oracle uses an OCI based driver. TimesTen supports OCI and you can connect via tnsnames.ora or the Easy Connect naming method like you would for an Oracle DB.

    0 讨论(0)
提交回复
热议问题