!57 add database function
From: @xuezhizone Reviewed-by: @xingwei-liu Signed-off-by: @xingwei-liu
This commit is contained in:
commit
79d8827a3f
52
0004-connect-sql-function.patch
Normal file
52
0004-connect-sql-function.patch
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
From 9d1aaac6870109b79ce77963f4270ba192a60a6f Mon Sep 17 00:00:00 2001
|
||||||
|
From: lixin <lixinb@uniontech.com>
|
||||||
|
Date: Mon, 6 Nov 2023 17:37:23 +0800
|
||||||
|
Subject: [PATCH] =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=95=B0=E6=8D=AE=E5=BA=93?=
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/plain; charset=UTF-8
|
||||||
|
Content-Transfer-Encoding: 8bit
|
||||||
|
|
||||||
|
---
|
||||||
|
connect_sql.py | 30 ++++++++++++++++++++++++++++++
|
||||||
|
1 file changed, 30 insertions(+)
|
||||||
|
create mode 100644 connect_sql.py
|
||||||
|
|
||||||
|
diff --git a/connect_sql.py b/connect_sql.py
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..e24a467
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/connect_sql.py
|
||||||
|
@@ -0,0 +1,30 @@
|
||||||
|
+import pymysql
|
||||||
|
+
|
||||||
|
+class DBHelper:
|
||||||
|
+ # 构造函数
|
||||||
|
+ def __init__(self, host=db_host, user=db_user, pwd=db_password, db=db_name):
|
||||||
|
+ self.host = host
|
||||||
|
+ self.user = user
|
||||||
|
+ self.pwd = pwd
|
||||||
|
+ self.db = db
|
||||||
|
+ self.connect = None
|
||||||
|
+ self.cursor = None
|
||||||
|
+
|
||||||
|
+ # 连接数据库
|
||||||
|
+ def connectDatabase(self):
|
||||||
|
+ try:
|
||||||
|
+ self.connect = pymysql.connect(host=self.host, user=self.user, password=self.pwd, db=self.db,
|
||||||
|
+ charset='utf8')
|
||||||
|
+ except:
|
||||||
|
+ print('connectDatabase failed')
|
||||||
|
+ return False
|
||||||
|
+ self.cursor = self.connect.cursor()
|
||||||
|
+ return True
|
||||||
|
+
|
||||||
|
+ # 关闭数据库
|
||||||
|
+ def close(self):
|
||||||
|
+ # 如果数据打开,则关闭;否则没有操作
|
||||||
|
+ if self.connect and self.cursor:
|
||||||
|
+ self.cursor.close()
|
||||||
|
+ self.connect.close()
|
||||||
|
+ return True
|
||||||
|
--
|
||||||
|
2.20.1
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
Name: migration-tools
|
Name: migration-tools
|
||||||
Version: 1.0.2
|
Version: 1.0.2
|
||||||
Release: 3
|
Release: 4
|
||||||
License: MulanPSL-2.0
|
License: MulanPSL-2.0
|
||||||
Summary: A tool to help users migrate the Centos system to the UOS system and openEuler system
|
Summary: A tool to help users migrate the Centos system to the UOS system and openEuler system
|
||||||
Source0: %{name}-%{version}.tar.gz
|
Source0: %{name}-%{version}.tar.gz
|
||||||
@ -10,6 +10,7 @@ Source2: xlwt-1.3.0-py2.py3-none-any.whl
|
|||||||
Patch0: 0001-format-code.patch
|
Patch0: 0001-format-code.patch
|
||||||
Patch1: 0002-modify-excel-report-content.patch
|
Patch1: 0002-modify-excel-report-content.patch
|
||||||
Patch2: 0003-delete-redundant-code.patch
|
Patch2: 0003-delete-redundant-code.patch
|
||||||
|
Patch3: 0004-connect-sql-function.patch
|
||||||
|
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
BuildRequires: systemd
|
BuildRequires: systemd
|
||||||
@ -108,6 +109,9 @@ rm -rf /usr/bin/migration-tools
|
|||||||
%endif
|
%endif
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Fri Nov 1 2024 xuezhixin <xuezhixin@uniontech.com> - 1.0.2-4
|
||||||
|
- add 0004-connect-sql-function.patch
|
||||||
|
|
||||||
* Fri Nov 1 2024 xuezhixin <xuezhixin@uniontech.com> - 1.0.2-3
|
* Fri Nov 1 2024 xuezhixin <xuezhixin@uniontech.com> - 1.0.2-3
|
||||||
- add 0003-delete-redundant-code.patch
|
- add 0003-delete-redundant-code.patch
|
||||||
|
|
||||||
@ -153,4 +157,4 @@ rm -rf /usr/bin/migration-tools
|
|||||||
- fix no migration detail error
|
- fix no migration detail error
|
||||||
|
|
||||||
* Wed Aug 16 2023 lixin <lixinb@uniontech.com> - 1.0.0-1
|
* Wed Aug 16 2023 lixin <lixinb@uniontech.com> - 1.0.0-1
|
||||||
- init
|
init
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user