From c5724421cb43bc624c103e354ef0c733cd73612a Mon Sep 17 00:00:00 2001 From: xuezhixin Date: Fri, 1 Nov 2024 17:48:54 +0800 Subject: [PATCH] add database function --- 0004-connect-sql-function.patch | 52 +++++++++++++++++++++++++++++++++ migration-tools.spec | 8 +++-- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 0004-connect-sql-function.patch diff --git a/0004-connect-sql-function.patch b/0004-connect-sql-function.patch new file mode 100644 index 0000000..8f64baa --- /dev/null +++ b/0004-connect-sql-function.patch @@ -0,0 +1,52 @@ +From 9d1aaac6870109b79ce77963f4270ba192a60a6f Mon Sep 17 00:00:00 2001 +From: lixin +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 + diff --git a/migration-tools.spec b/migration-tools.spec index 9c3d33b..5e4883d 100644 --- a/migration-tools.spec +++ b/migration-tools.spec @@ -1,6 +1,6 @@ Name: migration-tools Version: 1.0.2 -Release: 3 +Release: 4 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 @@ -10,6 +10,7 @@ Source2: xlwt-1.3.0-py2.py3-none-any.whl Patch0: 0001-format-code.patch Patch1: 0002-modify-excel-report-content.patch Patch2: 0003-delete-redundant-code.patch +Patch3: 0004-connect-sql-function.patch BuildArch: noarch BuildRequires: systemd @@ -108,6 +109,9 @@ rm -rf /usr/bin/migration-tools %endif %changelog +* Fri Nov 1 2024 xuezhixin - 1.0.2-4 +- add 0004-connect-sql-function.patch + * Fri Nov 1 2024 xuezhixin - 1.0.2-3 - add 0003-delete-redundant-code.patch @@ -153,4 +157,4 @@ rm -rf /usr/bin/migration-tools - fix no migration detail error * Wed Aug 16 2023 lixin - 1.0.0-1 -- init + init -- Gitee