未验证 提交 a67631a0 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #9791 from taosdata/feature/TD-12252-2.4

[TD-12252]<feature>(query):fix error in escape in like operator
......@@ -266,6 +266,7 @@ int patternMatch(const char *patterStr, const char *str, size_t size, const SPat
int32_t j = 0;
int32_t o = 0;
int32_t m = 0;
char escape = '\\'; // "\"
while ((c = patterStr[i++]) != 0) {
if (c == pInfo->matchAll) { /* Match "*" */
......@@ -308,13 +309,30 @@ int patternMatch(const char *patterStr, const char *str, size_t size, const SPat
++o;
if (j <= size) {
if (c == '\\' && patterStr[i] == '_' && c1 == '_') { i++; continue; }
if (c == '\\' && patterStr[i] == '%' && c1 == '%') { i++; continue; }
if (c == escape && patterStr[i] == pInfo->matchOne){
if(c1 == pInfo->matchOne){
i++;
continue;
}
else{
return TSDB_PATTERN_NOMATCH;
}
}
if (c == escape && patterStr[i] == pInfo->matchAll){
if(c1 == pInfo->matchAll){
i++;
continue;
}
else{
return TSDB_PATTERN_NOMATCH;
}
}
if (c == c1 || tolower(c) == tolower(c1) || (c == pInfo->matchOne && c1 != 0)) {
continue;
}
}
return TSDB_PATTERN_NOMATCH;
}
......@@ -428,8 +446,24 @@ int WCSPatternMatch(const uint32_t *patterStr, const uint32_t *str, size_t size,
c1 = str[j++];
if (j <= size) {
if (c == escape && patterStr[i] == matchOne && c1 == matchOne) { i++; continue; }
if (c == escape && patterStr[i] == matchAll && c1 == matchAll) { i++; continue; }
if (c == escape && patterStr[i] == matchOne){
if(c1 == matchOne){
i++;
continue;
}
else{
return TSDB_PATTERN_NOMATCH;
}
}
if (c == escape && patterStr[i] == matchAll){
if(c1 == matchAll){
i++;
continue;
}
else{
return TSDB_PATTERN_NOMATCH;
}
}
if (c == c1 || towlower(c) == towlower(c1) || (c == matchOne && c1 != 0)) {
continue;
}
......
......@@ -131,11 +131,17 @@ class TDTestCase:
tdSql.checkData(0, 1, r'\%')
# [TD-12815] like wildcard(%, _) are not supported nchar
tdSql.execute(r"insert into tt values(1591050708000, 'h\%d')")
tdSql.execute(r"insert into tt values(1591070708000, 'h%d')")
tdSql.execute(r"insert into tt values(1591080808000, 'h\_j')")
tdSql.execute(r"insert into tt values(1591080708000, 'h_j')")
tdSql.execute(r"insert into tt values(1591090708000, 'h\\j')")
tdSql.query(r"select * from tt where `i\t` like 'h\\\%d'")
tdSql.checkRows(1)
tdSql.query(r"select * from tt where `i\t` like 'h\%d'")
tdSql.checkRows(1)
tdSql.query(r"select * from tt where `i\t` like 'h\\\_j'")
tdSql.checkRows(1)
tdSql.query(r"select * from tt where `i\t` like 'h\_j'")
tdSql.checkRows(1)
tdSql.query(r"select * from tt where `i\t` like 'h\\j'")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册