使用python写了一个sql填充工具

python 复制代码
import tkinter as tk
from tkinter import ttk, scrolledtext

def fill_template():
    old_id = old_id_entry.get()
    new_id = new_id_entry.get()
    old_code = old_code_entry.get()
    new_code = new_code_entry.get()
    old_name = old_name_entry.get()
    new_name = new_name_entry.get()
    district_code = district_code_entry.get()
    province_city_district = province_city_district_entry.get()
    manage_gbcode = district_code_entry.get()
    manageorg_name = new_name_entry.get()
    p3_code = manage_gbcode[:2]
    c3_code = manage_gbcode[2:4]
    d3_code = manage_gbcode[4:6]
    s3_code = manage_gbcode[6:]
    sql_template = f"""
-- 3. Delete organization and clear user integration information
update roar_psy.organizations o set o.status = '1' where o.org_id = {old_id}; 
update roar_psy.users t
   set t.last_upload_message = '', t.is_async = '', t.is_pass = ''
 where t.org_id = {old_id};
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
-- 4. Process business data
-- Management organization 
-- Check 1
select count(*) from t_a_Disease_Info t where t.manageorg_id = {old_id};
       
-- 1. Basic information
update t_a_Disease_Info t
   set t.manageorg_code      = '{new_code}',
       t.manageorg_code_tmp  = '',
       t.manageorg_gbcode    = '{district_code}',
       t.manageorg_name      = '{new_name}',
       t.is_grab             = '',
       t.last_upload_message = '',
       t.grab_date           = t.modify_date, t.manageorg_id = {new_id}
 where t.manageorg_id = {old_id};
 -- Check 2
select count(*) from t_a_Disease_Info t where t.manageorg_id = {old_id};
-- More update statements...
"""
    output_text.delete('1.0', tk.END)
    output_text.insert(tk.INSERT, sql_template)

root = tk.Tk()
root.title("SQL Template Filler")

ttk.Label(root, text="Old Org ID:").grid(column=0, row=0)
old_id_entry = ttk.Entry(root)
old_id_entry.grid(column=1, row=0)

ttk.Label(root, text="New Org ID:").grid(column=0, row=1)
new_id_entry = ttk.Entry(root)
new_id_entry.grid(column=1, row=1)

ttk.Label(root, text="Old Org Code:").grid(column=0, row=2)
old_code_entry = ttk.Entry(root)
old_code_entry.grid(column=1, row=2)

ttk.Label(root, text="New Org Code:").grid(column=0, row=3)
new_code_entry = ttk.Entry(root)
new_code_entry.grid(column=1, row=3)

ttk.Label(root, text="Old Org Name:").grid(column=0, row=4)
old_name_entry = ttk.Entry(root)
old_name_entry.grid(column=1, row=4)

ttk.Label(root, text="New Org Name:").grid(column=0, row=5)
new_name_entry = ttk.Entry(root)
new_name_entry.grid(column=1, row=5)

ttk.Label(root, text="New District Code:").grid(column=0, row=6)
district_code_entry = ttk.Entry(root)
district_code_entry.grid(column=1, row=6)

ttk.Label(root, text="New Province/City/District:").grid(column=0, row=7)
province_city_district_entry = ttk.Entry(root)
province_city_district_entry.grid(column=1, row=7)

fill_button = ttk.Button(root, text="Fill Template", command=fill_template)
fill_button.grid(column=1, row=8)

output_text = scrolledtext.ScrolledText(root, width=80, height=20)
output_text.grid(column=0, row=9, columnspan=2)

root.mainloop()
相关推荐
YOU OU4 小时前
Redis基础常识与命令
数据库·redis·缓存
Scott9999HH4 小时前
【IIoT流量实战】蒸汽管道阀门全关却仍有流量?用 Python 实现涡街信号 FFT 频谱分析与温压全补偿积算网关,深度拆解靠谱的涡街流量计厂家硬核技术标准
开发语言·python
AI云海5 小时前
python 列表、元组、集合和字典
开发语言·python
二十雨辰5 小时前
[爬虫]-Urllib
爬虫·python
Database_Cool_6 小时前
OLTP 和 OLAP 区别详解:分析型数据库和事务型数据库怎么选(附阿里云 AnalyticDB MySQL 选型指南)
数据库·mysql·阿里云
爱写代码的阿森6 小时前
鸿蒙三方库 | harmony-utils之KvUtil键值型数据库操作详解
数据库·华为·harmonyos·鸿蒙·huawei
Database_Cool_7 小时前
单机 MySQL 迁移到分布式数据库方便吗?阿里云 PolarDB-X 100% MySQL 协议兼容零改造平滑迁移
数据库·分布式·mysql
玉鸯7 小时前
Agent Hook:在概率推理之上,为 Agent 叠加确定性控制
python·langchain·agent
姜太小白7 小时前
【MySQL】 索引优化实战:解决 WHERE 等值 + IS NULL 查询,TEXT 字段报错 1167 的完整指南
数据库·mysql