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). Is anyone aware of such module? The last resort is write the wrapper myself but this is something I really want to avoid.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
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.
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.
@ScalableDBDoug, would you mind providing the python code snippet? I tried using cx_Oracle in python script but was getting error message:
Here is my code snippet:
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,
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]
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.
I didn't find native one, but TimesTen has ODBC interface that you could use.
http://www.compwisdom.com/topics/ODBC