python 访问 TimesTen

发布于 2024-12-13 16:35:01 字数 122 浏览 2 评论 0原文

我在谷歌上搜索了很多,找到了任何Python模块来访问TimesTen(在内存数据库中)。 我正在编写一个自动化测试框架(更像是系统测试而不是单元测试)。有人知道这样的模块吗?最后的手段是自己编写包装器,但这是我真正想避免的事情。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

执着的年纪 2024-12-20 16:35:01

要将 Python 与 TimesTen(11.2 或 18.1)一起使用,您应该使用 cx_Oracle

cx_Oracle 的工作方式相同对于 TimesTen 和 Oracle RDBMS

cx_Oracle 使用 ODPI-COCI 的 C 库包装器

对于 TimesTen 和 Oracle RDBMS,cx_Oracle 可以使用 轻松连接方法或tnsnames.ora

以下 cx_Oracle 示例使用 tnsnames.ora [即 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()

TimesTen 18.1.2.3 Sampledb 的直接链接和客户端服务器 tnsnames.ora 条目为:

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

sampledbCS =(描述=(CONNECT_DATA =(SERVICE_NAME = SampledbCS)(SERVER = timesten_client)))

与往常一样,您需要源 bin/ttenv.sh 来配置环境!

在我的 Ubuntu 16.04 机器上,我的 PATH 和 LD_LIBRARY_PATH 是:

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/instantclie nt_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

回显$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 将在 TimesTen 18.1.3 中正式支持 ODPI-C 和 cx_Oracle

请避免在 TimesTen 中使用任何基于 ODBC 的 python 库,因为 cx_Oracle 是 Oracle 开发测试和开发的对象。

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.

末骤雨初歇 2024-12-20 16:35:01

我没有找到本机的,但 TimesTen 有 ODBC
您可以使用的界面。

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

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

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

过度放纵 2024-12-20 16:35:01

pyodbc 应该适用于 odbc 数据库。我不确定它是否真的有效。我认为 pyodbc 需要 odbc 3,而 timesten 可能不支持它(尚未检查),但值得检查。

还有mxODBC,我没有尝试过。这也可能有效。

是的,这是我尝试后的更新:
(假设你使用的是某种unix)
它实际上可以与 pyodbc 以及 unixodbc. pyodbc 需要 ODBC3.x,而 TimesTen 不支持。但是,unixodbc 将为您在两者之间进行“翻译”。
这意味着您不能使用 pyodbc 中的 timesten libodbc.so,因为它缺少 ODBC3 中的一堆函数。

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.

梦在深巷 2024-12-20 16:35:01

通过 Python 模块访问 TimesTen 的最佳方法是使用 cx_Oracle

cx_Oracle 使用基于 OCI 的驱动程序。
TimesTen 支持 OCI,您可以通过 tnsnames.ora 或 Easy Connect 命名方法进行连接,就像连接 Oracle DB 一样。

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.

终止放荡 2024-12-20 16:35:01

@ScalableDBDoug,您介意提供 python 代码片段吗?我尝试在 python 脚本中使用 cx_Oracle,但收到错误消息:

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

这是我的代码片段:


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)

作为解决方法,我现在使用 UnixODBC 和 pyodbc 来查询 timesten 数据库,但想使用本机 cx_Oracle 模块来访问 timesten。

谢谢,

@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,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文