fix(chat2db-oracle): Temporary processing of binary data

This commit is contained in:
zgq
2024-07-09 22:11:28 +08:00
parent d70c4754d1
commit cfcaa5b112
3 changed files with 60 additions and 3 deletions

View File

@ -15,7 +15,24 @@ public class OracleBlobProcessor extends DefaultValueProcessor {
@Override @Override
public String convertSQLValueByType(SQLDataValue dataValue) { public String convertSQLValueByType(SQLDataValue dataValue) {
return EasyStringUtils.quoteString(dataValue.getBlobHexString()); String value = dataValue.getValue();
if (value.startsWith("0x")) {
// 0xabcd
return EasyStringUtils.quoteString(value.substring(2));
} else {
//example: hello,world
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
boolean isDigit = (c >= '0' && c <= '9');
boolean isUpperCaseHex = (c >= 'A' && c <= 'F');
boolean isLowerCaseHex = (c >= 'a' && c <= 'f');
if (!isDigit && !isUpperCaseHex && !isLowerCaseHex) {
return EasyStringUtils.quoteString(dataValue.getBlobHexString());
}
}
// example: abcd1234
return EasyStringUtils.quoteString(value);
}
} }
@Override @Override

View File

@ -15,7 +15,25 @@ public class OracleLongRawProcessor extends DefaultValueProcessor {
@Override @Override
public String convertSQLValueByType(SQLDataValue dataValue) { public String convertSQLValueByType(SQLDataValue dataValue) {
return EasyStringUtils.quoteString(dataValue.getValue()); String value = dataValue.getValue();
if (value.startsWith("0x")) {
// 0xabcd
return EasyStringUtils.quoteString(value.substring(2));
} else {
//example: hello,world
// TODO: Need to optimize recognition of hexadecimal strings
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
boolean isDigit = (c >= '0' && c <= '9');
boolean isUpperCaseHex = (c >= 'A' && c <= 'F');
boolean isLowerCaseHex = (c >= 'a' && c <= 'f');
if (!isDigit && !isUpperCaseHex && !isLowerCaseHex) {
return EasyStringUtils.quoteString(dataValue.getBlobHexString());
}
}
// example: abcd1234
return EasyStringUtils.quoteString(value);
}
} }
@ -34,4 +52,9 @@ public class OracleLongRawProcessor extends DefaultValueProcessor {
return EasyStringUtils.quoteString(blobHexString); return EasyStringUtils.quoteString(blobHexString);
} }
public static void main(String[] args) {
String value = "0x123456";
value = value.substring(2);
System.out.println("value = " + value);
}
} }

View File

@ -14,7 +14,24 @@ public class OracleRawValueProcessor extends DefaultValueProcessor {
@Override @Override
public String convertSQLValueByType(SQLDataValue dataValue) { public String convertSQLValueByType(SQLDataValue dataValue) {
return EasyStringUtils.quoteString(dataValue.getValue()); String value = dataValue.getValue();
if (value.startsWith("0x")) {
// 0xabcd
return EasyStringUtils.quoteString(value.substring(2));
} else {
//example: hello,world
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
boolean isDigit = (c >= '0' && c <= '9');
boolean isUpperCaseHex = (c >= 'A' && c <= 'F');
boolean isLowerCaseHex = (c >= 'a' && c <= 'f');
if (!isDigit && !isUpperCaseHex && !isLowerCaseHex) {
return EasyStringUtils.quoteString(dataValue.getBlobHexString());
}
}
// example: abcd1234
return EasyStringUtils.quoteString(value);
}
} }