当前位置:   article > 正文

InterSystems IRIS使用python pyodbc连接 linux环境,odbc驱动安装,DSN配置,数据源配置,linux中文不展示问题

InterSystems IRIS使用python pyodbc连接 linux环境,odbc驱动安装,DSN配置,数据源配置,linux中文不展示问题

1、官方文档

ODBC Installation and Validation on UNIX® Systems | Using the InterSystems ODBC Driver | InterSystems IRIS for Health 2024.1

By default, a full ODBC installation is performed with a standard InterSystems installation. If you perform a custom installation (as described in the Installation Guide), you can select the “SQL client only” option to install only the client access components (ODBC client driver).

In addition, however, a stand-alone installer is provided for InterSystems ODBC. To use this installer:

  1. Create the directory where you wish to install the client, such as /usr/irisodbc/.

  2. Copy the appropriate zipped tar file into the directory that you just created.

    The ./dist/ODBC/ directory contains zipped tar files with names like the following:

    ODBC-release-code-platform.tar.gz
    
  • where release-code is a release-specific code (that varies among InterSystems versions and releases) and platform specifies the operating system that the ODBC client runs on.

  • Go to the directory you created and manually unpack the .tar file, as follows:

    1. # gunzip ODBC-release-code-platform.tar.gz
    2. # tar xvf ODBC-release-code-platform.tar
  • This creates bin and dev directories and installs a set of files.

  • Run the ODBCInstall program, which will be in the directory that you created. This program creates several sample scripts and configures irisodbc.ini under the mgr directory. For example:

    1. # pwd
    2. /usr/irisodbc
    3. # ./ODBCInstall

2、驱动地址

InterSystems IRIS | Driver Packages

同步到gitee的:于光/iris-driver-distribution

3、ai解读官方文档

根据官方文档提供的信息,以下是在 Linux 系统上安装和配置 ODBC 驱动程序的总结:

### 执行独立安装

1. 创建安装客户端的目录,如 `/usr/irisodbc/`。
2. 将适当的压缩 tar 文件复制到您创建的目录中。
3. 手动解压 `.tar` 文件,创建 `bin` 和 `dev` 目录并安装一组文件。
4. 运行 `ODBCInstall` 程序,该程序位于您创建的目录中,用于创建示例脚本并配置 `irisodbc.ini`。
   
### ODBC 客户端文件

- `libiodbc.so`:iODBC 驱动程序管理器,支持 8 位和 Unicode ODBC API。
- `libodbc.so`:unixODBC 驱动程序管理器,用于 8 位 ODBC API。
- InterSystems ODBC 客户端驱动程序:`libirisodbc35` 支持 8 位 ODBC 3.5,`libirisodbciw35` 支持 Unicode ODBC 3.5。
 
### 设置共享库路径

- 在 UNIX 系统上使用第三方共享库时,必须通过设置 `LD_LIBRARY_PATH` 来定义 `InterSystems IRIS LibPath` 参数。这是一项安全措施,以防止非特权用户更改路径。

### 故障排除共享对象依赖关系

1. 使用适当的命令列出 InterSystems ODBC 驱动程序的动态依赖项,例如在 Solaris 上使用 `ldd` 命令。
2. 如果没有找到依赖项,则说明所有依赖项都是有效的。如果有错误,请运行命令强制共享对象加载器查找当前目录。
   
以上总结可以帮助您在 Linux 系统上安装和配置 ODBC 驱动程序。如果您需要进一步的帮助或指导,请随时告诉我!

