SAP HANA Python客户端

hdbcli的Python项目详细描述


简介

python数据库api规范v2.0(pep 249)定义了一组方法,这些方法提供了与实际使用的数据库无关的一致的数据库接口。sap hana的python扩展模块实现了pep 249。安装模块后,可以从python访问和更改sap hana数据库中的信息。

在PEP 249中,自动提交在默认情况下处于关闭状态。在sap hana python驱动程序中,autocommit在默认情况下处于打开状态。

有关信息,请参见:PEP 249 – Python Database API Specification v2.0

开始

通过pip install hdbcli安装或通过HANA Client Install手动安装

快速启动

  • For HANA tenant databases, use the port number 3**NN**13 (where NN is the SAP instance number - e.g. 30013).
  • For HANA system databases in a multitenant system, the port number is 3**NN**13.
  • For HANA single-tenant databases, the port number is 3**NN**15.
from hdbcli import dbapi
conn = dbapi.connect(
    address="<hostname>",
    port=3<NN>MM,
    user="<username>",
    password="<password>"
)
cursor = conn.cursor()

执行不返回结果集的单个语句:

cursor.execute("CREATE TABLE T1 (ID INTEGER PRIMARY KEY, C2 VARCHAR(255))")
cursor.close()

使用问号参数绑定将值插入到上面创建的T1表中。参数值以python序列的形式提供,可以是文本值或变量名。本例使用文字值:

sql = 'INSERT INTO T1 (ID, C2) VALUES (?, ?)'
cursor = conn.cursor()
cursor.execute(sql, (1, 'hello'))
# returns True
cursor.execute(sql, (2, 'hello again'))
# returns True
cursor.close()

使用命名参数绑定将值插入T1表。这些值作为python字典提供,本例使用变量名。

sql = 'INSERT INTO T1 (ID, C2) VALUES (:id, :c2)'
cursor = conn.cursor()
id = 3
c2 = "goodbye"
cursor.execute(sql, {"id": id, "c2": c2})
# returns True
cursor.close()

在结果集的行上循环。

sql = 'SELECT * FROM T1'
cursor = conn.cursor()
cursor.execute(sql)
for row in cursor:
    print(row)

帮助

有关使用sap hana python客户端开发的详细信息,请参见SAP HANA Client Interface Programming Reference

许可证

hana python客户端是通过SAP Developer License Agreement提供的。

通过使用本软件,您同意将以下文本纳入开发人员协议的条款中:

If you are an existing SAP customer for On Premise software, your use of this current software is also covered by the terms of your software license agreement with SAP, including the Use Rights, the current version of which can be found at: https://www.sap.com/about/agreements/product-use-and-support-terms.html?tag=agreements:product-use-support-terms/on-premise-software/software-use-rights

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android编程存储的图像在PC上的格式无效   安卓无法通过Java代码使按钮变宽   java在Spring事务中的行为差异需要新的和嵌套的传播   java如何在Ubuntu上构建javafuse?   java不支持Eclipse包包含javac。exe   读取大文件时java StAX解析器的xml问题   连接到mysql时java通信链路故障   java WebSphere web容器线程的最大线程状态为runnable   为什么我需要添加双引号来打印java中字符数组的第一个和最后一个元素   java Hibernate在更新现有父实体时不创建新的子实体   java创建JSON格式输出   java SonarQube与Eclipse   无法从静态上下文引用java非静态方法toString   java位集向后显示值?   java为什么maven不从TestClass生成源代码?   java在实践中,在catch块中抛出异常是否有用?   java如何通过FileinputStream添加还原设置功能   java复制记事本中的所有内容并粘贴到网页的文本区域