达梦数据库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 <Python.h>
                    ^
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 <dmPython.Connection to SYSDBA@LOCALHOST:5236>>
>>> values = cursor.fetchall()
>>> values
[('DAMENG', datetime.datetime(2020, 7, 31, 17, 33, 28))]


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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值