4、ubuntu实操记录,安装odbc驱动

  1. #1 创建路径/usr/irisodbc
  2. root@ubuntu24:/home# cd /usr/
  3. root@ubuntu24:/usr# mkdir irisodbc
  4. root@ubuntu24:/usr# cd irisodbc/
  5. #2 解压驱动 ODBC-2023.1.0.229.0-lnxubuntu2204x64.tar.gz
  6. root@ubuntu24:/usr/irisodbc# ls
  7. ODBC-2023.1.0.229.0-lnxubuntu2204x64.tar.gz
  8. root@ubuntu24:/usr/irisodbc# tar -zxvf ODBC-2023.1.0.229.0-lnxubuntu2204x64.tar.gz
  9. ODBCinstall
  10. bin/
  11. bin/libirisodbc35.so
  12. bin/libirisodbciw35.so
  13. bin/libirisodbcur6435.so
  14. bin/odbcgateway.so
  15. bin/odbcgatewayiw.so
  16. bin/odbcgatewayur64.so
  17. bin/irisconnect.so
  18. bin/libiodbc.so
  19. bin/libodbc.so
  20. bin/libodbc.so.2
  21. bin/libodbc.so.2.0.0
  22. dev/
  23. dev/odbc/
  24. dev/odbc/redist/
  25. dev/odbc/redist/iodbc/
  26. dev/odbc/redist/iodbc/odbc.ini_iODBCtemplate
  27. dev/odbc/redist/iodbc/include/
  28. dev/odbc/redist/unixodbc/
  29. dev/odbc/redist/unixodbc/odbcinst.ini_unixODBCtemplate
  30. dev/odbc/redist/unixodbc/readme.txt
  31. dev/odbc/redist/unixodbc/odbc.ini_unixODBCtemplate
  32. dev/odbc/redist/unixodbc/include/
  33. dev/odbc/redist/unixodbc/include/autotest.h
  34. dev/odbc/redist/unixodbc/include/ini.h
  35. dev/odbc/redist/unixodbc/include/log.h
  36. dev/odbc/redist/unixodbc/include/lst.h
  37. dev/odbc/redist/unixodbc/include/odbcinst.h
  38. dev/odbc/redist/unixodbc/include/odbcinstext.h
  39. dev/odbc/redist/unixodbc/include/odbctrac.h
  40. dev/odbc/redist/unixodbc/include/odbctrace.h
  41. dev/odbc/redist/unixodbc/include/sql.h
  42. dev/odbc/redist/unixodbc/include/sqlext.h
  43. dev/odbc/redist/unixodbc/include/sqlspi.h
  44. dev/odbc/redist/unixodbc/include/sqltypes.h
  45. dev/odbc/redist/unixodbc/include/sqlucode.h
  46. dev/odbc/redist/unixodbc/include/sqp.h
  47. dev/odbc/redist/unixodbc/include/unixodbc_conf.h
  48. dev/odbc/redist/unixodbc/include/uodbc_extras.h
  49. dev/odbc/redist/unixodbc/include/uodbc_stats.h
  50. dev/odbc/redist/unixodbc/libodbcinst.so
  51. dev/odbc/redist/unixodbc/libodbcinst.so.2
  52. dev/odbc/redist/unixodbc/libodbcinst.so.2.0.0
  53. dev/odbc/redist/unixodbc/isql
  54. dev/odbc/redist/unixodbc/iusql
  55. dev/odbc/redist/unixodbc/odbcinst
  56. dev/odbc/redist/ssl/
  57. dev/odbc/redist/ssl/readme.txt
  58. dev/odbc/redist/ssl/odbcssl.ini.template
  59. dev/odbc/redist/ssl/irisodbc.ini.template
  60. # 解压后情况
  61. root@ubuntu24:/usr/irisodbc# ls
  62. bin dev ODBC-2023.1.0.229.0-lnxubuntu2204x64.tar.gz ODBCinstall
  63. root@ubuntu24:/usr/irisodbc# ll
  64. total 4636
  65. drwxr-xr-x 4 root root 4096 Jul 15 14:16 ./
  66. drwxr-xr-x 15 root root 4096 Jul 15 14:15 ../
  67. drwxrwxr-x 2 root root 4096 Apr 14 2023 bin/
  68. drwxr-xr-x 3 root root 4096 Apr 14 2023 dev/
  69. -rw-r--r-- 1 root root 4720787 Jul 15 14:16 ODBC-2023.1.0.229.0-lnxubuntu2204x64.tar.gz
  70. -rwxrwxr-x 1 root root 4501 Apr 14 2023 ODBCinstall*
  71. root@ubuntu24:/usr/irisodbc# pwd
  72. /usr/irisodbc
  73. root@ubuntu24:/usr/irisodbc# ls
  74. bin dev ODBC-2023.1.0.229.0-lnxubuntu2204x64.tar.gz ODBCinstall
  75. root@ubuntu24:/usr/irisodbc# cd /usr/irisodbc
  76. root@ubuntu24:/usr/irisodbc# ll
  77. total 4636
  78. drwxr-xr-x 4 root root 4096 Jul 15 14:16 ./
  79. drwxr-xr-x 15 root root 4096 Jul 15 14:15 ../
  80. drwxrwxr-x 2 root root 4096 Apr 14 2023 bin/
  81. drwxr-xr-x 3 root root 4096 Apr 14 2023 dev/
  82. -rw-r--r-- 1 root root 4720787 Jul 15 14:16 ODBC-2023.1.0.229.0-lnxubuntu2204x64.tar.gz
  83. -rwxrwxr-x 1 root root 4501 Apr 14 2023 ODBCinstall*
  84. # 安装驱动 可见创建了一个文件irisodbc.ini文件。
  85. root@ubuntu24:/usr/irisodbc# ./ODBCinstall
  86. Creating irisodbc.ini ...
  87. Done setting up ODBC and SQLGateway!
  88. root@ubuntu24:/usr/irisodbc# ls
  89. bin dev mgr ODBC-2023.1.0.229.0-lnxubuntu2204x64.tar.gz ODBCinstall
  90. # 查找文件路径 /usr/irisodbc/mgr/irisodbc.ini
  91. root@ubuntu24:/usr/irisodbc# find /usr/irisodbc/ -name "irisodbc.ini"
  92. /usr/irisodbc/mgr/irisodbc.ini
  93. root@ubuntu24:/usr/irisodbc# ll
  94. total 4640
  95. drwxr-xr-x 5 root root 4096 Jul 15 14:17 ./
  96. drwxr-xr-x 15 root root 4096 Jul 15 14:15 ../
  97. drwxrwxr-x 2 root root 4096 Apr 14 2023 bin/
  98. drwxr-xr-x 3 root root 4096 Apr 14 2023 dev/
  99. drwxr-xr-x 2 root root 4096 Jul 15 14:17 mgr/
  100. -rw-r--r-- 1 root root 4720787 Jul 15 14:16 ODBC-2023.1.0.229.0-lnxubuntu2204x64.tar.gz
  101. -rwxrwxr-x 1 root root 4501 Apr 14 2023 ODBCinstall*
  102. root@ubuntu24:/usr/irisodbc# cd mgr/
  103. root@ubuntu24:/usr/irisodbc/mgr# ls
  104. irisodbc.ini
  105. # 该驱动默认的DSN连接配置,如果直接用dsn连接,直接用dsn=User,或者dsn=Userunixodbc
  106. # 看配置的driver驱动配置:/usr/irisodbc/bin/libirisodbc35.so, 说明iris的驱动就是这个so文件,所以代码里面配置这个路径
  107. root@ubuntu24:/usr/irisodbc/mgr# cat irisodbc.ini
  108. [ODBC Data Sources]
  109. User = User
  110. Userunixodbc = Userunixodbc
  111. [User]
  112. Driver = /usr/irisodbc/bin/libirisodbc35.so
  113. Description = IRIS ODBC driver
  114. Host = localhost
  115. Namespace = USER
  116. UID = _SYSTEM
  117. Password = SYS
  118. Port = 1972
  119. Protocol = TCP
  120. Query Timeout = 1
  121. Static Cursors = 0
  122. Trace = off
  123. TraceFile = iodbctrace.log
  124. Authentication Method = 0
  125. Security Level = 2
  126. Service Principal Name = iris/localhost.domain.com
  127. [Userunixodbc]
  128. Driver = /usr/irisodbc/bin/libirisodbcur6435.so
  129. Description = IRIS ODBC driver
  130. Host = localhost
  131. Namespace = USER
  132. UID = _SYSTEM
  133. Password = SYS
  134. Port = 1972
  135. Protocol = TCP
  136. Query Timeout = 1
  137. Static Cursors = 0
  138. Trace = off
  139. TraceFile = iodbctrace.log
  140. Authentication Method = 0
  141. Security Level = 2
  142. Service Principal Name = iris/localhost.domain.com
  143. root@ubuntu24:/usr/irisodbc/mgr# ls
  144. irisodbc.ini
  145. # python查询版本
  146. root@ubuntu24:/usr/irisodbc/mgr# cd /home/code/
  147. root@ubuntu24:/home/code# vim c1.py
  148. root@ubuntu24:/home/code# python3 c1.py
  149. ('',)
  150. root@ubuntu24:/home/code# python3 c1.py
  151. ('',)
  152. root@ubuntu24:/home/code# cat c1.py
  153. import pyodbc
  154. driver = '/usr/irisodbc/bin/libirisodbc35.so'
  155. server = 'ip'
  156. database = 'test'
  157. username = ''
  158. password = ''
  159. port = '1927'
  160. cnxn = pyodbc.connect(Driver=driver, Server=server, Database=database, UID=username, PWD=password, Port=port)
  161. cursor = cnxn.cursor()
  162. cursor.execute("SELECT $ZVERSION")
  163. row = cursor.fetchone()
  164. while row:
  165. print(row)
  166. row = cursor.fetchone()
  167. cnxn.close()
  168. # python select 1
  169. root@ubuntu24:/home/code# cp c1.py c2.py
  170. root@ubuntu24:/home/code# vim c2.py
  171. root@ubuntu24:/home/code# python3 c2.py
  172. (1,)
  173. root@ubuntu24:/home/code# cat c2.py
  174. import pyodbc
  175. driver = '/usr/irisodbc/bin/libirisodbc35.so'
  176. server = 'ip'
  177. database = 'test'
  178. username = ''
  179. password = ''
  180. port = '1927'
  181. cnxn = pyodbc.connect(Driver=driver, Server=server, Database=database, UID=username, PWD=password, Port=port)
  182. cursor = cnxn.cursor()
  183. cursor.execute("SELECT 1")
  184. row = cursor.fetchone()
  185. while row:
  186. print(row)
  187. row = cursor.fetchone()
  188. cnxn.close()
  189. root@ubuntu24:/home/code#
  190. root@ubuntu24:/home/code#

