【问题标题】:Is there a way to select schema in python hdbcli dbapi?有没有办法在 python hdbcli dbapi 中选择模式?
【发布时间】:2020-09-17 06:29:56
【问题描述】:

根据documentation,连接HANA数据库需要的参数是主机、端口、用户和密码。

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

这默认选择用户名作为架构。有没有办法指定架构名称?

【问题讨论】:

    标签: python hana python-db-api


    【解决方案1】:

    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',)]
    

    这对我来说效果很好,除了设置架构的附加命令外,我没有看到任何副作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2020-04-05
      • 2018-12-04
      • 2014-06-18
      • 1970-01-01
      相关资源
      最近更新 更多