!58 add execution sql function

From: @xuezhizone 
Reviewed-by: @xingwei-liu 
Signed-off-by: @xingwei-liu
This commit is contained in:
openeuler-ci-bot 2024-11-01 10:13:42 +00:00 committed by Gitee
commit 3d7ad590db
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 67 additions and 1 deletions

View File

@ -0,0 +1,62 @@
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

View File

@ -1,6 +1,6 @@
Name: migration-tools
Version: 1.0.2
Release: 4
Release: 5
License: MulanPSL-2.0
Summary: A tool to help users migrate the Centos system to the UOS system and openEuler system
Source0: %{name}-%{version}.tar.gz
@ -11,6 +11,7 @@ Patch0: 0001-format-code.patch
Patch1: 0002-modify-excel-report-content.patch
Patch2: 0003-delete-redundant-code.patch
Patch3: 0004-connect-sql-function.patch
Patch4: 0005-execution-sql-function.patch
BuildArch: noarch
BuildRequires: systemd
@ -109,6 +110,9 @@ rm -rf /usr/bin/migration-tools
%endif
%changelog
* Fri Nov 1 2024 xuezhixin <xuezhixin@uniontech.com> - 1.0.2-5
- add 0005-execution-sql-function.patch
* Fri Nov 1 2024 xuezhixin <xuezhixin@uniontech.com> - 1.0.2-4
- add 0004-connect-sql-function.patch