使用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()
相关推荐
一个天蝎座 白勺 程序猿3 分钟前
Python爬虫(8)Python数据存储实战:JSON文件读写与复杂结构化数据处理指南
爬虫·python·json
q_q王19 分钟前
dify对接飞书云文档,并且将图片传入飞书文档
python·大模型·飞书·dify·智能体·图片展示
聪明的墨菲特i22 分钟前
SQL进阶知识:六、动态SQL
数据库·sql·sql注入·动态sql·prepare·execute
PingCAP24 分钟前
APTSell x TiDB AutoFlow:AI 数字员工,助力销售业绩持续增长
数据库
noravinsc25 分钟前
django filter 排除字段
后端·python·django
PingCAP27 分钟前
从企业数智化四阶段解读 TiDB 场景价值
数据库
Haoea!38 分钟前
java-mybatis01
java·数据库·oracle
zandy101139 分钟前
衡石科技:HENGSHI SENSE 数据权限解决方案
java·数据库·科技
爱的叹息1 小时前
数据库sql执行报错:non-grouping field xxx is used in HAVING clause错误详解
数据库·sql·oracle
zandy10111 小时前
嵌入式BI开发指南:如何通过衡石API将分析能力集成到业务系统?
开发语言·python·嵌入式