前面的几篇博客我们看了SQLite、Mysql、Oracle数据库的封装,本篇看下达梦数据库的封装.
https://www.cndba.cn/Dave/article/3827
1 测试环境
操作系统本:
[root@dm8 dmPython]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)
[root@dm8 dmPython]#
达梦数据库版本:
[root@dm8 dmPython]# disql SYSDBA/SYSDBA
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间: 7.944(毫秒)
disql V8
SQL> select * from v$version;
行号 BANNER
---------- -------------------------
1 DM Database Server 64 V8
2 DB Version: 0x7000a
已用时间: 1.862(毫秒). 执行号:3186.
SQL>
注意我这里的DM8 是测试版,所以版本和官方下载的不一样。
2 安装dmPython
Python 有现成的mysql,oracle 等数据库包,可以直接import 使用,但对于达梦数据库,必须首先安装dmPython,才可以使用。
在$DM_HOME/drivers 目录下有多种类型的驱动:
[dmdba@dm8 ~]$ cd /dm/dmdbms/drivers/
[dmdba@dm8 drivers]$ ls
dci dpi jdbc node.js oci odbc php_pdo python
[dmdba@dm8 drivers]$
[dmdba@dm8 drivers]$ cd python/
[dmdba@dm8 python]$ ls
dmPython third
[dmdba@dm8 python]$ cd dmPython/
[dmdba@dm8 dmPython]$ ls
Buffer.c dmPython.vcxproj Error.c exObject.c row.c tObject.c var_pub.h vInterval.c vObject.c
Buffer.h dmPython.vcxproj.filters Error.h py_Dameng.c row.h trc.c vBfile.c vLob.c vString.c
Connection.c dmPython.vcxproj.user exBfile.c py_Dameng.h setup.py trc.h vCursor.c vlong.c
Cursor.c Environment.c exLob.c README.txt strct.h var.c vDateTime.c vNumber.c
[dmdba@dm8 dmPython]$
这里我们需要手工安装dmPython 包。 进入dmPython目录后执行命令:python setup.py install
命令虽简单,但过程插曲比较多。https://www.cndba.cn/Dave/article/3827https://www.cndba.cn/Dave/article/3827
2.1 插曲一:
[dmdba@dm8 dmPython]$ python setup.py install
running install
error: can't create or remove files in install directory
The following error occurred while trying to add or remove files in the
installation directory:
[Errno 13] Permission denied: '/usr/lib64/python2.7/site-packages/test-easy-install-3032.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/lib64/python2.7/site-packages/
Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.
For information on other options, you may wish to consult the
documentation at:
https://pythonhosted.org/setuptools/easy_install.html
Please make the appropriate changes for your system and try again.
[dmdba@dm8 dmPython]$
根据提示,需要使用roo