在团队开发的系统使用中使用mycat,发现进行insert操作,当语句中有插入的值为转义符 [例:INSERT INTO table(co… #2594
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…lumn1, column2, column3, column4) VALUES ('value1' , 'value2', '\', 'value4');],出现Cause: java.sql.SQLSyntaxErrorException: String index out of range: -1报错,查看源码,源代码io.mycat.route.util.RouterUtil#parseSqlValueArrayAndSuffixStr发现连续的转义符('\')没有被正确的处理,修改此方法解决报错,在处理 VALUES 后面的值,处理值中含有单引号或双引号后,添加对连续的转义符的支持,代码如下:
if (flag == 1 || flag == 2) {
currentValue.append(c);
if (c == '\') {
char nextCode = valuesAndSuffixStr.charAt(pos + 1);
if (nextCode == ''' || nextCode == '"') {
currentValue.append(nextCode);
pos++;
continue;
// 新增代码开始
} else if (nextCode == '\') {
currentValue.append(nextCode);
pos++;
continue;
// 新增代码结束
}
}
if (c == '"' && flag == 1) {
flag = 0;
continue;
}
if (c == ''' && flag == 2) {
flag = 0;
continue;
}
}