mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-29 18:53:12 +08:00
MysqlValueProcessor and OracleValueProcessor
This commit is contained in:
@ -2,13 +2,11 @@ package ai.chat2db.plugin.mysql.builder;
|
||||
|
||||
import ai.chat2db.plugin.mysql.type.MysqlColumnTypeEnum;
|
||||
import ai.chat2db.plugin.mysql.type.MysqlIndexTypeEnum;
|
||||
import ai.chat2db.spi.SqlBuilder;
|
||||
import ai.chat2db.spi.jdbc.DefaultSqlBuilder;
|
||||
import ai.chat2db.spi.model.Database;
|
||||
import ai.chat2db.spi.model.Table;
|
||||
import ai.chat2db.spi.model.TableColumn;
|
||||
import ai.chat2db.spi.model.TableIndex;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
@ -288,14 +286,14 @@ public class MysqlSqlBuilder extends DefaultSqlBuilder {
|
||||
// 连续数据数量
|
||||
if (from < to) {
|
||||
for (int i = to; i < originalArray.length - 1; i++) {
|
||||
if (originalArray[i+1].equals(targetArray[findIndex(targetArray, originalArray[i]) +1])) {
|
||||
if (originalArray[i + 1].equals(targetArray[findIndex(targetArray, originalArray[i]) + 1])) {
|
||||
continuousDataCount.set(continuousDataCount.incrementAndGet());
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (continuousDataCount.get() > 0) {
|
||||
System.arraycopy(originalArray, from + 1, newArray, from, to - from +1);
|
||||
System.arraycopy(originalArray, from + 1, newArray, from, to - from + 1);
|
||||
isContinuousData = true;
|
||||
} else {
|
||||
System.arraycopy(originalArray, from + 1, newArray, from, to - from);
|
||||
@ -303,12 +301,20 @@ public class MysqlSqlBuilder extends DefaultSqlBuilder {
|
||||
} else {
|
||||
System.arraycopy(originalArray, to, newArray, to + 1, from - to);
|
||||
}
|
||||
if (isContinuousData){
|
||||
newArray[to+continuousDataCount.get()] = temp;
|
||||
if (isContinuousData) {
|
||||
newArray[to + continuousDataCount.get()] = temp;
|
||||
} else {
|
||||
newArray[to] = temp;
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void buildTableName(String databaseName, String schemaName, String tableName, StringBuilder script) {
|
||||
if (StringUtils.isNotBlank(databaseName)) {
|
||||
script.append("`").append(databaseName).append("`").append('.');
|
||||
}
|
||||
script.append("`").append(tableName).append("`");
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,13 @@ public class MysqlValueProcessor extends DefaultValueProcessor {
|
||||
|
||||
@Override
|
||||
public String convertJDBCValueByType(JDBCDataValue dataValue) {
|
||||
return MysqlValueProcessorFactory.getValueProcessor(dataValue.getType()).convertJDBCValueByType(dataValue);
|
||||
String type = dataValue.getType();
|
||||
return MysqlValueProcessorFactory.getValueProcessor(type).convertJDBCValueByType(dataValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertJDBCValueStrByType(JDBCDataValue dataValue) {
|
||||
return MysqlValueProcessorFactory.getValueProcessor(dataValue.getType()).convertJDBCValueStrByType(dataValue);
|
||||
String type = dataValue.getType();
|
||||
return MysqlValueProcessorFactory.getValueProcessor(type).convertJDBCValueStrByType(dataValue);
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ public class MysqlValueProcessorFactory {
|
||||
Map.entry(MysqlColumnTypeEnum.MULTIPOLYGON.name(), mysqlGeometryProcessor),
|
||||
Map.entry(MysqlColumnTypeEnum.GEOMETRYCOLLECTION.name(), mysqlGeometryProcessor),
|
||||
// binary
|
||||
Map.entry(MysqlColumnTypeEnum.VARBINARY.name(), mysqlVarBinaryProcessor),
|
||||
Map.entry(MysqlColumnTypeEnum.BLOB.name(), mysqlVarBinaryProcessor),
|
||||
Map.entry(MysqlColumnTypeEnum.LONGBLOB.name(), mysqlVarBinaryProcessor),
|
||||
Map.entry(MysqlColumnTypeEnum.TINYBLOB.name(), mysqlVarBinaryProcessor),
|
||||
|
@ -1,10 +1,8 @@
|
||||
package ai.chat2db.plugin.mysql.value.sub;
|
||||
|
||||
import ai.chat2db.plugin.mysql.value.template.MysqlDmlValueTemplate;
|
||||
import ai.chat2db.spi.jdbc.DefaultValueProcessor;
|
||||
import ai.chat2db.spi.model.JDBCDataValue;
|
||||
import ai.chat2db.spi.model.SQLDataValue;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
|
||||
/**
|
||||
* @author: zgq
|
||||
@ -26,6 +24,6 @@ public class MysqlBinaryProcessor extends DefaultValueProcessor {
|
||||
|
||||
@Override
|
||||
public String convertJDBCValueStrByType(JDBCDataValue dataValue) {
|
||||
return convertJDBCValueByType(dataValue);
|
||||
return dataValue.getBlobHexString();
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,18 @@ public class MysqlBitProcessor extends DefaultValueProcessor {
|
||||
|
||||
@Override
|
||||
public String convertJDBCValueStrByType(JDBCDataValue dataValue) {
|
||||
return getString(convertJDBCValueByType(dataValue));
|
||||
int precision = dataValue.getPrecision();
|
||||
byte[] bytes = dataValue.getBytes();
|
||||
if (precision == 1) {
|
||||
//bit(1) [1 -> true] [0 -> false]
|
||||
if (bytes.length == 1 && (bytes[0] == 0 || bytes[0] == 1)) {
|
||||
return String.valueOf(dataValue.getBoolean());
|
||||
}
|
||||
// tinyint(1)
|
||||
return String.valueOf(dataValue.getInt());
|
||||
}
|
||||
//bit(m) m: 2~64
|
||||
return wrap(EasyStringUtils.getBitString(bytes, precision));
|
||||
}
|
||||
|
||||
public String getString(String value) {
|
||||
|
@ -25,17 +25,17 @@ public class MysqlTextProcessor extends DefaultValueProcessor {
|
||||
|
||||
@Override
|
||||
public String convertJDBCValueByType(JDBCDataValue dataValue) {
|
||||
return getClobString(dataValue, true, super::convertJDBCValueByType);
|
||||
return getClobString(dataValue, super::convertJDBCValueByType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertJDBCValueStrByType(JDBCDataValue dataValue) {
|
||||
return wrap(getClobString(dataValue, false, super::convertJDBCValueStrByType));
|
||||
return wrap(getClobString(dataValue, super::convertJDBCValueStrByType));
|
||||
}
|
||||
|
||||
private String getClobString(JDBCDataValue dataValue, boolean limitSize, Function<JDBCDataValue, String> function) {
|
||||
private String getClobString(JDBCDataValue dataValue, Function<JDBCDataValue, String> function) {
|
||||
try {
|
||||
return dataValue.getClobString(limitSize);
|
||||
return dataValue.getClobString();
|
||||
} catch (Exception e) {
|
||||
log.warn("convertJDBCValue error database: {} , error dataType: {} ",
|
||||
Chat2DBContext.getDBConfig().getDbType(), dataValue.getType(), e);
|
||||
|
@ -1,8 +1,10 @@
|
||||
package ai.chat2db.plugin.mysql.value.sub;
|
||||
|
||||
import ai.chat2db.spi.jdbc.DefaultValueProcessor;
|
||||
import ai.chat2db.spi.model.JDBCDataValue;
|
||||
import ai.chat2db.spi.model.SQLDataValue;
|
||||
import ai.chat2db.spi.sql.Chat2DBContext;
|
||||
import ch.qos.logback.core.model.processor.DefaultProcessor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
@ -10,7 +12,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* @date: 2024年06月03日 20:48
|
||||
*/
|
||||
@Slf4j
|
||||
public class MysqlVarBinaryProcessor extends MysqlBinaryProcessor {
|
||||
public class MysqlVarBinaryProcessor extends DefaultValueProcessor {
|
||||
|
||||
@Override
|
||||
public String convertSQLValueByType(SQLDataValue dataValue) {
|
||||
@ -22,9 +24,9 @@ public class MysqlVarBinaryProcessor extends MysqlBinaryProcessor {
|
||||
@Override
|
||||
public String convertJDBCValueByType(JDBCDataValue dataValue) {
|
||||
try {
|
||||
return dataValue.getBlobString(true);
|
||||
return dataValue.getBlobString();
|
||||
} catch (Exception e) {
|
||||
log.warn("convertJDBCValueByType error database: {} , error dataType: {} ",
|
||||
log.warn("convertJDBCValue error database: {} , error dataType: {} ",
|
||||
Chat2DBContext.getDBConfig().getDbType(), dataValue.getType(), e);
|
||||
return super.convertJDBCValueByType(dataValue);
|
||||
}
|
||||
@ -33,7 +35,7 @@ public class MysqlVarBinaryProcessor extends MysqlBinaryProcessor {
|
||||
|
||||
@Override
|
||||
public String convertJDBCValueStrByType(JDBCDataValue dataValue) {
|
||||
return super.convertJDBCValueStrByType(dataValue);
|
||||
return dataValue.getBlobHexString();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user