有谁知道如何将远程 oracle 数据库与 Robot Framework 连接?

Does anyone know how to connect a distant oracle database with Robot Framework?

我尝试使用 cx_Oracle,但我无法安装它,我收到此消息错误:"cannot locate an Oracle software installation", 是的,我的 PC 上没有 Oracle 服务器,我只有 sqlDeveloper 来测试我的查询。 但是我想在这个远程数据库上使用机器人框架进行一些查询,这可能吗?

是的,这是可能的。

2 个解决方案:

  1. 使用 odbc 驱动程序和 pyodbc

  2. 使用 jtds 驱动程序和 jaydebeapi:

    ${jdbcDriver} 设置变量 '${jdbcDriversPath}/ojdbc6.jar' 使用自定义参数连接到数据库 jaydebeapi 'oracle.jdbc.driver.OracleDriver', ['jdbc:oracle:thin:@//${DB_HOST}:${DB_PORT}/${DB_SSID}','${database}','${DB_PASSWORD}'],${jdbcDriver}

我成功地使用 cx_Oracle 访问了使用 DatabaseLibrary 的 Oracle 数据库。在 Windows 平台上,您

  1. 安装the thin client
  2. 到系统PATH,添加即时客户端文件夹的路径
  3. 安装cx_Oracle

为我们的设置连接到数据库如下所示: Connect To Database Using Custom Params cx_Oracle user='bob', password='letmein', dsn='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=sql1.mycompany.com)(PORT=1521)))(CONNECT_DATA=(SID=warehouse)))'

安装以下 32 位版本解决了我的问题:

  • 即时客户端包 - 基本
  • 即时客户端包 - SDK

我不知道是什么原因,但 64 位版本的 Oracle 客户端对我不起作用。

安装 miniconda python distribution,这样会更容易。 它带有 conda 包管理器作为 pip 的替代品。安装 cx_oracle 包括即时客户端就这么简单:

 conda install oracle-instantclient
 conda install cx_oracle

它会自动下载匹配的DLL文件并将其放置到condo根目录。这样您就不必为 ORACLE_HOMEPATH 变量以及 python 和 oracle DLL 驱动程序的 32 位与 64 位不匹配而苦恼。

在机器人框架示例中使用它:

*** Settings ***
Documentation  Basic database related keywords
Library  DatabaseLibrary

*** Variables ***
${DB_CONNECT_STRING} =  'user/mypasswd@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myipaddress)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=mysid)))'

*** Keywords ***
Connect
    connect to database using custom params  cx_Oracle  ${DB_CONNECT_STRING}

Disconnect
    disconnect from database