此篇文章给大家介绍一个使用pyodbc连接到 InterSystems IRIS数据库的示例,详情如下:

InterSystems IRIS 安装在Redhat 操作系统中,使用pyodbc在Mac操作系统中连接到Redhat 操作系统中InterSystems IRIS数据库。

  1. 下载测试代码
  2. 使用vscode打开测试代码,并在Solutions文件夹下安装pyodbc
    pip install pyodbc
  3. 在Mac操作系统中安装ODBC驱动
    brew update
    brew install unixodbc
  4. 安装后,查看Mac操作系统中的odbcinst.ini文件,此时odbcinst.ini文件应该是空的。
  5. Mac操作系统中/usr/local/bin下使用下列命令注册驱动 或者 配置DSN
    odbcinst -i -d -f   pyodbc_wheel/mac/odbcinst.ini
    pyodbc_wheel/mac/odbcinst.iniodbcinst -i -s -h -f odbc.ini_unixODBCtemplate
    odbcinst -i -s -l -f pyodbc_wheel/mac/odbcinst.ini
  6. 执行后,查看Mac操作系统中的odbcinst.ini文件,此时odbcinst.ini文件应该是空的, 安装如下信息更改odbcinst.ini文件。
    [InterSystems ODBC]
    Description=InterSystems ODBC
    Driver=pyodbc_wheel/mac/libirisodbc35.so
    Setup=pyodbc_wheel/mac/libirisodbc35.so
    UsageCount=1
  7. 将connection.config连接配置文件里面的内容改成Redhat 操作系统中InterSystems IRIS的连接信息。
    ip: 192.168.157.XX
    port: 51773
    namespace: USER
    username: user
    password: pwd
  8. 运行pyodbcplaystocksTask1.py 文件。会显示“Connected to InterSystems IRIS”,表示成功连接到InterSystems IRIS 。