diff --git a/.idea/EasyTest.iml b/.idea/EasyTest.iml
new file mode 100644
index 0000000..bcde34f
--- /dev/null
+++ b/.idea/EasyTest.iml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..573545d
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,148 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..b7f2385
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..d262650
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/utils/database_control.py b/utils/database_control.py
index a5f74db..886237e 100644
--- a/utils/database_control.py
+++ b/utils/database_control.py
@@ -16,30 +16,21 @@ class MysqlDB:
host=config.mysql_db.host,
user=config.mysql_db.user,
password=config.mysql_db.password,
- port=config.mysql_db.port,
+ port=config.mysql_db.port
)
-
- # 使用 cursor 方法获取操作游标,得到一个可以执行sql语句,并且操作结果为字典返回的游标
self.cur = self.conn.cursor(cursor=pymysql.cursors.DictCursor)
- except AttributeError as error:
- logger.error("数据库连接失败,失败原因 %s", error)
+ except Exception as err:
+ logger.error(f"数据库连接失败, {err}")
def __del__(self):
try:
- # 关闭游标
self.cur.close()
- # 关闭连接
self.conn.close()
- except AttributeError as error:
- logger.error("数据库连接失败,失败原因 %s", error)
+ except Exception as err:
+ logger.error(f'数据库关闭连接失败, {err}')
def query(self, sql, state="all"):
- """
- 查询
- :param sql:
- :param state: all 是默认查询全部
- :return:
- """
+ """ 查询 """
try:
self.cur.execute(sql)
@@ -55,20 +46,16 @@ class MysqlDB:
raise
def execute(self, sql):
- """
- 更新 、 删除、 新增
- :param sql:
- :return:
- """
+ """ 更新 、 删除、 新增 """
try:
- # 使用 execute 操作 sql
rows = self.cur.execute(sql)
- # 提交事务
self.conn.commit()
return rows
- except AttributeError as error:
- logger.error("数据库连接失败,失败原因 %s", error)
- # 如果事务异常,则回滚数据
+ except Exception as err:
+ logger.error(f"数据库连接失败, {err}", )
self.conn.rollback()
raise
+
+if __name__ == '__main__':
+ pass
\ No newline at end of file