From 35b6453cd552e76179bf741dad335d3007d44e3f Mon Sep 17 00:00:00 2001 From: longfengpili <398745129@qq.com> Date: Tue, 5 Mar 2024 18:38:47 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]alter=5Fcolumn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pydbapi/col/colmodel.py | 2 +- pydbapi/db/base.py | 5 +++-- tests/mysql/mysql_test.py | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pydbapi/col/colmodel.py b/pydbapi/col/colmodel.py index 69ff755..77f5e84 100644 --- a/pydbapi/col/colmodel.py +++ b/pydbapi/col/colmodel.py @@ -2,7 +2,7 @@ # @Author: longfengpili # @Date: 2023-06-02 15:27:41 # @Last Modified by: longfengpili -# @Last Modified time: 2024-02-29 10:37:34 +# @Last Modified time: 2024-03-05 18:33:56 # @github: https://github.com/longfengpili from typing import Iterable, List, Any diff --git a/pydbapi/db/base.py b/pydbapi/db/base.py index 4745d02..fb55936 100644 --- a/pydbapi/db/base.py +++ b/pydbapi/db/base.py @@ -2,7 +2,7 @@ # @Author: longfengpili # @Date: 2023-06-02 15:27:41 # @Last Modified by: longfengpili -# @Last Modified time: 2024-03-04 18:22:37 +# @Last Modified time: 2024-03-05 18:38:16 # @github: https://github.com/longfengpili @@ -291,7 +291,8 @@ def alter_column(self, tablename: str, colname: str, newname: str = None, newtyp newname = newname or alter_col.newname newtype = newtype or alter_col.coltype - sqlexpr = sqlexpr or f"cast({colname} as {newtype})" if newtype != alter_col.coltype else None + sqlexpr = sqlexpr or f"cast({colname} as {newtype})" if newtype != alter_col.coltype \ + else f"{alter_col.newname}" if newname != alter_col.newname else None newcol = ColumnModel(newname, newtype, sqlexpr=sqlexpr) if newcol == alter_col: dblogger.info(f"{newcol} same, not need to change ~") diff --git a/tests/mysql/mysql_test.py b/tests/mysql/mysql_test.py index b951e93..9992018 100644 --- a/tests/mysql/mysql_test.py +++ b/tests/mysql/mysql_test.py @@ -2,7 +2,7 @@ # @Author: longfengpili # @Date: 2023-06-02 15:27:41 # @Last Modified by: longfengpili -# @Last Modified time: 2024-03-01 12:09:14 +# @Last Modified time: 2024-03-05 18:21:25 # @github: https://github.com/longfengpili @@ -46,10 +46,6 @@ def test_get_instance(self): # result = eval(f"mysql4.{i}") # print(f"【{i}】: {result}") - def test_cols(self): - result = self.mysqldb.get_columns(self.tablename) - print(result) - def test_drop(self): rows, action, result = self.mysqldb.drop(self.tablename) print(f"【rows】: {rows}, 【action】: {action}, 【result】: {result}") @@ -65,6 +61,10 @@ def test_create(self): rows, action, result = self.mysqldb.create(self.tablename, self.columns, indexes, partition='birthday') print(f"【rows】: {rows}, 【action】: {action}, 【result】: {result}") + def test_cols(self): + result = self.mysqldb.get_columns(self.tablename) + print(result) + def test_insert(self): values = [[1, 'apple', 'beijing', '2012-01-23', '{"yuwen": 90, "shuxue": 20}'], [2, 'banana', 'shanghai', '2020-02-25 01:00:00', '{"yuwen": 91, "shuxue": 80}'],