mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-30 11:12:55 +08:00
Simplify the update and delete statements for query results when the table contains primary keys
This commit is contained in:
@ -19,6 +19,7 @@ public class KingBaseDBManage extends DefaultDBManage implements DBManage {
|
||||
SQLExecutor.getInstance().execute(connection, "SET search_path TO \"" + connectInfo.getSchemaName() + "\"");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import ai.chat2db.server.domain.api.param.*;
|
||||
import ai.chat2db.server.domain.api.param.operation.OperationLogCreateParam;
|
||||
import ai.chat2db.server.domain.api.service.OperationLogService;
|
||||
import ai.chat2db.server.domain.api.service.TableService;
|
||||
import ai.chat2db.server.domain.core.util.MetaNameUtils;
|
||||
import ai.chat2db.spi.MetaData;
|
||||
import ai.chat2db.spi.model.*;
|
||||
import ai.chat2db.spi.sql.ConnectInfo;
|
||||
@ -180,7 +181,7 @@ public class DlTemplateServiceImpl implements DlTemplateService {
|
||||
}
|
||||
|
||||
List<Header> headers = executeResult.getHeaderList();
|
||||
if (executeResult.isCanEdit()) {
|
||||
if (executeResult.getSuccess() && executeResult.isCanEdit() && CollectionUtils.isNotEmpty(headers)){
|
||||
headers = setColumnInfo(headers, executeResult.getTableName(), param.getSchemaName(), param.getDatabaseName());
|
||||
}
|
||||
Header rowNumberHeader = Header.builder()
|
||||
@ -188,7 +189,7 @@ public class DlTemplateServiceImpl implements DlTemplateService {
|
||||
.dataType(DataTypeEnum.CHAT2DB_ROW_NUMBER
|
||||
.getCode()).build();
|
||||
|
||||
executeResult.setHeaderList(ListUtils.union(Arrays.asList(rowNumberHeader), headers));
|
||||
executeResult.setHeaderList(EasyCollectionUtils.union(Arrays.asList(rowNumberHeader), headers));
|
||||
if (executeResult.getDataList() != null) {
|
||||
int rowNumberIncrement = 1 + Math.max(pageNo - 1, 0) * pageSize;
|
||||
for (int i = 0; i < executeResult.getDataList().size(); i++) {
|
||||
@ -392,7 +393,7 @@ public class DlTemplateServiceImpl implements DlTemplateService {
|
||||
|
||||
private List<Header> setColumnInfo(List<Header> headers, String tableName, String schemaName, String databaseName) {
|
||||
TableQueryParam tableQueryParam = new TableQueryParam();
|
||||
tableQueryParam.setTableName(tableName);
|
||||
tableQueryParam.setTableName(MetaNameUtils.getMetaName(tableName));
|
||||
tableQueryParam.setSchemaName(schemaName);
|
||||
tableQueryParam.setDatabaseName(databaseName);
|
||||
List<TableColumn> columns = tableService.queryColumns(tableQueryParam);
|
||||
|
@ -0,0 +1,26 @@
|
||||
package ai.chat2db.server.domain.core.util;
|
||||
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class MetaNameUtils {
|
||||
|
||||
public static String getMetaName(String tableName) {
|
||||
if(StringUtils.isBlank(tableName)){
|
||||
return tableName;
|
||||
}
|
||||
if(tableName.startsWith("`") && tableName.endsWith("`")){
|
||||
return tableName.substring(1,tableName.length()-1);
|
||||
}
|
||||
if(tableName.startsWith("\"") && tableName.endsWith("\"")){
|
||||
return tableName.substring(1,tableName.length()-1);
|
||||
}
|
||||
if(tableName.startsWith("'") && tableName.endsWith("'")){
|
||||
return tableName.substring(1,tableName.length()-1);
|
||||
}
|
||||
if(tableName.startsWith("[") && tableName.endsWith("]")){
|
||||
return tableName.substring(1,tableName.length()-1);
|
||||
}
|
||||
return tableName;
|
||||
}
|
||||
}
|
@ -1,10 +1,6 @@
|
||||
package ai.chat2db.server.tools.common.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
@ -189,4 +185,15 @@ public class EasyCollectionUtils {
|
||||
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
||||
}
|
||||
|
||||
public static <E> List<E> union(List<? extends E> list1, List<? extends E> list2) {
|
||||
ArrayList<E> result = new ArrayList();
|
||||
if(list1 != null && list1.size()>0) {
|
||||
result.addAll(list1);
|
||||
}
|
||||
if(list2!= null && list2.size()>0) {
|
||||
result.addAll(list2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user