Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在团队开发的系统使用中使用mycat,发现进行insert操作,当语句中有插入的值为转义符 [例:INSERT INTO table(co… #2594

Conversation

naturelq
Copy link

…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;
}
}

…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;
    }
}
@junwen12221 junwen12221 merged commit 9061098 into MyCATApache:Mycat-server-1.6.7.4-release-20200105164103 Sep 21, 2020
@junwen12221 junwen12221 mentioned this pull request Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants