Skip to content

Commit

Permalink
[修复]alter_column
Browse files Browse the repository at this point in the history
  • Loading branch information
longfengpili committed Mar 5, 2024
1 parent 2a628fc commit 35b6453
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pydbapi/col/colmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pydbapi/db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 ~")
Expand Down
10 changes: 5 additions & 5 deletions tests/mysql/mysql_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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}")
Expand All @@ -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}'],
Expand Down

0 comments on commit 35b6453

Please sign in to comment.