cursorが見つからないエラーを修正したい

This commit is contained in:
suti7yk5032 2024-08-23 01:30:58 +09:00
parent 2d5ea6a48d
commit 1e8ef35e3f

View file

@ -237,7 +237,8 @@ class Bot(discord.Client):
return {"result": 1, "about": "error"}
finally:
cursor.close()
if cursor:
cursor.close()
def keyboard_used_check(self, **kwargs):
try:
@ -263,7 +264,8 @@ class Bot(discord.Client):
return {"result": 1, "about": "error"}
finally:
cursor.close()
if cursor:
cursor.close()
def mouse_used_check(self, **kwargs):
try:
@ -289,11 +291,13 @@ class Bot(discord.Client):
return {"result": 1, "about": "error"}
finally:
cursor.close()
if cursor:
cursor.close()
def register(self, **kwargs):
try:
cursor = None
user_info = {
"id": str(kwargs["user_id"]),
"name": str(kwargs["name"]),
@ -317,7 +321,6 @@ class Bot(discord.Client):
pass
else:
user_info["mouse_number"] = int(kwargs["mouse_number"])
cursor = dislocker.db.cursor()
# ユーザー登録されているかの確認
user_register = self.user_register_check(discord_user_id=user_info["id"])
if user_register["result"] == 0:
@ -339,6 +342,7 @@ class Bot(discord.Client):
password = self.password_generate(4)
password_hash = self.hash_genarate(password)
# PC使用履歴のテーブルにレコードを挿入
cursor = dislocker.db.cursor()
cursor.execute("INSERT INTO pc_usage_history (member_id, pc_number, keyboard_number, mouse_number, start_use_time, use_detail) VALUES (%s, %s, %s, %s, clock_timestamp(), %s)", (member_id, user_info["pc_number"], user_info["keyboard_number"], user_info["mouse_number"], user_info["detail"]))
# PCリストの該当のレコードを更新
cursor.execute("UPDATE pc_list SET using_member_id = %s, password_hash = %s WHERE pc_number = %s", (member_id, password_hash, user_info["pc_number"]))
@ -371,7 +375,8 @@ class Bot(discord.Client):
print(str(error))
return {"result": 1, "about": "error"}
finally:
cursor.close()
if cursor:
cursor.close()
def stop(self, **kwargs):
@ -434,7 +439,8 @@ class Bot(discord.Client):
return {"result": 1, "about": "error"}
finally:
cursor.close()
if cursor:
cursor.close()
def user_register(self, **kwargs):
try:
@ -459,7 +465,8 @@ class Bot(discord.Client):
return {"result": 1, "about": "error"}
finally:
cursor.close()
if cursor:
cursor.close()
def format_datetime(self, value):
@ -488,7 +495,8 @@ class Bot(discord.Client):
return {"result": 1, "about": "error"}
finally:
cursor.close()
if cursor:
cursor.close()
def report_export(self, **kwargs):
try:
@ -562,7 +570,8 @@ class Bot(discord.Client):
return {"result": 1, "about": "error"}
finally:
cursor.close()
if cursor:
cursor.close()
def force_stop(self, **kwargs):
@ -612,7 +621,8 @@ class Bot(discord.Client):
return {"result": 1, "about": "error"}
finally:
cursor.close()
if cursor:
cursor.close()
async def timeout_notify(self, **kwargs):
try:
@ -1002,7 +1012,8 @@ class Monitor():
dislocker.db.rollback()
finally:
cursor.close()
if cursor:
cursor.close()
print(result["result"])
return result