-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery1.py
32 lines (27 loc) · 918 Bytes
/
query1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Тест на наличие таблицы `good`
# Проверка наличия таблицы в базе данных, если таблица отсутствует выдать ошибку
import pymysql
import pymysql.cursors
from main_config_base import host, user, password, db_name
try:
connection = pymysql.connect(
host = host,
port = 3306,
user = user,
password = password,
database = db_name,
cursorclass = pymysql.cursors.DictCursor
)
print('success')
print('#' * 30)
try:
with connection.cursor() as cursor:
cursor.execute('SHOW TABLES LIKE "good"')
check_tables = cursor.fetchone()
for table in check_tables:
print(table)
finally:
connection.close()
except Exception as ex:
print('Connection rufus')
print(ex)