簡體   English   中英

有沒有辦法在 python hdbcli dbapi 中選擇模式?

[英]Is there a way to select schema in python hdbcli dbapi?

根據文檔,連接到 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',)]

這對我來說很有效,除了設置架構的附加命令之外,我沒有看到任何副作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM