mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-29 10:43:06 +08:00
Optimize code structure.
This commit is contained in:
@ -0,0 +1,52 @@
|
||||
package ai.chat2db.plugin.sqlserver;
|
||||
|
||||
import ai.chat2db.spi.ValueHandler;
|
||||
import ai.chat2db.spi.model.Command;
|
||||
import ai.chat2db.spi.model.ExecuteResult;
|
||||
import ai.chat2db.spi.sql.SQLExecutor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class SqlServerCommandExecutor extends SQLExecutor {
|
||||
|
||||
/**
|
||||
* Execute command
|
||||
*/
|
||||
@Override
|
||||
public List<ExecuteResult> execute(Command command) {
|
||||
String sql = command.getScript();
|
||||
command.setScript(removeSpecialGO(sql));
|
||||
return super.execute(command);
|
||||
}
|
||||
|
||||
|
||||
private String removeSpecialGO(String sql) {
|
||||
if (StringUtils.isBlank(sql)) {
|
||||
return null;
|
||||
}
|
||||
sql = sql.replaceAll("(?mi)^[ \\t]*go[ \\t]*$", ";");
|
||||
return sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute command
|
||||
*/
|
||||
@Override
|
||||
public ExecuteResult executeUpdate(String sql, Connection connection, int n) throws SQLException {
|
||||
sql = removeSpecialGO(sql);
|
||||
return super.executeUpdate(sql, connection, n);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ExecuteResult execute(final String sql, Connection connection, boolean limitRowSize, Integer offset,
|
||||
Integer count, ValueHandler valueHandler)
|
||||
throws SQLException {
|
||||
return super.execute(removeSpecialGO(sql), connection, limitRowSize, offset, count, valueHandler);
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ import ai.chat2db.plugin.sqlserver.builder.SqlServerSqlBuilder;
|
||||
import ai.chat2db.plugin.sqlserver.type.SqlServerColumnTypeEnum;
|
||||
import ai.chat2db.plugin.sqlserver.type.SqlServerDefaultValueEnum;
|
||||
import ai.chat2db.plugin.sqlserver.type.SqlServerIndexTypeEnum;
|
||||
import ai.chat2db.spi.CommandExecutor;
|
||||
import ai.chat2db.spi.MetaData;
|
||||
import ai.chat2db.spi.SqlBuilder;
|
||||
import ai.chat2db.spi.jdbc.DefaultMetaService;
|
||||
@ -73,7 +74,7 @@ public class SqlServerMetaData extends DefaultMetaService implements MetaData {
|
||||
@Override
|
||||
public String tableDDL(Connection connection, String databaseName, String schemaName, String tableName) {
|
||||
try {
|
||||
SQLExecutor.getInstance().executeSql(connection, functionSQL.replace("tableSchema", schemaName),
|
||||
SQLExecutor.getInstance().execute(connection, functionSQL.replace("tableSchema", schemaName),
|
||||
resultSet -> null);
|
||||
} catch (Exception e) {
|
||||
//log.error("创建函数失败", e);
|
||||
@ -392,4 +393,9 @@ public class SqlServerMetaData extends DefaultMetaService implements MetaData {
|
||||
public String getMetaDataName(String... names) {
|
||||
return Arrays.stream(names).filter(name -> StringUtils.isNotBlank(name)).map(name -> "[" + name + "]").collect(Collectors.joining("."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandExecutor getCommandExecutor() {
|
||||
return new SqlServerCommandExecutor();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user