Develop Python connection to Damon database (DM8)

Keywords: Python Database




dmPython is a database access interface provided by DM and developed according to the API usage regulations in Python DB API version 2.0
dmPython implements these API s to enable Python applications to access DM databases

My understanding is:
dmPython is the third-party library of python, which provides some modules and methods to access DM database (for example, python program can connect DM database by calling the method dmPython.connect)


dmPython completes python module extension by calling DM DPI interface
In addition to the Python standard library, the running environment of DPI is also required

My understanding is:
Compared with DM DPI, dmPython is more advanced and abstract (it is an interface designed for Python, similar to DM PHP of PHP); DM DPI is responsible for implementing some lower level modules or methods (that is, I think DM DPI is an interface designed for DM database), so dmPython needs to call DM DPI

[to sum up]
In my opinion, the interaction between PHP program and DM database = PHP program + dmPython + DM DPI + DM database

Environment introduction

DM databaseDM8
PythonPython 3.7.9

Install DM8 database

reference resources:

Install Python

  • Steps for installing Python (omitted temporarily)
Python The version is as follows
[root@dw1 dpi]# python3 --version
Python 3.7.9
  • Compile and install dmPython

Check the compiler gcc (if not, install it)

[root@dw1 dpi]# rpm -qa|grep gcc

Check whether there is Python 3-devel (if not, install it)

[root@dw1 dpi]# rpm -qa|grep python3-devel

After installing the DM database software, find the driver source code of dmPython in the drivers directory under the installation path

[root@dw1 python]# cd /home/dmdba/dmdbms/drivers/python
[root@dw1 python]# ls
django155  django196  django223  django317  dmPython  sqlalchemy

Enter the dmPython driver source directory

[root@dw1 python]# cd dmPython/
[root@dw1 dmPython]# pwd

Application scenario of build tool

Compile and install the python package dmPython and install it into the specified Python library

[root@dw1 dmPython]# python3 install

After compiling and installing, dmPython Installed in the following directory
[root@dw1 dmPython-2.3-py3.7-linux-x86_64.egg]# pwd

You can see the generation file
[root@dw1 dmPython-2.3-py3.7-linux-x86_64.egg]# ll
-rw-r--r-- 1 root root 313 11 June 30-15:24

[Note 1]
The source code of dmPython depends on the include header file provided in the DM installation directory. Before compiling and installing, you need to check whether the DM database software is installed and set DM_HOME environment variable.

Here, run the Python program directly on the server where the DM database is installed

  • Check dmPython installation

After compilation and installation, use the pip3 list command to check whether the installation is successful

[root@dw1 dmPython]# pip3 list | grep dmPython
dmPython               2.3
  • Set LD_LIBRARY_PATH environment variable

dmPython completes Python module extension by calling DM DPI interface. In addition to the python standard library, the running environment of DPI is also required.

Configure environment variables LD_LIBRARY_PATH´╝îEasy to call You can find it
vi /root/.bash_profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/dmdba/dmdbms/drivers/dpi/
source /root/.bash_profile

Interact with DM database using Python

Interact with the database through Python interactive programming

[Note 1]
The IP, port, user name and password of the database shall be modified according to the actual situation

Python returns the same result as the disql query (SYSSSO, SYSDBA, SYS, SYSAUDITOR)

SQL> select username from dba_users;

Line number     username  
---------- ----------
1          SYSSSO
2          SYSDBA
3          SYS
4          SYSAUDITOR

Elapsed time: 4.973(millisecond). Execution number:1200.

The python code is as follows:

import dmPython
conn=dmPython.connect(user='SYSDBA',password='SYSDBA',server='', port=5236)
cursor = conn.cursor()
cursor.execute('select username from dba_users')
values = cursor.fetchall()

Damon cloud adaptation Center:

Posted by Ruud Hermans on Thu, 02 Dec 2021 14:39:58 -0800