mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-08-01 18:53:35 +08:00
Merge pull request #1410 from tmlx1990/fixmysqlbuilder
Fix the problem that MySQL generates incorrect statements after moving a column to deleting a column
This commit is contained in:
@ -2,13 +2,12 @@ package ai.chat2db.plugin.mysql.builder;
|
|||||||
|
|
||||||
import ai.chat2db.plugin.mysql.type.MysqlColumnTypeEnum;
|
import ai.chat2db.plugin.mysql.type.MysqlColumnTypeEnum;
|
||||||
import ai.chat2db.plugin.mysql.type.MysqlIndexTypeEnum;
|
import ai.chat2db.plugin.mysql.type.MysqlIndexTypeEnum;
|
||||||
import ai.chat2db.spi.SqlBuilder;
|
import ai.chat2db.spi.enums.EditStatus;
|
||||||
import ai.chat2db.spi.jdbc.DefaultSqlBuilder;
|
import ai.chat2db.spi.jdbc.DefaultSqlBuilder;
|
||||||
import ai.chat2db.spi.model.Database;
|
import ai.chat2db.spi.model.Database;
|
||||||
import ai.chat2db.spi.model.Table;
|
import ai.chat2db.spi.model.Table;
|
||||||
import ai.chat2db.spi.model.TableColumn;
|
import ai.chat2db.spi.model.TableColumn;
|
||||||
import ai.chat2db.spi.model.TableIndex;
|
import ai.chat2db.spi.model.TableIndex;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -145,7 +144,13 @@ public class MysqlSqlBuilder extends DefaultSqlBuilder {
|
|||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
return "-1";
|
return "-1";
|
||||||
}
|
}
|
||||||
return newTable.getColumnList().get(index - 1).getName();
|
// Find the previous column that is not deleted
|
||||||
|
for (int i = index - 1; i >= 0; i--) {
|
||||||
|
if (newTable.getColumnList().get(i).getEditStatus() == null || !newTable.getColumnList().get(i).getEditStatus().equals(EditStatus.DELETE.name())) {
|
||||||
|
return newTable.getColumnList().get(i).getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "-1";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user