migration-tools/0005-execution-sql-function.patch
2024-11-01 18:07:19 +08:00

63 lines
1.7 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 8dd714b9fe161358f48857fff9a08faac2af6af4 Mon Sep 17 00:00:00 2001
From: lixin <lixinb@uniontech.com>
Date: Mon, 6 Nov 2023 17:44:45 +0800
Subject: [PATCH] =?UTF-8?q?=E6=89=A7=E8=A1=8Csql=E8=AF=AD=E5=8F=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
connect_sql.py | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/connect_sql.py b/connect_sql.py
index e24a467..b5d0570 100644
--- a/connect_sql.py
+++ b/connect_sql.py
@@ -28,3 +28,42 @@ class DBHelper:
self.cursor.close()
self.connect.close()
return True
+
+ def execute(self, sql):
+ """
+ 传入查询 修改 删除sql语句
+ :param sql:
+ :return:self.cursor
+ """
+ self.connectDatabase()
+ # 处理显示的数据
+ try:
+ self.cursor.execute(sql)
+ self.connect.commit()
+ except Exception as e:
+ print('%s执行失败%s' % (sql, e))
+ else:
+ self.close()
+ print('%s 执行成功' % sql)
+ data = self.cursor
+ return data
+
+ def insert(self, sql, val):
+ """
+ 传入sql语句
+ :param sql:
+ :return:self.cursor
+ 如果想获取查询数据需要fetchall()
+ """
+ self.connectDatabase()
+ # 处理显示的数据
+ try:
+ self.cursor.executemany(sql, val)
+ self.connect.commit()
+ except Exception as e:
+ print('%s执行失败%s' % (sql, e))
+ else:
+ self.close()
+ print('%s 执行成功' % sql)
+ data = self.cursor
+ return data
--
2.20.1