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 Log4j:运行服务器日志时发出警告   ssl与Java通信到TLSEncypted CUPS打印服务器   Guice Java提供的方法没有已知的依赖关系?   java Android:EditText的默认文本大小是多少?   更正错误字符串的Java异常   string Java如何从来自多个源的数据推断类型   从路径错误创建java文件   java获取不同类安卓中切换按钮的状态   java扩展AnyVal和AnyRef的对象的内存分配有什么不同   java如何从callable(即runnable)获取类名   java Hornetq大量消息填满了磁盘空间   用java从excel中读取一行的多列?   java不使用JAXB将映射转换为XML   java将多个图像与一个图像进行比较   当X扩展Y时,javax不适用于参数Y   运行时jar文件中未显示java Python输出   JavaSpringMVC3:定义自己的DatatypeBinding   java从fragment类调用activity函数给出了NPE   java在时区、日历和SimpleDataFormat方面存在奇怪的问题