达梦数据库DM8 dmPython

dmPython DM 提供的依据 Python DB API version 2.0 API 使用规定而开发的数据库访问接口。dmPython 实现这些 API,使 Python 应用程序能够对 DM 数据库进行访问。

1、环境

操作系统:NeoKylin 7

python版本:2.7.5

[root@localhost ~]# cat /etc/issue
NeoKylin Linux Advanced Server release V7
[root@localhost ~]$ python -V
Python 2.7.5

数据库版本:DM8

SQL> select * from v$version;

行号     BANNER                   
---------- -------------------------
1          DM Database Server 64 V8 
2          DB Version: 0x7000a

2、安装dmPython

 
# 添加环境变量
[root@localhost ~]# cat ~/.bash_profile 
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/dm/bin"
export DM_HOME="/dm"

[root@localhost ~]# unzip dmPython.zip
[root@localhost ~]# cd dmPython
[root@localhost dmPython]# python setup.py install
...
In file included from py_Dameng.c:3:0:
py_Dameng.h:8:20: fatal error: Python.h: No such file or directory
 #include 
                    ^
compilation terminated.
error: command 'gcc' failed with exit status 1

# 安装python-devel
[root@localhost dmPython]# yum install python-devel
Installed:
  python-devel.x86_64 0:2.7.5-88.el7

[root@localhost dmPython]# python setup.py install
Installed /usr/lib64/python2.7/site-packages/dmPython-2.3-py2.7-linux-x86_64.egg
Processing dependencies for dmPython==2.3
Finished processing dependencies for dmPython==2.3

3、使用dmPython操作数据库

[root@localhost ~]# python
Python 2.7.5 (default, Apr  2 2020, 13:16:51) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import dmPython

# 连接数据库
>>> conn=dmPython.connect(user='SYSDBA',password='***',server= 'LOCALHOST',port=5236)
# 建立游标
>>> cursor = conn.cursor()

# 查询
>>> cursor.execute('select NAME, CREATE_TIME from v$database')
<__builtin__.DmdbCursor on >
>>> values = cursor.fetchall()
>>> values
[('DAMENG', datetime.datetime(2020, 7, 31, 17, 33, 28))]


# 关闭游标
>>> cursor.close()
关闭连接
>>> conn.close()

 

你可能感兴趣的:(达梦数据库)