[英]Is there a way to select schema in python hdbcli dbapi?
According to documentation , parameters needed to connect to HANA database are host, port, user and password.根据文档,连接到 HANA 数据库所需的参数是主机、端口、用户和密码。
from hdbcli import dbapi
conn = dbapi.connect(
address="<hostname>",
port=3<NN>MM,
user="<username>",
password="<password>"
)
cursor = conn.cursor()
This selects username as schema by default.这默认选择用户名作为架构。 Is there a way to specify schema name?
有没有办法指定架构名称?
AFAIK there is no connection property that would allow setting/switching to a specific schema. AFAIK 没有允许设置/切换到特定模式的连接属性。
What you can easily do, however, is to switch to your intended schema right after creating the connection:但是,您可以轻松地做的是在创建连接后立即切换到您想要的模式:
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',)]
This works well for me and I don't see any side-effects besides the additional command to set the schema.这对我来说很有效,除了设置架构的附加命令之外,我没有看到任何副作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.