Passed
Push — master ( b3d581...f9508c )
by Guangyu
06:53 queued 11s
created

test_mysql   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 21
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A test_connect() 0 20 4
1
import mysql.connector
2
import config
3
4
5
def test_connect():
6
    cursor = None
7
    cnx = None
8
    try:
9
        cnx = mysql.connector.connect(**config.myems_user_db)
10
        cursor = cnx.cursor()
11
12
        query = (" SELECT id, name, display_name, email "
13
                 " FROM tbl_users  "
14
                 " ORDER BY id ")
15
        cursor.execute(query)
16
        rows = cursor.fetchall()
17
        print("The config of database is right:", rows)
18
    except Exception as e:
19
        print("The config of database is wrong:", str(e))
20
    finally:
21
        if cursor:
22
            cursor.close()
23
        if cnx:
24
            cnx.disconnect()
25
26
27
if __name__ == "__main__":
28
    test_connect()
29