Python connection to DM8 database

Keywords: Python Database Big Data DM8

1. Test environment

Add, delete, modify and query Python version 2.7.5 and DM8 database in Window. The following are the notes on stepping on the pit.

Softwareedition
DM databaseDM 8.0 and above
PythonPython 2.7.5
Window10 professionalWindow10 professional

Note: in case of error reporting during implementation, you must see whether there is a solution to your problem in Q & A.

2. Steps

2.1 installing Python

Users should download and install Python by themselves. Python version 2.7.5 installed

2.2 initializing dmPython

  1. dmPython is under the installation directory of Damon database, and the path is * * [database installation path] / drivers/python * * (my installation path is D:\damba\dm8\drivers\python\dmPython)

  1. Enter dmPython to compile and execute the following command

    python setup.py install
    

As shown in the figure, the installation is successful.

If the following prompt error appears: Microsoft Visual C + + 9.0 is required. Please refer to the solution in [Q & A]

2.3 verification

If the following appears, the installation is successful

2.5 test whether the connection is successful

# !/usr/bin/python
# coding:utf-8
import dmPython

try:
    conn = dmPython.connect(user='SYSDBA', password='SYSDBA', server='localhost', port=5236)
    cursor = conn.cursor()
    print('python: conn success!')
    conn.close()
except (dmPython.Error, Exception) as err:
    print(err)

If shown, it is successful.

As shown in the figure below:

If you are prompted with ImportError: DLL load failed: the specified module cannot be found. Please check in [Q & A]

2.6 addition, deletion, modification and query

#!/usr/bin/python
# coding:utf-8
import dmPython

try:
    conn = dmPython.connect(user='SYSDBA', password='SYSDBA', server='localhost', port=5236)
    cursor = conn.cursor()
    try:
        # Empty the table and initialize the test environment
        cursor.execute('delete from PRODUCTION.PRODUCT_CATEGORY')
    except (dmPython.Error, Exception) as err:
        print(err)
    try:
        # insert data
        cursor.execute("insert into PRODUCTION.PRODUCT_CATEGORY(NAME) values('1'), ('2'), ('3'), ('4')")
        print('python: insert success!')
        # Delete data
        cursor.execute("delete from PRODUCTION.PRODUCT_CATEGORY where name='1'")
        print('python: delete success!')

        # Update data
        cursor.execute('update PRODUCTION.PRODUCT_CATEGORY set name = \'222\' where name=\'2\'')
        print('python: update success!')

        # Query data
        cursor.execute("select name from PRODUCTION.PRODUCT_CATEGORY")
        res = cursor.fetchall()
        for tmp in res:
            for c1 in tmp:
                print c1

        print('python: select success!')
    except (dmPython.Error, Exception) as err1:
        print (err1)
    conn.close()
except (dmPython.Error, Exception) as err:
    print(err)

Q&A

1. pip failed to install the third-party library

Tip: WARNING: You are using pip version 20.2.3, however version 20.2.4 is available

Reason: the installation of the third-party library failed because the pip version is too low

## Directly enter the following command to solve the problem
python -m pip install --upgrade pip

2. error: Microsoft Visual C++ 9.0 is required

Reason: there is no C + + compilation environment when compiling the package, so you only need to install it. Install the vcforpython 27.msi file in the network disk link. When the download is complete, double-click install

[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-2kqvi9ae-163396471188) (Python DM / dm_5. PNG)]

3. Console garbled

Modify the pychart code. The window defaults to gbk.

Solution

4.ImportError: DLL load failed: the specified module cannot be found

When calling Dameng database, you need to call some DLL files of DM database. Because they are not found, an error is reported.

Solution

When the project starts, configure Environment variables in Environment variables

Note: D:\damba\dm8 is the installation path of my local dm and needs to be replaced with your own.

PYTHONUNBUFFERED=1;PATH=PATH=D:\damba\dm8\drivers\\;D:\damba\dm8\drivers\logmnr\\;D:\damba\dm8\bin

data

Link: https://pan.baidu.com/s/1Xv8xmy83VbA42FVk7_NtPA extraction code: b2u8

=======================================

If you have any questions, please go to the technology community for feedback.

24-hour free service hotline: 400 991 6599

Dameng technology community: https://eco.dameng.com

Posted by sherrilljjj on Mon, 11 Oct 2021 11:11:41 -0700