在python hdbcli dbapi中有选择模式的方法吗?

在python hdbcli dbapi中有选择模式的方法吗?,python,hana,python-db-api,Python,Hana,Python Db Api,根据,连接HANA数据库所需的参数为主机、端口、用户和密码 from hdbcli import dbapi conn = dbapi.connect( address="<hostname>", port=3<NN>MM, user="<username>", password="<password>" ) cursor = conn.cursor()

根据,连接HANA数据库所需的参数为主机、端口、用户和密码

from hdbcli import dbapi
conn = dbapi.connect(
    address="<hostname>",
    port=3<NN>MM,
    user="<username>",
    password="<password>"
)
cursor = conn.cursor()

默认情况下,这会选择用户名作为模式。有没有办法指定架构名称?

AFAIK没有允许设置/切换到特定架构的连接属性

但是,您可以轻松地做到的是,在创建连接后立即切换到所需的模式:

conn = dbapi.connect(
    address = 'hxehost',
    port = '39013',       # connecting to the HANA system, not the DB directly
    user = '...',
    password = '...',
    databasename = 'HXE', # using the DB name instead of a port number
    #key='USER1UserKey', # address, port, user and password are retreived from the hdbuserstore
    encrypt=True, # must be set to True when connecting to HANA Cloud
    sslValidateCertificate=False # True HC, False for HANA Express.
)

#If no errors, print connected
print('connected')

c1 = conn.cursor()
c1.execute("SET SCHEMA R_C")       # <-- here we set the current schema for the connection
c1.execute("SELECT current_schema FROM DUMMY") # <-- checking the current schema
rows = c1.fetchall();          # <-- [('R_C',)]
这对我来说很好,除了设置模式的额外命令之外,我没有看到任何副作用