|
|
|
|
@ -58,14 +58,31 @@ def insert_or_update_data(table_name, operation):
|
|
|
|
|
submit_button = ttk.Button(top, text="Submit", command=submit)
|
|
|
|
|
submit_button.grid(row=len(tables_schema[table_name]), column=0, columnspan=2, padx=5, pady=5)
|
|
|
|
|
|
|
|
|
|
# 删除操作
|
|
|
|
|
# 删除操作
|
|
|
|
|
def delete_data(table_name):
|
|
|
|
|
condition = simpledialog.askstring("Input", f"Enter delete condition for {table_name} (e.g., id = 1):")
|
|
|
|
|
sql = f"DELETE FROM {table_name} WHERE {condition}"
|
|
|
|
|
with connection.cursor() as cursor:
|
|
|
|
|
cursor.execute(sql)
|
|
|
|
|
connection.commit()
|
|
|
|
|
messagebox.showinfo("Success", "Data deleted successfully")
|
|
|
|
|
# 弹出对话框让用户输入要删除的字段名
|
|
|
|
|
field = simpledialog.askstring("Input", f"Enter the field to delete from {table_name} (e.g., Name):")
|
|
|
|
|
if not field:
|
|
|
|
|
messagebox.showerror("Error", "No field specified")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# 弹出对话框让用户输入要删除的字段值
|
|
|
|
|
value = simpledialog.askstring("Input", f"Enter the value of {field} to delete from {table_name} (e.g., John):")
|
|
|
|
|
if not value:
|
|
|
|
|
messagebox.showerror("Error", "No value specified")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# 构造SQL删除语句
|
|
|
|
|
sql = f"DELETE FROM {table_name} WHERE {field} = %s"
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
with connection.cursor() as cursor:
|
|
|
|
|
cursor.execute(sql, (value,))
|
|
|
|
|
connection.commit()
|
|
|
|
|
messagebox.showinfo("Success", "Data deleted successfully")
|
|
|
|
|
except Exception as e:
|
|
|
|
|
messagebox.showerror("Error", f"An error occurred: {e}")
|
|
|
|
|
|
|
|
|
|
# 选择表并执行操作
|
|
|
|
|
def choose_table_and_operate():
|
|
|
|
|
|