5、python代码

  1. import pyodbc
  2. driver = '/usr/irisodbc/bin/libirisodbc35.so'
  3. server = 'xxx'
  4. database = 'xxx'
  5. username = 'xxx'
  6. password = 'xxx'
  7. port = '1927'
  8. cnxn = pyodbc.connect(Driver=driver, Server=server, Database=database, UID=username, PWD=password, Port=port)
  9. cursor = cnxn.cursor()
  10. cursor.execute("SELECT 1")
  11. row = cursor.fetchone()
  12. while row:
  13. print(row)
  14. row = cursor.fetchone()
  15. cnxn.close()

6、中文显示空字符串问题

增加

  1. ###ensure it reads strings correctly.
  2. cnxn.setdecoding(pyodbc.SQL_CHAR, encoding='utf8')
  3. cnxn.setdecoding(pyodbc.SQL_WCHAR, encoding='utf8')
  4. cnxn.setencoding(encoding='utf8')
  1. root@ubuntu:/home/code# cat c1.py
  2. import pyodbc
  3. driver = '/usr/irisodbc/bin/libirisodbc35.so'
  4. server = 'ip'
  5. database = ''
  6. username = ''
  7. password = ''
  8. port = '1972'
  9. cnxn = pyodbc.connect(Driver=driver, Server=server, Database=database, UID=username, PWD=password, Port=port)
  10. ###ensure it reads strings correctly.
  11. cnxn.setdecoding(pyodbc.SQL_CHAR, encoding='utf8')
  12. cnxn.setdecoding(pyodbc.SQL_WCHAR, encoding='utf8')
  13. cnxn.setencoding(encoding='utf8')
  14. cursor = cnxn.cursor()
  15. cursor.execute("SELECT $ZVERSION")
  16. row = cursor.fetchone()
  17. while row:
  18. print(row)
  19. row = cursor.fetchone()
  20. cnxn.close()
  21. root@ubuntu:/home/code# vim c1.py
  22. root@ubuntu:/home/code# python3 c1.py
  23. ('IRIS for UNIX (Red Hat Enterprise Linux for x86-64) 2021.1.2 (Build 338_0_21956U) Thu Nov 3 2022 16:05:53 EDT',)
  24. root@ubuntu:/home/code#

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/843162
推荐阅读
相关标签
  

闽ICP备14008679号