Druid Version: 1.1.10
Expect: 1/Upload\TIM\\Picture.jpg
Actual: 1/UploadTIM\Picture.jpg
I want to capture the update field
key-value as Map<String, String>.
When the value
contain \
, The Backslash is missing. What's should I do?
Chinese: 我想获取更新字段的原始key-value。但是当存在 \
时,会出现丢失的情况。请问是我调用错误了吗?
public static void main(String[] args) {
// UPDATE my_table SET content='1/Upload\TIM\\Picture.jpg' WHERE id=13
String sql = "UPDATE my_table SET content='1/Upload\\TIM\\\\Picture.jpg' WHERE id=13";
String tableName = null;
Map<String, String> fields = new HashMap<>();
String where = null;
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL);
List<SQLObject> sqlObjects = parser.parseStatement().getChildren();
for (SQLObject sqlObject : sqlObjects) {
// 2.1. get Table Name(获取表名)
if(SQLExprTableSource.class.isAssignableFrom(sqlObject.getClass())) {
SQLExprTableSource tableSource = (SQLExprTableSource) sqlObject;
tableName = tableSource.getName().getSimpleName();
continue;
}
// 2.2. get field as Map(获取字段, 转为 key-value的形式)
if(SQLUpdateSetItem.class.isAssignableFrom(sqlObject.getClass())) {
SQLUpdateSetItem update = (SQLUpdateSetItem) sqlObject;
String column = update.getColumn().toString();
// clear ` (清除 字符串 的 起始终止反引号)
column = StringUtils.removeStart(column, "`");
column = StringUtils.removeEnd(column, "`");
String value = update.getValue().toString();
// clear ' (清除 字符串 的 起始终止单引号)
value = StringUtils.removeStart(value, "'");
value = StringUtils.removeEnd(value, "'");
fields.put(column, value);
continue;
}
// 2.3. get where condition (获取where 子句)
if(SQLBinaryOpExpr.class.isAssignableFrom(sqlObject.getClass())) {
SQLBinaryOpExpr expr = (SQLBinaryOpExpr) sqlObject;
where = expr.toString();
continue;
}
}
// UPDATE my_table SET content='1/Upload\TIM\\Picture.jpg' WHERE id=13
System.out.println(tableName);
System.out.println(JSONObject.toJSONString(fields));
System.out.println(fields.get("content")); // 1/UploadTIM\Picture.jpg
System.out.println(where);
}
I Debug and find L1087 do something?
Chinese: debug了一下,发现L1087进行了转义操作?
1条答案
按热度按时间owfi6suc1#
Is there any progress on this ?